From 2c7518873eddafcd041fe73a509756155f35ac9a Mon Sep 17 00:00:00 2001 From: millette Date: Wed, 3 Dec 2008 14:26:58 -0500 Subject: moving delete profile to its own space. darcs-hash:20081203192658-099f7-37d26abf7409ab2996a22de4aa71cb7a5f68d205.gz --- actions/deleteprofile.php | 212 ++++++++++++++++++++++++++++++++++++++++++++ actions/profilesettings.php | 168 +---------------------------------- lib/deleteprofileaction.php | 61 +++++++++++++ 3 files changed, 275 insertions(+), 166 deletions(-) create mode 100644 actions/deleteprofile.php create mode 100644 lib/deleteprofileaction.php diff --git a/actions/deleteprofile.php b/actions/deleteprofile.php new file mode 100644 index 000000000..4328dfc2c --- /dev/null +++ b/actions/deleteprofile.php @@ -0,0 +1,212 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once(INSTALLDIR.'/lib/settingsaction.php'); + +class DeleteprofileAction extends Action { // was SettingsAction... + + function get_instructions() { + return _('You can update your personal profile info here '. + 'so people know more about you.'); + } + + function show_form($msg=NULL, $success=false) { + $this->form_header(_('Delete my account'), $msg, $success); + common_element('h2', NULL, _('Delete my account')); + $this->show_delete_form(); + common_show_footer(); + } + + function handle_post() { + + # CSRF protection + + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->show_form(_('There was a problem with your session token. Try again, please.')); + return; + } + + if ($this->arg('deleteaccount')) { + $this->delete_account_confirmation(); + } + + } + + function show_feeds_list($feeds) { + common_element_start('div', array('class' => 'feedsdel')); + common_element('p', null, 'Feeds:'); + common_element_start('ul', array('class' => 'xoxo')); + + foreach ($feeds as $key => $value) { + $this->common_feed_item($feeds[$key]); + } + common_element_end('ul'); + common_element_end('div'); + } + + //TODO move to common.php (and retrace its origin) + function common_feed_item($feed) { + $user = common_current_user(); + $nickname = $user->nickname; + + switch($feed['item']) { + case 'notices': default: + $feed_classname = $feed['type']; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "$nickname's ".$feed['version']." notice feed"; + $feed['textContent'] = "RSS"; + break; + + case 'foaf': + $feed_classname = "foaf"; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "$nickname's FOAF file"; + $feed['textContent'] = "FOAF"; + break; + } + common_element_start('li'); + common_element('a', array('href' => $feed['href'], + 'class' => $feed_classname, + 'type' => $feed_mimetype, + 'title' => $feed_title), + $feed['textContent']); + common_element_end('li'); + } + + function show_delete_form() { + $user = common_current_user(); + $notices = DB_DataObject::factory('notice'); + $notices->profile_id = $user->id; + $notice_count = (int) $notices->count(); + + common_element_start('form', array('method' => 'POST', + 'id' => 'delete', + 'action' => + common_local_url('profilesettings'))); + + common_hidden('token', common_session_token()); + common_element('p', null, "You can copy your notices and contacts by saving the two links belowxbefore deleting your account. Be careful, this operation cannot be undone."); + + + $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)), + 'type' => 'rss', + 'version' => 'RSS 1.0', + 'item' => 'notices'), + 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)), + 'type' => 'rdf', + 'version' => 'FOAF', + 'item' => 'foaf'))); + + common_submit('deleteaccount', _('Delete my account')); + common_element_end('form'); + } + + function delete_account_confirmation() { + // ask confirmation then + $this->delete_account(); + } + + function delete_account() { + $user = common_current_user(); + assert(!is_null($user)); # should already be checked + + // deleted later through the profile + /* + $avatar = new Avatar; + $avatar->profile_id = $user->id; + $n_avatars_deleted = $avatar->delete(); + */ + + $fave = new Fave; + $fave->user_id = $user->id; + $n_faves_deleted = $fave->delete(); + + $confirmation = new Confirm_address; + $confirmation->user_id = $user->id; + $n_confirmations_deleted = $confirmation->delete(); + + // TODO foreign stuff... + + $invitation = new Invitation; + $invitation->user_id = $user->id; + $n_invitations_deleted = $invitation->delete(); + + $message_from = new Message; + $message_from->from_profile = $user->id; + $n_messages_from_deleted = $message_from->delete(); + + $message_to = new Message; + $message_to->to_profile = $user->id; + $n_messages_to_deleted = $message_to->delete(); + + $notice_inbox = new Notice_inbox; + $notice_inbox->user_id = $user->id; + $n_notices_inbox_deleted = $notice_inbox->delete(); + + $profile_tagger = new Profile_tag; + $profile_tagger->tagger = $user->id; + $n_profiles_tagger_deleted = $profile_tagger->delete(); + + $profile_tagged = new Profile_tag; + $profile_tagged->tagged = $user->id; + $n_profiles_tagged_deleted = $profile_tagged->delete(); + + $remember_me = new Remember_me; + $remember_me->user_id = $user->id; + $n_remember_mes_deleted = $remember_me->delete(); + + $reply= new Reply; + $reply->profile_id = $user->id; + $n_replies_deleted = $reply->delete(); + + // FIXME we're not removings replies to deleted notices. + // notices should take care of that themselves. + + $notice = new Notice; + $notice->profile_id = $user->id; + $n_notices_deleted = $notice->delete(); + + $subscriber = new Subscription; + $subscriber->subscriber = $user->id; + $n_subscribers_deleted = $subscriber->delete(); + + $subscribed = new Subscription; + $subscribed->subscribed = $user->id; + $n_subscribeds_deleted = $subscribed->delete(); + + $user_openid = new User_openid; + $user_openid->user_id = $user->id; + $n_user_openids_deleted = $user_openid->delete(); + + $profile = new Profile; + $profile->id = $user->id; + $profile->delete_avatars(); + $n_profiles_deleted = $profile->delete(); + $n_users_deleted = $user->delete(); + + // logout and redirect to public + common_set_user(NULL); + common_real_login(false); # not logged in + common_forgetme(); # don't log back in! + common_redirect(common_local_url('public')); + } +} diff --git a/actions/profilesettings.php b/actions/profilesettings.php index f0083b219..ed2623c9b 100644 --- a/actions/profilesettings.php +++ b/actions/profilesettings.php @@ -35,8 +35,8 @@ class ProfilesettingsAction extends SettingsAction { $this->show_avatar_form(); common_element('h2', NULL, _('Change password')); $this->show_password_form(); - common_element('h2', NULL, _('Delete my account')); - $this->show_delete_form(); +// common_element('h2', NULL, _('Delete my account')); +// $this->show_delete_form(); common_show_footer(); } @@ -56,8 +56,6 @@ class ProfilesettingsAction extends SettingsAction { $this->upload_avatar(); } else if ($this->arg('changepass')) { $this->change_password(); - } else if ($this->arg('deleteaccount')) { - $this->delete_account(); } } @@ -192,75 +190,6 @@ class ProfilesettingsAction extends SettingsAction { common_element_end('form'); } - - function show_feeds_list($feeds) { - common_element_start('div', array('class' => 'feedsdel')); - common_element('p', null, 'Feeds:'); - common_element_start('ul', array('class' => 'xoxo')); - - foreach ($feeds as $key => $value) { - $this->common_feed_item($feeds[$key]); - } - common_element_end('ul'); - common_element_end('div'); - } - - function common_feed_item($feed) { - $user = common_current_user(); - $nickname = $user->nickname; - - switch($feed['item']) { - case 'notices': default: - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "$nickname's ".$feed['version']." notice feed"; - $feed['textContent'] = "RSS"; - break; - - case 'foaf': - $feed_classname = "foaf"; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "$nickname's FOAF file"; - $feed['textContent'] = "FOAF"; - break; - } - common_element_start('li'); - common_element('a', array('href' => $feed['href'], - 'class' => $feed_classname, - 'type' => $feed_mimetype, - 'title' => $feed_title), - $feed['textContent']); - common_element_end('li'); - } - - function show_delete_form() { - $user = common_current_user(); - $notices = DB_DataObject::factory('notice'); - $notices->profile_id = $user->id; - $notice_count = (int) $notices->count(); - - common_element_start('form', array('method' => 'POST', - 'id' => 'delete', - 'action' => - common_local_url('profilesettings'))); - - common_hidden('token', common_session_token()); - common_element('p', null, "You can copy your notices and contacts by saving the two links belowxbefore deleting your account. Be careful, this operation cannot be undone."); - - - $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)), - 'type' => 'rss', - 'version' => 'RSS 1.0', - 'item' => 'notices'), - 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)), - 'type' => 'rdf', - 'version' => 'FOAF', - 'item' => 'foaf'))); - - common_submit('deleteaccount', _('Delete my account')); - common_element_end('form'); - } - function save_profile() { $nickname = $this->trimmed('nickname'); $fullname = $this->trimmed('fullname'); @@ -507,97 +436,4 @@ class ProfilesettingsAction extends SettingsAction { $this->show_form(_('Password saved.'), true); } - - function delete_account() { - $user = common_current_user(); - assert(!is_null($user)); # should already be checked - - // deleted later through the profile - /* - $avatar = new Avatar; - $avatar->profile_id = $user->id; - $n_avatars_deleted = $avatar->delete(); - */ - - $fave = new Fave; - $fave->user_id = $user->id; - $n_faves_deleted = $fave->delete(); - - $confirmation = new Confirm_address; - $confirmation->user_id = $user->id; - $n_confirmations_deleted = $confirmation->delete(); - - // TODO foreign stuff... - - $invitation = new Invitation; - $invitation->user_id = $user->id; - $n_invitations_deleted = $invitation->delete(); - - $message_from = new Message; - $message_from->from_profile = $user->id; - $n_messages_from_deleted = $message_from->delete(); - - $message_to = new Message; - $message_to->to_profile = $user->id; - $n_messages_to_deleted = $message_to->delete(); - - $notice = new Notice; - $notice->profile_id = $user->id; - $n_notices_deleted = $notice->delete(); - - $notice_inbox = new Notice_inbox; - $notice_inbox->user_id = $user->id; - $n_notices_inbox_deleted = $notice_inbox->delete(); - - $profile_tagger = new Profile_tag; - $profile_tagger->tagger = $user->id; - $n_profiles_tagger_deleted = $profile_tagger->delete(); - - $profile_tagged = new Profile_tag; - $profile_tagged->tagged = $user->id; - $n_profiles_tagged_deleted = $profile_tagged->delete(); - - $remember_me = new Remember_me; - $remember_me->user_id = $user->id; - $n_remember_mes_deleted = $remember_me->delete(); - - $reply_from = new Reply; - $reply_from->profile_id = $user->id; - $n_replies_from_deleted = $reply_from->delete(); - - // not sure if this should be deleted... - //TODO: test - if (1) { - $reply_to = new Reply; - $reply_to->replied_id = $user->id; - $reply_to->find(); - while ($reply_to->fetch()) { - $str = print_r($reply_to, true); - } -// $n_replies_to_deleted = $reply_to->delete(); - } - - $subscriber = new Subscription; - $subscriber->subscriber = $user->id; - $n_subscribers_deleted = $subscriber->delete(); - - $subscribed = new Subscription; - $subscribed->subscribed = $user->id; - $n_subscribeds_deleted = $subscribed->delete(); - - $user_openid = new User_openid; - $user_openid->user_id = $user->id; - $n_user_openids_deleted = $user_openid->delete(); - - // last steps - if (0) { - $profile = new Profile; - $profile->id = $user->id; - $profile->delete_avatars(); - $n_profiles_deleted = $profile->delete(); - $n_users_deleted = $user->delete(); - } - - $this->show_form(_("Your account has been deleted. ($str)"), true); - } } diff --git a/lib/deleteprofileaction.php b/lib/deleteprofileaction.php new file mode 100644 index 000000000..5ba0e7e44 --- /dev/null +++ b/lib/deleteprofileaction.php @@ -0,0 +1,61 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +class DeleteAction extends Action { + + function handle($args) { + parent::handle($args); + $user = common_current_user(); + $notice_id = $this->trimmed('notice'); + $notice = Notice::staticGet($notice_id); + if (!$notice) { + common_user_error(_('No such notice.')); + exit; + } + + $profile = $notice->getProfile(); + $user_profile = $user->getProfile(); + + if (!common_logged_in()) { + common_user_error(_('Not logged in.')); + exit; + } else if ($notice->profile_id != $user_profile->id) { + common_user_error(_('Can\'t delete this notice.')); + exit; + } + } + + function show_top($arr=NULL) { + $instr = $this->get_instructions(); + $output = common_markup_to_html($instr); + common_element_start('div', 'instructions'); + common_raw($output); + common_element_end('div'); + } + + function get_title() { + return NULL; + } + + function show_header() { + return; + } +} -- cgit v1.2.3-54-g00ecf