oauthappssettings.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List the OAuth applications that a user has registered with this instance
  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 Settings
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @copyright 2008-2009 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. require_once INSTALLDIR . '/lib/applicationlist.php';
  33. /**
  34. * Show a user's registered OAuth applications
  35. *
  36. * @category Settings
  37. * @package StatusNet
  38. * @author Zach Copley <zach@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. *
  42. * @see SettingsAction
  43. */
  44. class OauthappssettingsAction extends SettingsAction
  45. {
  46. var $page = 0;
  47. function prepare($args)
  48. {
  49. parent::prepare($args);
  50. $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
  51. if (!common_logged_in()) {
  52. // TRANS: Message displayed to an anonymous user trying to view OAuth application list.
  53. $this->clientError(_('You must be logged in to list your applications.'));
  54. }
  55. return true;
  56. }
  57. /**
  58. * Title of the page
  59. *
  60. * @return string Title of the page
  61. */
  62. function title()
  63. {
  64. // TRANS: Page title for OAuth applications
  65. return _('OAuth applications');
  66. }
  67. /**
  68. * Instructions for use
  69. *
  70. * @return instructions for use
  71. */
  72. function getInstructions()
  73. {
  74. // TRANS: Page instructions for OAuth applications
  75. return _('Applications you have registered');
  76. }
  77. /**
  78. * Content area of the page
  79. *
  80. * @return void
  81. */
  82. function showContent()
  83. {
  84. $user = common_current_user();
  85. $offset = ($this->page - 1) * APPS_PER_PAGE;
  86. $limit = APPS_PER_PAGE + 1;
  87. $application = new Oauth_application();
  88. $application->owner = $user->id;
  89. $application->whereAdd("name != 'anonymous'");
  90. $application->limit($offset, $limit);
  91. $application->orderBy('created DESC');
  92. $application->find();
  93. $cnt = 0;
  94. if ($application) {
  95. $al = new ApplicationList($application, $user, $this);
  96. $cnt = $al->show();
  97. if (0 == $cnt) {
  98. $this->showEmptyListMessage();
  99. }
  100. }
  101. $this->elementStart('p', array('id' => 'application_register'));
  102. $this->element('a',
  103. array('href' => common_local_url('newapplication'),
  104. 'class' => 'more'
  105. ),
  106. // TRANS: Link description to add a new OAuth application.
  107. 'Register a new application');
  108. $this->elementEnd('p');
  109. $this->pagination(
  110. $this->page > 1,
  111. $cnt > APPS_PER_PAGE,
  112. $this->page,
  113. 'oauthappssettings'
  114. );
  115. }
  116. function showEmptyListMessage()
  117. {
  118. // TRANS: Empty list message on page with OAuth applications.
  119. $message = sprintf(_('You have not registered any applications yet.'));
  120. $this->elementStart('div', 'guide');
  121. $this->raw(common_markup_to_html($message));
  122. $this->elementEnd('div');
  123. }
  124. /**
  125. * Handle posts to this form
  126. *
  127. * Based on the button that was pressed, muxes out to other functions
  128. * to do the actual task requested.
  129. *
  130. * All sub-functions reload the form with a message -- success or failure.
  131. *
  132. * @return void
  133. */
  134. function handlePost()
  135. {
  136. // CSRF protection
  137. $token = $this->trimmed('token');
  138. if (!$token || $token != common_session_token()) {
  139. $this->showForm(_('There was a problem with your session token. '.
  140. 'Try again, please.'));
  141. return;
  142. }
  143. }
  144. }