specialPage( "Userlogout" ) ) $returnto = ""; $wpCookieCheck = $_REQUEST[ "wpCookieCheck" ]; if ( isset( $wpCookieCheck ) ) { onCookieRedirectCheck( $wpCookieCheck ); } else if ( isset( $wpCreateaccount ) ) { addNewAccount(); } else if ( isset( $wpCreateaccountMail ) ) { addNewAccountMailPassword(); } else if ( isset( $wpMailmypassword ) ) { mailPassword(); } else if ( "submit" == $action || isset( $wpLoginattempt ) ) { processLogin(); } else { mainLoginForm( "" ); } } /* private */ function addNewAccountMailPassword() { global $wgOut, $wpEmail, $wpName; if ("" == $wpEmail) { mainLoginForm( wfMsg( "noemail", $wpName ) ); return; } $u = addNewaccountInternal(); if ($u == NULL) { return; } $u->saveSettings(); if (mailPasswordInternal($u) == NULL) { return; } $wgOut->setPageTitle( wfMsg( "accmailtitle" ) ); $wgOut->setRobotpolicy( "noindex,nofollow" ); $wgOut->setArticleFlag( false ); $wgOut->addWikiText( wfMsg( "accmailtext", $u->getName(), $u->getEmail() ) ); $wgOut->returnToMain( false ); $u = 0; } /* private */ function addNewAccount() { global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember; global $wpEmail, $wgDeferredUpdateList; $u = addNewAccountInternal(); if ($u == NULL) { return; } $wgUser = $u; $wgUser->setCookies(); $up = new UserUpdate(); array_push( $wgDeferredUpdateList, $up ); if( hasSessionCookie() ) { return successfulLogin( wfMsg( "welcomecreation", $wgUser->getName() ) ); } else { return cookieRedirectCheck( "new" ); } } /* private */ function addNewAccountInternal() { global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember; global $wpEmail; if (!$wgUser->isAllowedToCreateAccount()) { userNotPrivilegedMessage(); return; } if ( 0 != strcmp( $wpPassword, $wpRetype ) ) { mainLoginForm( wfMsg( "badretype" ) ); return; } $wpName = trim( $wpName ); if ( ( "" == $wpName ) || preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $wpName ) || (strpos( $wpName, "/" ) !== false) ) { mainLoginForm( wfMsg( "noname" ) ); return; } if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } $u = User::newFromName( $wpName ); if ( 0 != $u->idForName() ) { mainLoginForm( wfMsg( "userexists" ) ); return; } $u->addToDatabase(); $u->setPassword( $wpPassword ); $u->setEmail( $wpEmail ); if ( 1 == $wpRemember ) { $r = 1; } else { $r = 0; } $u->setOption( "rememberpassword", $r ); return $u; } /* private */ function processLogin() { global $wgUser, $wpName, $wpPassword, $wpRemember; global $wgDeferredUpdateList; global $returnto; if ( "" == $wpName ) { mainLoginForm( wfMsg( "noname" ) ); return; } $u = User::newFromName( $wpName ); $id = $u->idForName(); if ( 0 == $id ) { mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) ); return; } $u->setId( $id ); $u->loadFromDatabase(); $ep = $u->encryptPassword( $wpPassword ); if ( 0 != strcmp( $ep, $u->getPassword() ) ) { if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) { mainLoginForm( wfMsg( "wrongpassword" ) ); return; } } # We've verified now, update the real record # if ( 1 == $wpRemember ) { $r = 1; $u->setCookiePassword( $wpPassword ); } else { $r = 0; } $u->setOption( "rememberpassword", $r ); $wgUser = $u; $wgUser->setCookies(); $up = new UserUpdate(); array_push( $wgDeferredUpdateList, $up ); if( hasSessionCookie() ) { return successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) ); } else { return cookieRedirectCheck( "login" ); } } /* private */ function mailPassword() { global $wgUser, $wpName, $wgDeferredUpdateList, $wgOutputEncoding; global $wgCookiePath, $wgCookieDomain, $wgDBname; if ( "" == $wpName ) { mainLoginForm( wfMsg( "noname" ) ); return; } $u = User::newFromName( $wpName ); $id = $u->idForName(); if ( 0 == $id ) { mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) ); return; } $u->setId( $id ); $u->loadFromDatabase(); if (mailPasswordInternal($u) == NULL) { return; } mainLoginForm( wfMsg( "passwordsent", $u->getName() ) ); } /* private */ function mailPasswordInternal( $u ) { global $wpName, $wgDeferredUpdateList, $wgOutputEncoding; global $wgPasswordSender, $wgDBname; if ( "" == $u->getEmail() ) { mainLoginForm( wfMsg( "noemail", $u->getName() ) ); return; } $np = User::randomPassword(); $u->setNewpassword( $np ); setcookie( "{$wgDBname}Password", "", time() - 3600, $wgCookiePath, $wgCookieDomain ); $u->saveSettings(); $ip = getenv( "REMOTE_ADDR" ); if ( "" == $ip ) { $ip = "(Unknown)"; } $m = wfMsg( "passwordremindertext", $ip, $u->getName(), $np ); mail( $u->getEmail(), wfMsg( "passwordremindertitle" ), $m, "MIME-Version: 1.0\r\n" . "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" . "Content-transfer-encoding: 8bit\r\n" . "From: $wgPasswordSender" ); return $u; } /* private */ function successfulLogin( $msg ) { global $wgUser; global $wgDeferredUpdateList; global $wgOut; $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) ); $wgOut->setRobotpolicy( "noindex,nofollow" ); $wgOut->setArticleFlag( false ); $wgOut->addHTML( $msg . "\n

