openidtrust.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 OpenidtrustAction extends Action
  24. {
  25. var $trust_root;
  26. var $allowUrl;
  27. var $denyUrl;
  28. var $user;
  29. /**
  30. * Is this a read-only action?
  31. *
  32. * @return boolean false
  33. */
  34. function isReadOnly($args)
  35. {
  36. return false;
  37. }
  38. /**
  39. * Title of the page
  40. *
  41. * @return string title of the page
  42. */
  43. function title()
  44. {
  45. // TRANS: Title for identity verification page.
  46. return _m('OpenID Identity Verification');
  47. }
  48. function prepare(array $args = array())
  49. {
  50. parent::prepare($args);
  51. common_ensure_session();
  52. $this->user = common_current_user();
  53. if(empty($this->user)){
  54. /* Go log in, and then come back. */
  55. common_set_returnto($_SERVER['REQUEST_URI']);
  56. common_redirect(common_local_url('login'));
  57. }
  58. $this->trust_root = $_SESSION['openid_trust_root'];
  59. $this->allowUrl = $_SESSION['openid_allow_url'];
  60. $this->denyUrl = $_SESSION['openid_deny_url'];
  61. if(empty($this->trust_root) || empty($this->allowUrl) || empty($this->denyUrl)){
  62. // TRANS: Client error when visiting page directly.
  63. $this->clientError(_m('This page should only be reached during OpenID processing, not directly.'));
  64. }
  65. return true;
  66. }
  67. function handle()
  68. {
  69. parent::handle();
  70. if($_SERVER['REQUEST_METHOD'] == 'POST'){
  71. $this->handleSubmit();
  72. }else{
  73. $this->showPage();
  74. }
  75. }
  76. function handleSubmit()
  77. {
  78. global $_PEAR;
  79. unset($_SESSION['openid_trust_root']);
  80. unset($_SESSION['openid_allow_url']);
  81. unset($_SESSION['openid_deny_url']);
  82. if($this->arg('allow'))
  83. {
  84. //save to database
  85. $user_openid_trustroot = new User_openid_trustroot();
  86. $user_openid_trustroot->user_id = $this->user->id;
  87. $user_openid_trustroot->trustroot = $this->trust_root;
  88. $user_openid_trustroot->created = common_sql_now();
  89. if (!$user_openid_trustroot->insert()) {
  90. $err = &$_PEAR->getStaticProperty('DB_DataObject','lastError');
  91. }
  92. common_redirect($this->allowUrl, $code=302);
  93. }else{
  94. common_redirect($this->denyUrl, $code=302);
  95. }
  96. }
  97. /**
  98. * Show page notice
  99. *
  100. * Display a notice for how to use the page, or the
  101. * error if it exists.
  102. *
  103. * @return void
  104. */
  105. function showPageNotice()
  106. {
  107. // TRANS: Page notice. %s is a trustroot name.
  108. $this->element('p',null,sprintf(_m('%s has asked to verify your identity. Click Continue to verify your identity and login without creating a new password.'),$this->trust_root));
  109. }
  110. /**
  111. * Core of the display code
  112. *
  113. * Shows the login form.
  114. *
  115. * @return void
  116. */
  117. function showContent()
  118. {
  119. $this->elementStart('form', array('method' => 'post',
  120. 'id' => 'form_openidtrust',
  121. 'class' => 'form_settings',
  122. 'action' => common_local_url('openidtrust')));
  123. $this->elementStart('fieldset');
  124. // TRANS: Button text to continue OpenID identity verification.
  125. $this->submit('allow', _m('BUTTON','Continue'));
  126. // TRANS: Button text to cancel OpenID identity verification.
  127. $this->submit('deny', _m('BUTTON','Cancel'));
  128. $this->elementEnd('fieldset');
  129. $this->elementEnd('form');
  130. }
  131. }