3 function wfSpecialUserlogin()
5 global $wpCreateaccount, $wpLoginattempt, $wpMailmypassword;
8 $fields = array( "wpName", "wpPassword", "wpName",
9 "wpPassword", "wpRetype", "wpEmail" );
10 wfCleanFormFields( $fields );
12 if ( isset( $wpCreateaccount ) ) {
14 } else if ( isset( $wpMailmypassword ) ) {
16 } else if ( "submit" == $action ||
isset( $wpLoginattempt ) ) {
23 /* private */ function addNewAccount()
25 global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
26 global $wpEmail, $wgDeferredUpdateList;
28 if ( 0 != strcmp( $wpPassword, $wpRetype ) ) {
29 mainLoginForm( wfMsg( "badretype" ) );
32 $wpName = trim( $wpName );
33 if ( ( "" == $wpName ) ||
34 preg_match( "/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/", $wpName ) )
36 mainLoginForm( wfMsg( "noname" ) );
40 $wgOut->readOnlyPage();
43 $u = User
::newFromName( $wpName );
45 if ( 0 != $u->idForName() ) {
46 mainLoginForm( wfMsg( "userexists" ) );
50 $u->setPassword( $wpPassword );
51 $u->setEmail( $wpEmail );
52 if ( 1 == $wpRemember ) { $r = 1; }
54 $u->setOption( "rememberpassword", $r );
57 $m = str_replace( "$1", $wgUser->getName(), wfMsg( "welcomecreation" ) );
58 successfulLogin( $m );
61 /* private */ function processLogin()
63 global $wgUser, $wpName, $wpPassword, $wpRemember;
66 if ( "" == $wpName ) {
67 mainLoginForm( wfMsg( "noname" ) );
70 $u = User
::newFromName( $wpName );
71 $id = $u->idForName();
73 $m = str_replace( "$1", $u->getName(), wfMsg( "nosuchuser" ) );
78 $u->loadFromDatabase();
79 $ep = $u->encryptPassword( $wpPassword );
80 if ( 0 != strcmp( $ep, $u->getPassword() ) ) {
81 if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) {
82 mainLoginForm( wfMsg( "wrongpassword" ) );
87 # We've verified now, update the real record
89 if ( 1 == $wpRemember ) {
91 $u->setCookiePassword( $wpPassword );
95 $u->setOption( "rememberpassword", $r );
98 $m = str_replace( "$1", $wgUser->getName(), wfMsg( "loginsuccess" ) );
99 successfulLogin( $m );
102 /* private */ function mailPassword()
104 global $wgUser, $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
106 if ( "" == $wpName ) {
107 mainLoginForm( wfMsg( "noname" ) );
110 $u = User
::newFromName( $wpName );
111 $id = $u->idForName();
113 $m = str_replace( "$1", $u->getName(), wfMsg( "nosuchuser" ) );
118 $u->loadFromDatabase();
120 if ( "" == $u->getEmail() ) {
121 $m = str_replace( "$1", $u->getName(), wfMsg( "noemail" ) );
125 $np = User
::randomPassword();
126 $u->setNewpassword( $np );
128 setcookie( "wcUserPassword", "", time() - 3600 );
131 $ip = getenv( "REMOTE_ADDR" );
132 if ( "" == $ip ) { $ip = "(Unknown)"; }
134 $m = str_replace( "$1", $ip, wfMsg( "passwordremindertext" ) );
135 $m = str_replace( "$2", $u->getName(), $m );
136 $m = str_replace( "$3", $np, $m );
138 #FIXME: Generilize the email addresses for 3rd party sites...
139 mail( $u->getEmail(), wfMsg( "passwordremindertitle" ), $m,
140 "MIME-Version: 1.0\r\n" .
141 "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" .
142 "Content-transfer-encoding: 8bit\r\n" .
143 "From: Wikipedia Mail <apache@www.wikipedia.org>\r\n" .
144 "Reply-To: webmaster@www.wikipedia.org" );
145 $m = str_replace( "$1", $u->getName(), wfMsg( "passwordsent" ) );
149 /* private */ function successfulLogin( $msg )
151 global $wgUser, $wgOut, $returnto;
152 global $wgDeferredUpdateList;
154 $wgUser->setCookies();
155 $up = new UserUpdate();
156 array_push( $wgDeferredUpdateList, $up );
158 $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
159 $wgOut->setRobotpolicy( "noindex,nofollow" );
160 $wgOut->setArticleFlag( false );
161 $wgOut->addHTML( $msg . "\n<p>" );
162 $wgOut->returnToMain();
165 /* private */ function mainLoginForm( $err )
167 global $wgUser, $wgOut, $wgLang, $returnto;
168 global $wpName, $wpPassword, $wpRetype, $wpRemember;
169 global $wpEmail, $HTTP_COOKIE_VARS;
171 $le = wfMsg( "loginerror" );
172 $yn = wfMsg( "yourname" );
173 $yp = wfMsg( "yourpassword" );
174 $ypa = wfMsg( "yourpasswordagain" );
175 $rmp = wfMsg( "remembermypassword" );
176 $ayn = wfMsg( "areyounew" );
177 $nuo = wfMsg( "newusersonly" );
178 $li = wfMsg( "login" );
179 $ca = wfMsg( "createaccount" );
180 $ye = wfMsg( "youremail" );
181 $efl = wfMsg( "emailforlost" );
182 $mmp = wfMsg( "mailmypassword" );
186 if ( 0 != $wgUser->getID() ) {
187 $name = $wgUser->getName();
189 $name = $HTTP_COOKIE_VARS["wcUserName"];
194 $wgOut->setPageTitle( wfMsg( "userlogin" ) );
195 $wgOut->setRobotpolicy( "noindex,nofollow" );
196 $wgOut->setArticleFlag( false );
199 $wgOut->addHTML( "<h2>$li:</h2>\n" );
201 $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1'
202 color='red'>$err</font>\n" );
204 if ( 1 == $wgUser->getOption( "rememberpassword" ) ) {
205 $checked = " checked";
209 $q = "action=submit";
210 if ( "" != $returnto ) { $q .= "&returnto=" . wfUrlencode($returnto); }
211 $action = wfLocalUrlE( $wgLang->specialPage( "Userlogin" ), $q );
213 $wpName = wfEscapeHTML( $wpName );
214 $wpPassword = wfEscapeHTML( $wpPassword );
215 $wpRetype = wfEscapeHTML( $wpRetype );
216 $wpEmail = wfEscapeHTML( $wpEmail );
219 <form id=\"userlogin\" method=\"post\" action=\"{$action}\">
221 <td align=right>$yn:</td>
222 <td colspan=2 align=left>
223 <input tabindex=1 type=text name=\"wpName\" value=\"{$name}\" size=20>
225 <td align=right>$yp:</td>
227 <input tabindex=2 type=password name=\"wpPassword\" value=\"{$pwd}\" size=20>
230 <input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
232 <tr><td colspan=3> </td></tr><tr>
233 <td align=right>$ypa:</td>
235 <input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\"
237 </td><td>$nuo</td></tr>
239 <td align=right>$ye:</td>
241 <input tabindex=5 type=text name=\"wpEmail\" value=\"{$wpEmail}\" size=20>
243 <input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
246 <td colspan=3 align=left>
247 <input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\"$checked>$rmp
249 <tr><td colspan=3> </td></tr><tr>
250 <td colspan=3 align=left>
252 <input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">