" ); $wgOut->returnToMain(); } function userNotPrivilegedMessage() { global $wgOut, $wgUser, $wgLang; $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) ); $wgOut->setRobotpolicy( "noindex,nofollow" ); $wgOut->setArticleFlag( false ); $wgOut->addWikiText( wfMsg( "whitelistacctext" ) ); $wgOut->returnToMain( false ); } /* private */ function mainLoginForm( $err ) { global $wgUser, $wgOut, $wgLang, $returnto; global $wpName, $wpPassword, $wpRetype, $wpRemember; global $wpEmail, $HTTP_COOKIE_VARS, $wgDBname; $le = wfMsg( "loginerror" ); $yn = wfMsg( "yourname" ); $yp = wfMsg( "yourpassword" ); $ypa = wfMsg( "yourpasswordagain" ); $rmp = wfMsg( "remembermypassword" ); $nuo = wfMsg( "newusersonly" ); $li = wfMsg( "login" ); $ca = wfMsg( "createaccount" ); $cam = wfMsg( "createaccountmail" ); $ye = wfMsg( "youremail" ); $efl = wfMsg( "emailforlost" ); $mmp = wfMsg( "mailmypassword" ); $name = $wpName; if ( "" == $name ) { if ( 0 != $wgUser->getID() ) { $name = $wgUser->getName(); } else { $name = $HTTP_COOKIE_VARS["{$wgDBname}UserName"]; } } $pwd = $wpPassword; $wgOut->setPageTitle( wfMsg( "userlogin" ) ); $wgOut->setRobotpolicy( "noindex,nofollow" ); $wgOut->setArticleFlag( false ); if ( "" == $err ) { $lp = wfMsg( "loginprompt" ); $wgOut->addHTML( "

$li:

\n

$lp

" ); } else { $wgOut->addHTML( "

$le:

\n$err\n" ); } if ( 1 == $wgUser->getOption( "rememberpassword" ) ) { $checked = " checked"; } else { $checked = ""; } $q = "action=submit"; if ( "" != $returnto ) { $q .= "&returnto=" . wfUrlencode($returnto); } $action = wfLocalUrlE( $wgLang->specialPage( "Userlogin" ), $q ); $wpName = wfEscapeHTML( $wpName ); $wpPassword = wfEscapeHTML( $wpPassword ); $wpRetype = wfEscapeHTML( $wpRetype ); $wpEmail = wfEscapeHTML( $wpEmail ); if ($wgUser->getID() != 0) { $cambutton = ""; } $wgOut->addHTML( "
"); if ($wgUser->isAllowedToCreateAccount()) { $wgOut->addHTML(""); } $wgOut->addHTML("
$yn:
$yp:
 
$ypa: $nuo
$ye: $cambutton
 

$efl

\n" ); } /* private */ function hasSessionCookie() { global $wgDisableCookieCheck; return ( $wgDisableCookieCheck ) ? true : ( "" != $_COOKIE[session_name()] ); } /* private */ function cookieRedirectCheck( $type ) { global $wgOut, $wgLang; $check = wfLocalUrl( $wgLang->specialPage( "Userlogin" ), "wpCookieCheck=$type" ); return $wgOut->redirect( $check ); } /* private */ function onCookieRedirectCheck( $type ) { global $wgUser; if ( !hasSessionCookie() ) { if ( $type == "new" ) { return mainLoginForm( wfMsg( "nocookiesnew" ) ); } else if ( $type == "login" ) { return mainLoginForm( wfMsg( "nocookieslogin" ) ); } else { # shouldn't happen return mainLoginForm( wfMsg( "error" ) ); } } else { return successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) ); } } ?>