passwordsettings.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Change user password
  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 Evan Prodromou <evan@status.net>
  25. * @author Zach Copley <zach@status.net>
  26. * @copyright 2008-2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) { exit(1); }
  31. /**
  32. * Change password
  33. *
  34. * @category Settings
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @author Zach Copley <zach@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. class PasswordsettingsAction extends SettingsAction
  42. {
  43. /**
  44. * Title of the page
  45. *
  46. * @return string Title of the page
  47. */
  48. function title()
  49. {
  50. // TRANS: Title for page where to change password.
  51. return _m('TITLE','Change password');
  52. }
  53. /**
  54. * Instructions for use
  55. *
  56. * @return instructions for use
  57. */
  58. function getInstructions()
  59. {
  60. // TRANS: Instructions for page where to change password.
  61. return _('Change your password.');
  62. }
  63. function showScripts()
  64. {
  65. parent::showScripts();
  66. $this->autofocus('oldpassword');
  67. }
  68. function showContent()
  69. {
  70. $this->elementStart('form', array('method' => 'POST',
  71. 'id' => 'form_password',
  72. 'class' => 'form_settings',
  73. 'action' =>
  74. common_local_url('passwordsettings')));
  75. $this->elementStart('fieldset');
  76. // TRANS: Fieldset legend on page where to change password.
  77. $this->element('legend', null, _('Password change'));
  78. $this->hidden('token', common_session_token());
  79. $this->elementStart('ul', 'form_data');
  80. // Users who logged in with OpenID won't have a pwd
  81. if ($this->scoped->hasPassword()) {
  82. $this->elementStart('li');
  83. // TRANS: Field label on page where to change password.
  84. $this->password('oldpassword', _('Old password'));
  85. $this->elementEnd('li');
  86. }
  87. $this->elementStart('li');
  88. // TRANS: Field label on page where to change password.
  89. $this->password('newpassword', _('New password'),
  90. // TRANS: Field title on page where to change password.
  91. _('6 or more characters.'));
  92. $this->elementEnd('li');
  93. $this->elementStart('li');
  94. // TRANS: Field label on page where to change password. In this field the new password should be typed a second time.
  95. $this->password('confirm', _m('LABEL','Confirm'),
  96. // TRANS: Field title on page where to change password.
  97. _('Same as password above.'));
  98. $this->elementEnd('li');
  99. $this->elementEnd('ul');
  100. // TRANS: Button text on page where to change password.
  101. $this->submit('changepass', _m('BUTTON','Change'));
  102. $this->elementEnd('fieldset');
  103. $this->elementEnd('form');
  104. }
  105. protected function doPost()
  106. {
  107. // FIXME: scrub input
  108. $newpassword = $this->arg('newpassword');
  109. $confirm = $this->arg('confirm');
  110. // Some validation
  111. if (strlen($newpassword) < 6) {
  112. // TRANS: Form validation error on page where to change password.
  113. throw new ClientException(_('Password must be 6 or more characters.'));
  114. } else if (0 != strcmp($newpassword, $confirm)) {
  115. // TRANS: Form validation error on password change when password confirmation does not match.
  116. throw new ClientException(_('Passwords do not match.'));
  117. }
  118. $oldpassword = null;
  119. if ($this->scoped->hasPassword()) {
  120. $oldpassword = $this->arg('oldpassword');
  121. if (!common_check_user($this->scoped->getNickname(), $oldpassword)) {
  122. // TRANS: Form validation error on page where to change password.
  123. throw new ClientException(_('Incorrect old password.'));
  124. }
  125. }
  126. if (Event::handle('StartChangePassword', array($this->scoped, $oldpassword, $newpassword))) {
  127. //no handler changed the password, so change the password internally
  128. $user->setPassword($newpassword);
  129. Event::handle('EndChangePassword', array($this->scoped));
  130. }
  131. // TRANS: Form validation notice on page where to change password.
  132. return _('Password saved.');
  133. }
  134. }