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/
52 class DeleteaccountAction extends Action
54 private $_complete = false;
55 private $_error = null;
58 * For initializing members of the class.
60 * @param array $argarray misc. arguments
62 * @return boolean true
65 function prepare($argarray)
67 parent::prepare($argarray);
69 $cur = common_current_user();
72 throw new ClientException(_("Only logged-in users ".
73 "can delete their account."), 403);
76 if (!$cur->hasRight(Right::DELETEACCOUNT)) {
77 throw new ClientException(_("You cannot delete your account."), 403);
86 * @param array $argarray is ignored since it's now passed in in prepare()
91 function handle($argarray=null)
93 parent::handle($argarray);
95 if ($this->isPost()) {
96 $this->deleteAccount();
104 * Return true if read only.
108 * @param array $args other arguments
110 * @return boolean is read only action?
113 function isReadOnly($args)
119 * Return last modified, if applicable.
123 * @return string last modified http header
126 function lastModified()
128 // For comparison with If-Last-Modified
129 // If not applicable, return null
134 * Return etag, if applicable.
138 * @return string etag http header
147 * Delete the current user's account
149 * Checks for the "I am sure." string to make sure the user really
150 * wants to delete their account.
152 * Then, marks the account as deleted and begins the deletion process
153 * (actually done by a back-end handler).
155 * If successful it logs the user out, and shows a brief completion message.
160 function deleteAccount()
162 $this->checkSessionToken();
164 if ($this->trimmed('iamsure') != _('I am sure.')) {
165 $this->_error = _('You must write "I am sure." exactly in the box.');
170 $cur = common_current_user();
172 // Mark the account as deleted and shove low-level deletion tasks
173 // to background queues. Removing a lot of posts can take a while...
175 if (!$cur->hasRole(Profile_role::DELETED)) {
176 $cur->grantRole(Profile_role::DELETED);
179 $qm = QueueManager::get();
180 $qm->enqueue($cur, 'deluser');
182 // The user is really-truly logged out
184 common_set_user(null);
185 common_real_login(false); // not logged in
186 common_forgetme(); // don't log back in!
188 $this->_complete = true;
193 * Shows the page content.
195 * If the deletion is complete, just shows a completion message.
197 * Otherwise, shows the deletion form.
203 function showContent()
205 if ($this->_complete) {
206 $this->element('p', 'confirmation',
207 _('Account deleted.'));
211 if (!empty($this->_error)) {
212 $this->element('p', 'error', $this->_error);
213 $this->_error = null;
216 $form = new DeleteAccountForm($this);
221 * Show the title of the page
223 * @return string title
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/
246 class DeleteAccountForm extends Form
251 * @return string the form's class
256 return 'form_profile_delete';
260 * URL the form posts to
262 * @return string the form's action URL
267 return common_local_url('deleteaccount');
273 * Instructions plus an 'i am sure' entry box.
280 $cur = common_current_user();
282 $msg = _('<p>This will <strong>permanently delete</strong> '.
283 'your account data from this server. </p>');
285 if ($cur->hasRight(Right::BACKUPACCOUNT)) {
286 $msg .= sprintf(_('<p>You are strongly advised to '.
287 '<a href="%s">back up your data</a>'
288 ' before deletion.</p>'),
289 common_local_url('backupaccount'));
292 $this->out->elementStart('p');
293 $this->out->raw($msg);
294 $this->out->elementEnd('p');
296 $this->out->input('iamsure',
299 _('Enter "I am sure." to confirm that '.
300 'you want to delete your account.'));
304 * Buttons for the form
306 * In this case, a single submit button
311 function formActions()
313 $this->out->submit('submit',
314 _m('BUTTON', 'Delete'),
317 _('Permanently your account'));