openidlogin.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('STATUSNET')) {
  20. exit(1);
  21. }
  22. require_once INSTALLDIR.'/plugins/OpenID/openid.php';
  23. class OpenidloginAction extends Action
  24. {
  25. function handle($args)
  26. {
  27. parent::handle($args);
  28. if (common_is_real_login()) {
  29. // TRANS: Client error message trying to log on with OpenID while already logged on.
  30. $this->clientError(_m('Already logged in.'));
  31. } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  32. $provider = common_config('openid', 'trusted_provider');
  33. if ($provider) {
  34. $openid_url = $provider;
  35. if (common_config('openid', 'append_username')) {
  36. $openid_url .= $this->trimmed('openid_username');
  37. }
  38. } else {
  39. $openid_url = $this->trimmed('openid_url');
  40. }
  41. oid_assert_allowed($openid_url);
  42. $rememberme = $this->boolean('rememberme');
  43. common_ensure_session();
  44. $_SESSION['openid_rememberme'] = $rememberme;
  45. $result = oid_authenticate($openid_url,
  46. 'finishopenidlogin');
  47. if (is_string($result)) { # error message
  48. unset($_SESSION['openid_rememberme']);
  49. $this->showForm($result, $openid_url);
  50. }
  51. } else {
  52. $openid_url = oid_get_last();
  53. $this->showForm(null, $openid_url);
  54. }
  55. }
  56. function getInstructions()
  57. {
  58. if (common_logged_in() && !common_is_real_login() &&
  59. common_get_returnto()) {
  60. // rememberme logins have to reauthenticate before
  61. // changing any profile settings (cookie-stealing protection)
  62. // TRANS: OpenID plugin message. Rememberme logins have to reauthenticate before changing any profile settings.
  63. // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
  64. return _m('For security reasons, please re-login with your ' .
  65. '[OpenID](%%doc.openid%%) ' .
  66. 'before changing your settings.');
  67. } else {
  68. // TRANS: OpenID plugin message.
  69. // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
  70. return _m('Login with an [OpenID](%%doc.openid%%) account.');
  71. }
  72. }
  73. function showPageNotice()
  74. {
  75. if ($this->error) {
  76. $this->element('div', array('class' => 'error'), $this->error);
  77. } else {
  78. $instr = $this->getInstructions();
  79. $output = common_markup_to_html($instr);
  80. $this->elementStart('div', 'instructions');
  81. $this->raw($output);
  82. $this->elementEnd('div');
  83. }
  84. }
  85. function showScripts()
  86. {
  87. parent::showScripts();
  88. if (common_config('openid', 'trusted_provider')) {
  89. if (common_config('openid', 'append_username')) {
  90. $this->autofocus('openid_username');
  91. } else {
  92. $this->autofocus('rememberme');
  93. }
  94. } else {
  95. $this->autofocus('openid_url');
  96. }
  97. }
  98. function title()
  99. {
  100. // TRANS: OpenID plugin message. Title.
  101. return _m('TITLE','OpenID Login');
  102. }
  103. function showForm($error=null, $openid_url)
  104. {
  105. $this->error = $error;
  106. $this->openid_url = $openid_url;
  107. $this->showPage();
  108. }
  109. function showContent() {
  110. $formaction = common_local_url('openidlogin');
  111. $this->elementStart('form', array('method' => 'post',
  112. 'id' => 'form_openid_login',
  113. 'class' => 'form_settings',
  114. 'action' => $formaction));
  115. $this->elementStart('fieldset');
  116. // TRANS: OpenID plugin logon form legend.
  117. $this->element('legend', null, _m('LEGEND','OpenID login'));
  118. $this->elementStart('ul', 'form_data');
  119. $this->elementStart('li');
  120. $provider = common_config('openid', 'trusted_provider');
  121. $appendUsername = common_config('openid', 'append_username');
  122. if ($provider) {
  123. // TRANS: Field label.
  124. $this->element('label', array(), _m('LABEL','OpenID provider'));
  125. $this->element('span', array(), $provider);
  126. if ($appendUsername) {
  127. $this->element('input', array('id' => 'openid_username',
  128. 'name' => 'openid_username',
  129. 'style' => 'float: none'));
  130. }
  131. $this->element('p', 'form_guide',
  132. // TRANS: Form guide.
  133. ($appendUsername ? _m('Enter your username.') . ' ' : '') .
  134. // TRANS: Form guide.
  135. _m('You will be sent to the provider\'s site for authentication.'));
  136. $this->hidden('openid_url', $provider);
  137. } else {
  138. // TRANS: OpenID plugin logon form field label.
  139. $this->input('openid_url', _m('OpenID URL'),
  140. $this->openid_url,
  141. // TRANS: OpenID plugin logon form field title.
  142. _m('Your OpenID URL.'));
  143. }
  144. $this->elementEnd('li');
  145. $this->elementStart('li', array('id' => 'settings_rememberme'));
  146. // TRANS: OpenID plugin logon form checkbox label for setting to put the OpenID information in a cookie.
  147. $this->checkbox('rememberme', _m('Remember me'), false,
  148. // TRANS: OpenID plugin logon form field title.
  149. _m('Automatically login in the future; ' .
  150. 'not for shared computers!'));
  151. $this->elementEnd('li');
  152. $this->elementEnd('ul');
  153. // TRANS: OpenID plugin logon form button label to start logon with the data provided in the logon form.
  154. $this->submit('submit', _m('BUTTON', 'Login'));
  155. $this->elementEnd('fieldset');
  156. $this->elementEnd('form');
  157. }
  158. function showLocalNav()
  159. {
  160. $nav = new LoginGroupNav($this);
  161. $nav->show();
  162. }
  163. function showNoticeForm()
  164. {
  165. }
  166. function showProfileBlock()
  167. {
  168. }
  169. }