deleteapplication.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Action class to delete an OAuth application
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Action
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @copyright 2010 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Delete an OAuth appliction
  34. *
  35. * @category Action
  36. * @package StatusNet
  37. * @author Zach Copley <zach@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  39. * @link http://status.net/
  40. */
  41. class DeleteapplicationAction extends Action
  42. {
  43. var $app = null;
  44. /**
  45. * Take arguments for running
  46. *
  47. * @param array $args $_REQUEST args
  48. *
  49. * @return boolean success flag
  50. */
  51. function prepare($args)
  52. {
  53. if (!parent::prepare($args)) {
  54. return false;
  55. }
  56. if (!common_logged_in()) {
  57. // TRANS: Client error displayed trying to delete an application while not logged in.
  58. $this->clientError(_('You must be logged in to delete an application.'));
  59. }
  60. $id = (int)$this->arg('id');
  61. $this->app = Oauth_application::getKV('id', $id);
  62. if (empty($this->app)) {
  63. // TRANS: Client error displayed trying to delete an application that does not exist.
  64. $this->clientError(_('Application not found.'));
  65. }
  66. $cur = common_current_user();
  67. if ($cur->id != $this->app->owner) {
  68. // TRANS: Client error displayed trying to delete an application the current user does not own.
  69. $this->clientError(_('You are not the owner of this application.'), 401);
  70. }
  71. return true;
  72. }
  73. /**
  74. * Handle request
  75. *
  76. * Shows a page with list of favorite notices
  77. *
  78. * @param array $args $_REQUEST args; handled in prepare()
  79. *
  80. * @return void
  81. */
  82. function handle($args)
  83. {
  84. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  85. // CSRF protection
  86. $token = $this->trimmed('token');
  87. if (!$token || $token != common_session_token()) {
  88. // TRANS: Client error displayed when the session token does not match or is not given.
  89. $this->clientError(_('There was a problem with your session token.'));
  90. }
  91. if ($this->arg('no')) {
  92. common_redirect(common_local_url('showapplication',
  93. array('id' => $this->app->id)), 303);
  94. } elseif ($this->arg('yes')) {
  95. $this->handlePost();
  96. common_redirect(common_local_url('oauthappssettings'), 303);
  97. } else {
  98. $this->showPage();
  99. }
  100. }
  101. }
  102. function showContent() {
  103. $this->areYouSureForm();
  104. }
  105. function title() {
  106. // TRANS: Title for delete application page.
  107. return _('Delete application');
  108. }
  109. function showNoticeForm() {
  110. // nop
  111. }
  112. /**
  113. * Confirm with user.
  114. *
  115. * Shows a confirmation form.
  116. *
  117. * @return void
  118. */
  119. function areYouSureForm()
  120. {
  121. $id = $this->app->id;
  122. $this->elementStart('form', array('id' => 'deleteapplication-' . $id,
  123. 'method' => 'post',
  124. 'class' => 'form_settings form_entity_block',
  125. 'action' => common_local_url('deleteapplication',
  126. array('id' => $this->app->id))));
  127. $this->elementStart('fieldset');
  128. $this->hidden('token', common_session_token());
  129. // TRANS: Fieldset legend on delete application page.
  130. $this->element('legend', _('Delete application'));
  131. $this->element('p', null,
  132. // TRANS: Confirmation text on delete application page.
  133. _('Are you sure you want to delete this application? '.
  134. 'This will clear all data about the application from the '.
  135. 'database, including all existing user connections.'));
  136. $this->submit('form_action-no',
  137. // TRANS: Button label on the delete application form.
  138. _m('BUTTON','No'),
  139. 'submit form_action-primary',
  140. 'no',
  141. // TRANS: Submit button title for 'No' when deleting an application.
  142. _('Do not delete this application.'));
  143. $this->submit('form_action-yes',
  144. // TRANS: Button label on the delete application form.
  145. _m('BUTTON','Yes'),
  146. 'submit form_action-secondary',
  147. // TRANS: Submit button title for 'Yes' when deleting an application.
  148. 'yes', _('Delete this application.'));
  149. $this->elementEnd('fieldset');
  150. $this->elementEnd('form');
  151. }
  152. /**
  153. * Actually delete the app
  154. *
  155. * @return void
  156. */
  157. function handlePost()
  158. {
  159. $this->app->delete();
  160. }
  161. }