deleteaccount.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * Delete your own account
  7. *
  8. * PHP version 5
  9. *
  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.
  14. *
  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.
  19. *
  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/>.
  22. *
  23. * @category Account
  24. * @package StatusNet
  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/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * Action to delete your own account
  37. *
  38. * Note that this is distinct from DeleteuserAction, which see. I thought
  39. * that making that action do both things (delete another user and delete the
  40. * current user) would open a lot of holes. I'm open to refactoring, however.
  41. *
  42. * @category Account
  43. * @package StatusNet
  44. * @author Evan Prodromou <evan@status.net>
  45. * @copyright 2010 StatusNet, Inc.
  46. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  47. * @link http://status.net/
  48. */
  49. class DeleteaccountAction extends Action
  50. {
  51. private $_complete = false;
  52. private $_error = null;
  53. /**
  54. * For initializing members of the class.
  55. *
  56. * @param array $argarray misc. arguments
  57. *
  58. * @return boolean true
  59. */
  60. function prepare($argarray)
  61. {
  62. parent::prepare($argarray);
  63. $cur = common_current_user();
  64. if (empty($cur)) {
  65. // TRANS: Client exception displayed trying to delete a user account while not logged in.
  66. throw new ClientException(_("Only logged-in users ".
  67. "can delete their account."), 403);
  68. }
  69. if (!$cur->hasRight(Right::DELETEACCOUNT)) {
  70. // TRANS: Client exception displayed trying to delete a user account without have the rights to do that.
  71. throw new ClientException(_("You cannot delete your account."), 403);
  72. }
  73. return true;
  74. }
  75. /**
  76. * Handler method
  77. *
  78. * @param array $argarray is ignored since it's now passed in in prepare()
  79. *
  80. * @return void
  81. */
  82. function handle($argarray=null)
  83. {
  84. parent::handle($argarray);
  85. if ($this->isPost()) {
  86. $this->deleteAccount();
  87. } else {
  88. $this->showPage();
  89. }
  90. return;
  91. }
  92. /**
  93. * Return true if read only.
  94. *
  95. * MAY override
  96. *
  97. * @param array $args other arguments
  98. *
  99. * @return boolean is read only action?
  100. */
  101. function isReadOnly($args)
  102. {
  103. return false;
  104. }
  105. /**
  106. * Return last modified, if applicable.
  107. *
  108. * MAY override
  109. *
  110. * @return string last modified http header
  111. */
  112. function lastModified()
  113. {
  114. // For comparison with If-Last-Modified
  115. // If not applicable, return null
  116. return null;
  117. }
  118. /**
  119. * Return etag, if applicable.
  120. *
  121. * MAY override
  122. *
  123. * @return string etag http header
  124. */
  125. function etag()
  126. {
  127. return null;
  128. }
  129. /**
  130. * Delete the current user's account
  131. *
  132. * Checks for the "I am sure." string to make sure the user really
  133. * wants to delete their account.
  134. *
  135. * Then, marks the account as deleted and begins the deletion process
  136. * (actually done by a back-end handler).
  137. *
  138. * If successful it logs the user out, and shows a brief completion message.
  139. *
  140. * @return void
  141. */
  142. function deleteAccount()
  143. {
  144. $this->checkSessionToken();
  145. // !!! If this string is changed, it also needs to be changed in DeleteAccountForm::formData()
  146. // TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
  147. $iamsure = _('I am sure.');
  148. if ($this->trimmed('iamsure') != $iamsure ) {
  149. // TRANS: Notification for user about the text that must be input to be able to delete a user account.
  150. // TRANS: %s is the text that needs to be input.
  151. $this->_error = sprintf(_('You must write "%s" exactly in the box.'), $iamsure);
  152. $this->showPage();
  153. return;
  154. }
  155. $cur = common_current_user();
  156. // Mark the account as deleted and shove low-level deletion tasks
  157. // to background queues. Removing a lot of posts can take a while...
  158. if (!$cur->hasRole(Profile_role::DELETED)) {
  159. $cur->grantRole(Profile_role::DELETED);
  160. }
  161. $qm = QueueManager::get();
  162. $qm->enqueue($cur, 'deluser');
  163. // The user is really-truly logged out
  164. common_set_user(null);
  165. common_real_login(false); // not logged in
  166. common_forgetme(); // don't log back in!
  167. $this->_complete = true;
  168. $this->showPage();
  169. }
  170. /**
  171. * Shows the page content.
  172. *
  173. * If the deletion is complete, just shows a completion message.
  174. *
  175. * Otherwise, shows the deletion form.
  176. *
  177. * @return void
  178. *
  179. */
  180. function showContent()
  181. {
  182. if ($this->_complete) {
  183. $this->element('p', 'confirmation',
  184. // TRANS: Confirmation that a user account has been deleted.
  185. _('Account deleted.'));
  186. return;
  187. }
  188. if (!empty($this->_error)) {
  189. $this->element('p', 'error', $this->_error);
  190. $this->_error = null;
  191. }
  192. $form = new DeleteAccountForm($this);
  193. $form->show();
  194. }
  195. /**
  196. * Show the title of the page
  197. *
  198. * @return string title
  199. */
  200. function title()
  201. {
  202. // TRANS: Page title for page on which a user account can be deleted.
  203. return _('Delete account');
  204. }
  205. }
  206. /**
  207. * Form for deleting your account
  208. *
  209. * Note that this mostly is here to keep you from accidentally deleting your
  210. * account.
  211. *
  212. * @category Account
  213. * @package StatusNet
  214. * @author Evan Prodromou <evan@status.net>
  215. * @copyright 2010 StatusNet, Inc.
  216. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  217. * @link http://status.net/
  218. */
  219. class DeleteAccountForm extends Form
  220. {
  221. /**
  222. * Class of the form.
  223. *
  224. * @return string the form's class
  225. */
  226. function formClass()
  227. {
  228. return 'form_profile_delete';
  229. }
  230. /**
  231. * URL the form posts to
  232. *
  233. * @return string the form's action URL
  234. */
  235. function action()
  236. {
  237. return common_local_url('deleteaccount');
  238. }
  239. /**
  240. * Output form data
  241. *
  242. * Instructions plus an 'i am sure' entry box.
  243. *
  244. * @return void
  245. */
  246. function formData()
  247. {
  248. $cur = common_current_user();
  249. // TRANS: Form text for user deletion form.
  250. $msg = '<p>' . _('This will <strong>permanently delete</strong> '.
  251. 'your account data from this server.') . '</p>';
  252. if ($cur->hasRight(Right::BACKUPACCOUNT)) {
  253. // TRANS: Additional form text for user deletion form shown if a user has account backup rights.
  254. // TRANS: %s is a URL to the backup page.
  255. $msg .= '<p>' . sprintf(_('You are strongly advised to '.
  256. '<a href="%s">back up your data</a>'.
  257. ' before deletion.'),
  258. common_local_url('backupaccount')) . '</p>';
  259. }
  260. $this->out->elementStart('p');
  261. $this->out->raw($msg);
  262. $this->out->elementEnd('p');
  263. // !!! If this string is changed, it also needs to be changed in class DeleteaccountAction.
  264. // TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
  265. $iamsure = _("I am sure.");
  266. $this->out->input('iamsure',
  267. // TRANS: Field label for delete account confirmation entry.
  268. _('Confirm'),
  269. null,
  270. // TRANS: Input title for the delete account field.
  271. // TRANS: %s is the text that needs to be input.
  272. sprintf(_('Enter "%s" to confirm that '.
  273. 'you want to delete your account.'),$iamsure ));
  274. }
  275. /**
  276. * Buttons for the form
  277. *
  278. * In this case, a single submit button
  279. *
  280. * @return void
  281. */
  282. function formActions()
  283. {
  284. $this->out->submit('submit',
  285. // TRANS: Button text for user account deletion.
  286. _m('BUTTON', 'Delete'),
  287. 'submit',
  288. null,
  289. // TRANS: Button title for user account deletion.
  290. _('Permanently delete your account.'));
  291. }
  292. }