3 function wfSpecialResetpass( $par ) {
4 $form = new PasswordResetForm();
5 $form->execute( $par );
8 class PasswordResetForm
extends SpecialPage
{
9 function __construct( $name=null, $reset=null ) {
10 if( $name !== null ) {
12 $this->mTemporaryPassword
= $reset;
15 $this->mName
= $wgRequest->getVal( 'wpName' );
16 $this->mTemporaryPassword
= $wgRequest->getVal( 'wpPassword' );
21 * Main execution point
23 function execute( $par='' ) {
24 global $wgUser, $wgAuth, $wgOut, $wgRequest;
26 if( !$wgAuth->allowPasswordChange() ) {
27 $this->error( wfMsg( 'resetpass_forbidden' ) );
31 if( $this->mName
=== null && !$wgRequest->wasPosted() ) {
32 $this->error( wfMsg( 'resetpass_missing' ) );
36 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
37 $newpass = $wgRequest->getVal( 'wpNewPassword' );
38 $retype = $wgRequest->getVal( 'wpRetype' );
40 $this->attemptReset( $newpass, $retype );
41 $wgOut->addWikiText( wfMsg( 'resetpass_success' ) );
44 'action' => 'submitlogin',
45 'wpName' => $this->mName
,
46 'wpPassword' => $newpass,
47 'returnto' => $wgRequest->getVal( 'returnto' ),
49 if( $wgRequest->getCheck( 'wpRemember' ) ) {
50 $data['wpRemember'] = 1;
52 $login = new LoginForm( new FauxRequest( $data, true ) );
56 } catch( PasswordError
$e ) {
57 $this->error( $e->getMessage() );
63 function error( $msg ) {
65 $wgOut->addHtml( '<div class="errorbox">' .
66 htmlspecialchars( $msg ) .
71 global $wgOut, $wgUser, $wgLang, $wgRequest;
73 $self = SpecialPage
::getTitleFor( 'Resetpass' );
75 '<div id="userloginForm">' .
76 wfOpenElement( 'form',
79 'action' => $self->getLocalUrl() ) ) .
80 '<h2>' . wfMsgHtml( 'resetpass_header' ) . '</h2>' .
81 '<div id="userloginprompt">' .
82 wfMsgExt( 'resetpass_text', array( 'parse' ) ) .
85 wfHidden( 'token', $wgUser->editToken() ) .
86 wfHidden( 'wpName', $this->mName
) .
87 wfHidden( 'wpPassword', $this->mTemporaryPassword
) .
88 wfHidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) .
90 array( 'wpName', 'username', 'text', $this->mName
),
91 array( 'wpNewPassword', 'newpassword', 'password', '' ),
92 array( 'wpRetype', 'yourpasswordagain', 'password', '' ),
97 Xml
::checkLabel( wfMsg( 'remembermypassword' ),
98 'wpRemember', 'wpRemember',
99 $wgRequest->getCheck( 'wpRemember' ) ) .
105 wfSubmitButton( wfMsgHtml( 'resetpass_submit' ) ) .
109 wfCloseElement( 'form' ) .
111 $wgOut->addHtml( $form );
114 function pretty( $fields ) {
116 foreach( $fields as $list ) {
117 list( $name, $label, $type, $value ) = $list;
118 if( $type == 'text' ) {
119 $field = '<tt>' . htmlspecialchars( $value ) . '</tt>';
121 $field = Xml
::input( $name, 20, $value,
122 array( 'id' => $name, 'type' => $type ) );
125 $out .= '<td align="right">';
126 $out .= Xml
::label( wfMsg( $label ), $name );
137 * @throws PasswordError
139 function attemptReset( $newpass, $retype ) {
140 $user = User
::newFromName( $this->mName
);
141 if( $user->isAnon() ) {
142 throw new PasswordError( 'no such user' );
145 if( !$user->checkTemporaryPassword( $this->mTemporaryPassword
) ) {
146 throw new PasswordError( wfMsg( 'resetpass_bad_temporary' ) );
149 if( $newpass !== $retype ) {
150 throw new PasswordError( wfMsg( 'badretype' ) );
153 $user->setPassword( $newpass );
154 $user->saveSettings();