3 function wfSpecialUserlogin()
5 global $wpCreateaccount, $wpCreateaccountMail;
6 global $wpLoginattempt, $wpMailmypassword;
7 global $action, $_REQUEST;
9 $fields = array( "wpName", "wpPassword", "wpName",
10 "wpPassword", "wpRetype", "wpEmail" );
11 wfCleanFormFields( $fields );
13 $wpCookieCheck = $_REQUEST[ "wpCookieCheck" ];
15 if ( isset( $wpCookieCheck ) ) {
16 onCookieRedirectCheck( $wpCookieCheck );
17 } else 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;
36 mainLoginForm( wfMsg( "noemail", $wpName ) );
40 $u = addNewaccountInternal();
47 if (mailPasswordInternal($u) == NULL)
52 $wgOut->setPageTitle( wfMsg( "accmailtitle" ) );
53 $wgOut->setRobotpolicy( "noindex,nofollow" );
54 $wgOut->setArticleFlag( false );
56 $wgOut->addWikiText( wfMsg( "accmailtext", $u->getName(), $u->getEmail() ) );
57 $wgOut->returnToMain( false );
63 /* private */ function addNewAccount()
65 global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
66 global $wpEmail, $wgDeferredUpdateList;
68 $u = addNewAccountInternal();
75 $wgUser->setCookies();
77 $up = new UserUpdate();
78 array_push( $wgDeferredUpdateList, $up );
80 if (hasSessionCookie()) {
81 return successfulLogin( wfMsg( "welcomecreation", $wgUser->getName() ) );
83 return cookieRedirectCheck("new");
88 /* private */ function addNewAccountInternal()
90 global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
93 if (!$wgUser->isAllowedToCreateAccount()) {
94 userNotPrivilegedMessage();
98 if ( 0 != strcmp( $wpPassword, $wpRetype ) ) {
99 mainLoginForm( wfMsg( "badretype" ) );
102 $wpName = trim( $wpName );
103 if ( ( "" == $wpName ) ||
104 preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $wpName ) ||
105 (strpos( $wpName, "/" ) !== false) )
107 mainLoginForm( wfMsg( "noname" ) );
110 if ( wfReadOnly() ) {
111 $wgOut->readOnlyPage();
114 $u = User
::newFromName( $wpName );
116 if ( 0 != $u->idForName() ) {
117 mainLoginForm( wfMsg( "userexists" ) );
121 $u->setPassword( $wpPassword );
122 $u->setEmail( $wpEmail );
123 if ( 1 == $wpRemember ) { $r = 1; }
125 $u->setOption( "rememberpassword", $r );
133 /* private */ function processLogin()
135 global $wgUser, $wpName, $wpPassword, $wpRemember;
136 global $wgDeferredUpdateList;
139 if ( "" == $wpName ) {
140 mainLoginForm( wfMsg( "noname" ) );
143 $u = User
::newFromName( $wpName );
144 $id = $u->idForName();
146 mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
150 $u->loadFromDatabase();
151 $ep = $u->encryptPassword( $wpPassword );
152 if ( 0 != strcmp( $ep, $u->getPassword() ) ) {
153 if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) {
154 mainLoginForm( wfMsg( "wrongpassword" ) );
159 # We've verified now, update the real record
161 if ( 1 == $wpRemember ) {
163 $u->setCookiePassword( $wpPassword );
167 $u->setOption( "rememberpassword", $r );
170 $wgUser->setCookies();
172 $up = new UserUpdate();
173 array_push( $wgDeferredUpdateList, $up );
175 if (hasSessionCookie()) {
176 return successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) );
178 return cookieRedirectCheck( "login" );
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 )
244 global $wgDeferredUpdateList;
245 global $wgOut, $returnto;
247 $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
248 $wgOut->setRobotpolicy( "noindex,nofollow" );
249 $wgOut->setArticleFlag( false );
250 $wgOut->addHTML( $msg . "\n<p>" );
251 $wgOut->returnToMain();
254 function userNotPrivilegedMessage()
256 global $wgOut, $wgUser, $wgLang;
258 $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) );
259 $wgOut->setRobotpolicy( "noindex,nofollow" );
260 $wgOut->setArticleFlag( false );
262 $wgOut->addWikiText( wfMsg( "whitelistacctext" ) );
263 $wgOut->returnToMain( false );
266 /* private */ function mainLoginForm( $err )
268 global $wgUser, $wgOut, $wgLang, $returnto;
269 global $wpName, $wpPassword, $wpRetype, $wpRemember;
270 global $wpEmail, $HTTP_COOKIE_VARS, $wgDBname;
272 $le = wfMsg( "loginerror" );
273 $yn = wfMsg( "yourname" );
274 $yp = wfMsg( "yourpassword" );
275 $ypa = wfMsg( "yourpasswordagain" );
276 $rmp = wfMsg( "remembermypassword" );
277 $ayn = wfMsg( "areyounew" );
278 $nuo = wfMsg( "newusersonly" );
279 $li = wfMsg( "login" );
280 $ca = wfMsg( "createaccount" );
281 $cam = wfMsg( "createaccountmail" );
282 $ye = wfMsg( "youremail" );
283 $efl = wfMsg( "emailforlost" );
284 $mmp = wfMsg( "mailmypassword" );
288 if ( 0 != $wgUser->getID() ) {
289 $name = $wgUser->getName();
291 $name = $HTTP_COOKIE_VARS["{$wgDBname}UserName"];
296 $wgOut->setPageTitle( wfMsg( "userlogin" ) );
297 $wgOut->setRobotpolicy( "noindex,nofollow" );
298 $wgOut->setArticleFlag( false );
301 $lp = wfMsg( "loginprompt" );
302 $wgOut->addHTML( "<h2>$li:</h2>\n<p>$lp</p>" );
304 $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1'
305 color='red'>$err</font>\n" );
307 if ( 1 == $wgUser->getOption( "rememberpassword" ) ) {
308 $checked = " checked";
312 $q = "action=submit";
313 if ( "" != $returnto ) { $q .= "&returnto=" . wfUrlencode($returnto); }
314 $action = wfLocalUrlE( $wgLang->specialPage( "Userlogin" ), $q );
316 $wpName = wfEscapeHTML( $wpName );
317 $wpPassword = wfEscapeHTML( $wpPassword );
318 $wpRetype = wfEscapeHTML( $wpRetype );
319 $wpEmail = wfEscapeHTML( $wpEmail );
321 if ($wgUser->getID() != 0) {
322 $cambutton = "<input tabindex=6 type=submit name=\"wpCreateaccountMail\" value=\"{$cam}\">";
326 <form name=\"userlogin\" id=\"userlogin\" method=\"post\" action=\"{$action}\">
328 <td align=right>$yn:</td>
329 <td colspan=2 align=left>
330 <input tabindex=1 type=text name=\"wpName\" value=\"{$name}\" size=20>
332 <td align=right>$yp:</td>
334 <input tabindex=2 type=password name=\"wpPassword\" value=\"{$pwd}\" size=20>
337 <input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
340 if ($wgUser->isAllowedToCreateAccount()) {
342 $wgOut->addHTML("<tr><td colspan=3> </td></tr><tr>
343 <td align=right>$ypa:</td>
345 <input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\"
347 </td><td>$nuo</td></tr>
349 <td align=right>$ye:</td>
351 <input tabindex=5 type=text name=\"wpEmail\" value=\"{$wpEmail}\" size=20>
353 <input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
360 <td colspan=3 align=left>
361 <input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\" id=\"wpRemember\"$checked><label for=\"wpRemember\">$rmp</label>
363 <tr><td colspan=3> </td></tr><tr>
364 <td colspan=3 align=left>
366 <input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">
374 /* private */ function hasSessionCookie()
376 global $HTTP_COOKIE_VARS;
377 global $wgDisableCookieCheck;
379 return ( $wgDisableCookieCheck ) ?
true : ( "" != $HTTP_COOKIE_VARS[session_name()]);
382 /* private */ function cookieRedirectCheck( $type )
384 global $wgOut, $wgLang;
386 $check = wfLocalUrl( $wgLang->specialPage( "Userlogin" ),
387 "wpCookieCheck=$type" );
389 return $wgOut->redirect( $check );
392 /* private */ function onCookieRedirectCheck( $type ) {
396 if (!hasSessionCookie()) {
397 if ( $type == "new" ) {
398 return mainLoginForm( wfMsg( "nocookiesnew" ) );
399 } else if ( $type == "login" ) {
400 return mainLoginForm( wfMsg( "nocookieslogin" ) );
403 return mainLoginForm( wfMsg( "error" ) );
406 return successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) );