4 function wfSpecialResetpass( $par ) {
5 $form = new PasswordResetForm();
6 $form->execute( $par );
10 * Let users recover their password.
11 * @addtogroup SpecialPage
13 class PasswordResetForm
extends SpecialPage
{
14 function __construct( $name=null, $reset=null ) {
15 if( $name !== null ) {
17 $this->mTemporaryPassword
= $reset;
20 $this->mName
= $wgRequest->getVal( 'wpName' );
21 $this->mTemporaryPassword
= $wgRequest->getVal( 'wpPassword' );
26 * Main execution point
28 function execute( $par='' ) {
29 global $wgUser, $wgAuth, $wgOut, $wgRequest;
31 if( !$wgAuth->allowPasswordChange() ) {
32 $this->error( wfMsg( 'resetpass_forbidden' ) );
36 if( $this->mName
=== null && !$wgRequest->wasPosted() ) {
37 $this->error( wfMsg( 'resetpass_missing' ) );
41 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
42 $newpass = $wgRequest->getVal( 'wpNewPassword' );
43 $retype = $wgRequest->getVal( 'wpRetype' );
45 $this->attemptReset( $newpass, $retype );
46 $wgOut->addWikiText( wfMsg( 'resetpass_success' ) );
49 'action' => 'submitlogin',
50 'wpName' => $this->mName
,
51 'wpPassword' => $newpass,
52 'returnto' => $wgRequest->getVal( 'returnto' ),
54 if( $wgRequest->getCheck( 'wpRemember' ) ) {
55 $data['wpRemember'] = 1;
57 $login = new LoginForm( new FauxRequest( $data, true ) );
61 } catch( PasswordError
$e ) {
62 $this->error( $e->getMessage() );
68 function error( $msg ) {
70 $wgOut->addHtml( '<div class="errorbox">' .
71 htmlspecialchars( $msg ) .
76 global $wgOut, $wgUser, $wgRequest;
78 $self = SpecialPage
::getTitleFor( 'Resetpass' );
80 '<div id="userloginForm">' .
81 wfOpenElement( 'form',
84 'action' => $self->getLocalUrl() ) ) .
85 '<h2>' . wfMsgHtml( 'resetpass_header' ) . '</h2>' .
86 '<div id="userloginprompt">' .
87 wfMsgExt( 'resetpass_text', array( 'parse' ) ) .
90 wfHidden( 'token', $wgUser->editToken() ) .
91 wfHidden( 'wpName', $this->mName
) .
92 wfHidden( 'wpPassword', $this->mTemporaryPassword
) .
93 wfHidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) .
95 array( 'wpName', 'username', 'text', $this->mName
),
96 array( 'wpNewPassword', 'newpassword', 'password', '' ),
97 array( 'wpRetype', 'yourpasswordagain', 'password', '' ),
102 Xml
::checkLabel( wfMsg( 'remembermypassword' ),
103 'wpRemember', 'wpRemember',
104 $wgRequest->getCheck( 'wpRemember' ) ) .
110 wfSubmitButton( wfMsgHtml( 'resetpass_submit' ) ) .
114 wfCloseElement( 'form' ) .
116 $wgOut->addHtml( $form );
119 function pretty( $fields ) {
121 foreach( $fields as $list ) {
122 list( $name, $label, $type, $value ) = $list;
123 if( $type == 'text' ) {
124 $field = '<tt>' . htmlspecialchars( $value ) . '</tt>';
126 $field = Xml
::input( $name, 20, $value,
127 array( 'id' => $name, 'type' => $type ) );
130 $out .= '<td align="right">';
131 $out .= Xml
::label( wfMsg( $label ), $name );
142 * @throws PasswordError when cannot set the new password because requirements not met.
144 function attemptReset( $newpass, $retype ) {
145 $user = User
::newFromName( $this->mName
);
146 if( $user->isAnon() ) {
147 throw new PasswordError( 'no such user' );
150 if( !$user->checkTemporaryPassword( $this->mTemporaryPassword
) ) {
151 throw new PasswordError( wfMsg( 'resetpass_bad_temporary' ) );
154 if( $newpass !== $retype ) {
155 throw new PasswordError( wfMsg( 'badretype' ) );
158 $user->setPassword( $newpass );
159 $user->saveSettings();