3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * Delete your own account
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Action to delete your own account
40 * Note that this is distinct from DeleteuserAction, which see. I thought
41 * that making that action do both things (delete another user and delete the
42 * current user) would open a lot of holes. I'm open to refactoring, however.
46 * @author Evan Prodromou <evan@status.net>
47 * @copyright 2010 StatusNet, Inc.
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
49 * @link http://status.net/
51 class DeleteaccountAction extends Action
53 private $_complete = false;
54 private $_error = null;
57 * For initializing members of the class.
59 * @param array $argarray misc. arguments
61 * @return boolean true
63 function prepare($argarray)
65 parent::prepare($argarray);
67 $cur = common_current_user();
70 // TRANS: Client exception displayed trying to delete a user account while not logged in.
71 throw new ClientException(_("Only logged-in users ".
72 "can delete their account."), 403);
75 if (!$cur->hasRight(Right::DELETEACCOUNT)) {
76 // TRANS: Client exception displayed trying to delete a user account without have the rights to do that.
77 throw new ClientException(_("You cannot delete your account."), 403);
86 * @param array $argarray is ignored since it's now passed in in prepare()
90 function handle($argarray=null)
92 parent::handle($argarray);
94 if ($this->isPost()) {
95 $this->deleteAccount();
103 * Return true if read only.
107 * @param array $args other arguments
109 * @return boolean is read only action?
111 function isReadOnly($args)
117 * Return last modified, if applicable.
121 * @return string last modified http header
123 function lastModified()
125 // For comparison with If-Last-Modified
126 // If not applicable, return null
131 * Return etag, if applicable.
135 * @return string etag http header
143 * Delete the current user's account
145 * Checks for the "I am sure." string to make sure the user really
146 * wants to delete their account.
148 * Then, marks the account as deleted and begins the deletion process
149 * (actually done by a back-end handler).
151 * If successful it logs the user out, and shows a brief completion message.
155 function deleteAccount()
157 $this->checkSessionToken();
158 // !!! If this string is changed, it also needs to be changed in DeleteAccountForm::formData()
159 // TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
160 $iamsure = _('I am sure.');
161 if ($this->trimmed('iamsure') != $iamsure ) {
162 // TRANS: Notification for user about the text that must be input to be able to delete a user account.
163 // TRANS: %s is the text that needs to be input.
164 $this->_error = sprintf(_('You must write "%s" exactly in the box.'), $iamsure);
169 $cur = common_current_user();
171 // Mark the account as deleted and shove low-level deletion tasks
172 // to background queues. Removing a lot of posts can take a while...
174 if (!$cur->hasRole(Profile_role::DELETED)) {
175 $cur->grantRole(Profile_role::DELETED);
178 $qm = QueueManager::get();
179 $qm->enqueue($cur, 'deluser');
181 // The user is really-truly logged out
183 common_set_user(null);
184 common_real_login(false); // not logged in
185 common_forgetme(); // don't log back in!
187 $this->_complete = true;
192 * Shows the page content.
194 * If the deletion is complete, just shows a completion message.
196 * Otherwise, shows the deletion form.
201 function showContent()
203 if ($this->_complete) {
204 $this->element('p', 'confirmation',
205 // TRANS: Confirmation that a user account has been deleted.
206 _('Account deleted.'));
210 if (!empty($this->_error)) {
211 $this->element('p', 'error', $this->_error);
212 $this->_error = null;
215 $form = new DeleteAccountForm($this);
220 * Show the title of the page
222 * @return string title
227 // TRANS: Page title for page on which a user account can be deleted.
228 return _('Delete account');
233 * Form for deleting your account
235 * Note that this mostly is here to keep you from accidentally deleting your
240 * @author Evan Prodromou <evan@status.net>
241 * @copyright 2010 StatusNet, Inc.
242 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
243 * @link http://status.net/
245 class DeleteAccountForm extends Form
250 * @return string the form's class
254 return 'form_profile_delete';
258 * URL the form posts to
260 * @return string the form's action URL
264 return common_local_url('deleteaccount');
270 * Instructions plus an 'i am sure' entry box.
276 $cur = common_current_user();
278 // TRANS: Form text for user deletion form.
279 $msg = '<p>' . _('This will <strong>permanently delete</strong> '.
280 'your account data from this server.') . '</p>';
282 if ($cur->hasRight(Right::BACKUPACCOUNT)) {
283 // TRANS: Additional form text for user deletion form shown if a user has account backup rights.
284 // TRANS: %s is a URL to the backup page.
285 $msg .= '<p>' . sprintf(_('You are strongly advised to '.
286 '<a href="%s">back up your data</a>'.
287 ' before deletion.'),
288 common_local_url('backupaccount')) . '</p>';
291 $this->out->elementStart('p');
292 $this->out->raw($msg);
293 $this->out->elementEnd('p');
295 // !!! If this string is changed, it also needs to be changed in class DeleteaccountAction.
296 // TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
297 $iamsure = _("I am sure.");
298 $this->out->input('iamsure',
299 // TRANS: Field label for delete account confirmation entry.
302 // TRANS: Input title for the delete account field.
303 // TRANS: %s is the text that needs to be input.
304 sprintf(_('Enter "%s" to confirm that '.
305 'you want to delete your account.'),$iamsure ));
309 * Buttons for the form
311 * In this case, a single submit button
315 function formActions()
317 $this->out->submit('submit',
318 // TRANS: Button text for user account deletion.
319 _m('BUTTON', 'Delete'),
322 // TRANS: Button title for user account deletion.
323 _('Permanently delete your account'));