3 function wfSpecialUserlogin()
5 global $wpCreateaccount, $wpCreateaccountMail;
6 global $wpLoginattempt, $wpMailmypassword;
8 $wpCreateaccount = $_REQUEST["wpCreateaccount"];
9 $wpCreateaccountMail = $_REQUEST["wpCreateaccountMail"];
10 $wpLoginattempt = $_REQUEST["wpLoginattempt"];
11 $wpMailmypassword = $_REQUEST["wpMailmypassword"];
13 $fields = array( "wpName", "wpPassword", "wpName",
14 "wpPassword", "wpRetype", "wpEmail" );
15 wfCleanFormFields( $fields );
17 if ( isset( $wpCreateaccount ) ) {
19 } else if ( isset( $wpCreateaccountMail ) ) {
20 addNewAccountMailPassword();
21 } else if ( isset( $wpMailmypassword ) ) {
23 } else if ( "submit" == $action ||
isset( $wpLoginattempt ) ) {
31 /* private */ function addNewAccountMailPassword()
33 global $wgOut, $wpEmail, $wpName;
34 $wpEmail = $_REQUEST["wpEmail"];
35 $wpName = $_REQUEST["wpName"];
38 mainLoginForm( wfMsg( "noemail", $wpName ) );
42 $u = addNewaccountInternal();
49 if (mailPasswordInternal($u) == NULL)
54 $wgOut->setPageTitle( wfMsg( "accmailtitle" ) );
55 $wgOut->setRobotpolicy( "noindex,nofollow" );
56 $wgOut->setArticleFlag( false );
58 $wgOut->addWikiText( wfMsg( "accmailtext", $u->getName(), $u->getEmail() ) );
59 $wgOut->returnToMain( false );
65 /* private */ function addNewAccount()
67 global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
68 global $wpEmail, $wgDeferredUpdateList;
69 $wpPassword = $_REQUEST["wpPassword"];
70 $wpRetype = $_REQUEST["wpRetype"];
71 $wpName = $_REQUEST["wpName"];
72 $wpRemember = $_REQUEST["wpRemember"];
73 $wpEmail = $_REQUEST["wpEmail"];
75 $u = addNewAccountInternal();
82 successfulLogin( wfMsg( "welcomecreation", $wgUser->getName() ) );
86 /* private */ function addNewAccountInternal()
88 global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
89 global $wpEmail, $wgDeferredUpdateList;
96 if (!$wgUser->isAllowedToCreateAccount()) {
97 userNotPrivilegedMessage();
101 if ( 0 != strcmp( $wpPassword, $wpRetype ) ) {
102 mainLoginForm( wfMsg( "badretype" ) );
105 $wpName = trim( $wpName );
106 if ( ( "" == $wpName ) ||
107 preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $wpName ) ||
108 (strpos( $wpName, "/" ) !== false) )
110 mainLoginForm( wfMsg( "noname" ) );
113 if ( wfReadOnly() ) {
114 $wgOut->readOnlyPage();
117 $u = User
::newFromName( $wpName );
119 if ( 0 != $u->idForName() ) {
120 mainLoginForm( wfMsg( "userexists" ) );
124 $u->setPassword( $wpPassword );
125 $u->setEmail( $wpEmail );
126 if ( 1 == $wpRemember ) { $r = 1; }
128 $u->setOption( "rememberpassword", $r );
136 /* private */ function processLogin()
138 global $wgUser, $wpName, $wpPassword, $wpRemember;
140 $wpPassword = $_REQUEST["wpPassword"];
141 $wpName = $_REQUEST["wpName"];
142 $wpRemember = $_REQUEST["wpRemember"];
144 if (!cookieCheck()) {
148 if ( "" == $wpName ) {
149 mainLoginForm( wfMsg( "noname" ) );
152 $u = User
::newFromName( $wpName );
153 $id = $u->idForName();
155 mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
159 $u->loadFromDatabase();
160 $ep = $u->encryptPassword( $wpPassword );
161 if ( 0 != strcmp( $ep, $u->getPassword() ) ) {
162 if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) {
163 mainLoginForm( wfMsg( "wrongpassword" ) );
168 # We've verified now, update the real record
170 if ( 1 == $wpRemember ) {
172 $u->setCookiePassword( $wpPassword );
176 $u->setOption( "rememberpassword", $r );
179 successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) );
182 /* private */ function mailPassword()
184 global $wgUser, $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
185 global $wgCookiePath, $wgCookieDomain, $wgDBname;
187 if ( "" == $wpName ) {
188 mainLoginForm( wfMsg( "noname" ) );
191 $u = User
::newFromName( $wpName );
192 $id = $u->idForName();
194 mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
198 $u->loadFromDatabase();
200 if (mailPasswordInternal($u) == NULL) {
204 mainLoginForm( wfMsg( "passwordsent", $u->getName() ) );
208 /* private */ function mailPasswordInternal( $u )
210 global $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
211 global $wgPasswordSender;
213 if ( "" == $u->getEmail() ) {
214 mainLoginForm( wfMsg( "noemail", $u->getName() ) );
217 $np = User
::randomPassword();
218 $u->setNewpassword( $np );
220 setcookie( "{$wgDBname}Password", "", time() - 3600, $wgCookiePath, $wgCookieDomain );
223 $ip = getenv( "REMOTE_ADDR" );
224 if ( "" == $ip ) { $ip = "(Unknown)"; }
226 $m = wfMsg( "passwordremindertext", $ip, $u->getName(), $np );
228 mail( $u->getEmail(), wfMsg( "passwordremindertitle" ), $m,
229 "MIME-Version: 1.0\r\n" .
230 "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" .
231 "Content-transfer-encoding: 8bit\r\n" .
232 "From: $wgPasswordSender" );
241 /* private */ function successfulLogin( $msg )
243 global $wgUser, $wgOut, $returnto;
244 global $wgDeferredUpdateList;
246 $wgUser->setCookies();
247 $up = new UserUpdate();
248 array_push( $wgDeferredUpdateList, $up );
250 $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
251 $wgOut->setRobotpolicy( "noindex,nofollow" );
252 $wgOut->setArticleFlag( false );
253 $wgOut->addHTML( $msg . "\n<p>" );
254 $wgOut->returnToMain();
261 function userNotPrivilegedMessage()
263 global $wgOut, $wgUser, $wgLang;
265 $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) );
266 $wgOut->setRobotpolicy( "noindex,nofollow" );
267 $wgOut->setArticleFlag( false );
269 $wgOut->addWikiText( wfMsg( "whitelistacctext" ) );
270 $wgOut->returnToMain( false );
276 /* private */ function mainLoginForm( $err )
278 global $wgUser, $wgOut, $wgLang, $returnto;
279 global $wpName, $wpPassword, $wpRetype, $wpRemember;
280 global $wpEmail, $HTTP_COOKIE_VARS, $wgDBname;
282 $le = wfMsg( "loginerror" );
283 $yn = wfMsg( "yourname" );
284 $yp = wfMsg( "yourpassword" );
285 $ypa = wfMsg( "yourpasswordagain" );
286 $rmp = wfMsg( "remembermypassword" );
287 $ayn = wfMsg( "areyounew" );
288 $nuo = wfMsg( "newusersonly" );
289 $li = wfMsg( "login" );
290 $ca = wfMsg( "createaccount" );
291 $cam = wfMsg( "createaccountmail" );
292 $ye = wfMsg( "youremail" );
293 $efl = wfMsg( "emailforlost" );
294 $mmp = wfMsg( "mailmypassword" );
298 if ( 0 != $wgUser->getID() ) {
299 $name = $wgUser->getName();
301 $name = $HTTP_COOKIE_VARS["{$wgDBname}UserName"];
306 $wgOut->setPageTitle( wfMsg( "userlogin" ) );
307 $wgOut->setRobotpolicy( "noindex,nofollow" );
308 $wgOut->setArticleFlag( false );
311 $wgOut->addHTML( "<h2>$li:</h2>\n" );
313 $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1'
314 color='red'>$err</font>\n" );
316 if ( 1 == $wgUser->getOption( "rememberpassword" ) ) {
317 $checked = " checked";
321 $q = "action=submit";
322 if ( "" != $returnto ) { $q .= "&returnto=" . wfUrlencode($returnto); }
323 $action = wfLocalUrlE( $wgLang->specialPage( "Userlogin" ), $q );
325 $wpName = wfEscapeHTML( $wpName );
326 $wpPassword = wfEscapeHTML( $wpPassword );
327 $wpRetype = wfEscapeHTML( $wpRetype );
328 $wpEmail = wfEscapeHTML( $wpEmail );
330 if ($wgUser->getID() != 0) {
331 $cambutton = "<input tabindex=6 type=submit name=\"wpCreateaccountMail\" value=\"{$cam}\">";
335 <form name=\"userlogin\" id=\"userlogin\" method=\"post\" action=\"{$action}\">
337 <td align=right>$yn:</td>
338 <td colspan=2 align=left>
339 <input tabindex=1 type=text name=\"wpName\" value=\"{$name}\" size=20>
341 <td align=right>$yp:</td>
343 <input tabindex=2 type=password name=\"wpPassword\" value=\"{$pwd}\" size=20>
346 <input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
349 if ($wgUser->isAllowedToCreateAccount()) {
351 $wgOut->addHTML("<tr><td colspan=3> </td></tr><tr>
352 <td align=right>$ypa:</td>
354 <input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\"
356 </td><td>$nuo</td></tr>
358 <td align=right>$ye:</td>
360 <input tabindex=5 type=text name=\"wpEmail\" value=\"{$wpEmail}\" size=20>
362 <input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
369 <td colspan=3 align=left>
370 <input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\" id=\"wpRemember\"$checked><label for=\"wpRemember\">$rmp</label>
372 <tr><td colspan=3> </td></tr><tr>
373 <td colspan=3 align=left>
375 <input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">
383 /* private */ function cookieCheck() {
385 global $HTTP_COOKIE_VARS, $wgOut, $returnto;
386 global $wgDisableCookieCheck;
388 if ( $wgDisableCookieCheck ) {
392 # XXX: kind of crude check to see if cookies are enabled, but it works OK
394 if ( "" == $HTTP_COOKIE_VARS[session_name()])
396 # Don't go back to login page; they won't get time to
397 # enable cookies and send us one, so they'll get this msg again. Instead,
398 # let them enable cookies on the error page, then go back to login page.
399 # XXX: wipes returnto, unfortunately.
401 $returnto = "Special:Userlogin";
402 $wgOut->errorpage( "nocookies", "nocookiestext" );