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 ) ) {
35 mainLoginForm( wfMsg( "noname" ) );
39 $wgOut->readOnlyPage();
42 $u = User
::newFromName( $wpName );
44 if ( 0 != $u->idForName() ) {
45 mainLoginForm( wfMsg( "userexists" ) );
49 $u->setPassword( $wpPassword );
50 $u->setEmail( $wpEmail );
51 if ( 1 == $wpRemember ) { $r = 1; }
53 $u->setOption( "rememberpassword", $r );
56 $m = str_replace( "$1", $wgUser->getName(), wfMsg( "welcomecreation" ) );
57 successfulLogin( $m );
60 /* private */ function processLogin()
62 global $wgUser, $wpName, $wpPassword, $wpRemember;
65 if ( "" == $wpName ) {
66 mainLoginForm( wfMsg( "noname" ) );
69 $u = User
::newFromName( $wpName );
70 $id = $u->idForName();
72 $m = str_replace( "$1", $u->getName(), wfMsg( "nosuchuser" ) );
77 $u->loadFromDatabase();
78 $ep = User
::encryptPassword( $wpPassword );
79 if ( 0 != strcmp( $ep, $u->getPassword() ) ) {
80 if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) {
81 mainLoginForm( wfMsg( "wrongpassword" ) );
85 # We've verified now, update the real record
87 if ( 1 == $wpRemember ) { $r = 1; }
89 $u->setOption( "rememberpassword", $r );
92 $m = str_replace( "$1", $wgUser->getName(), wfMsg( "loginsuccess" ) );
93 successfulLogin( $m );
96 /* private */ function mailPassword()
98 global $wgUser, $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
100 if ( "" == $wpName ) {
101 mainLoginForm( wfMsg( "noname" ) );
104 $u = User
::newFromName( $wpName );
105 $id = $u->idForName();
107 $m = str_replace( "$1", $u->getName(), wfMsg( "nosuchuser" ) );
112 $u->loadFromDatabase();
114 if ( "" == $u->getEmail() ) {
115 $m = str_replace( "$1", $u->getName(), wfMsg( "noemail" ) );
119 $np = User
::randomPassword();
120 $u->setNewpassword( $np );
121 setcookie( "wcUserPassword", "", time() - 3600 );
124 $ip = getenv( "REMOTE_ADDR" );
125 if ( "" == $ip ) { $ip = "(Unknown)"; }
127 $m = str_replace( "$1", $ip, wfMsg( "passwordremindertext" ) );
128 $m = str_replace( "$2", $u->getName(), $m );
129 $m = str_replace( "$3", $np, $m );
131 #FIXME: Generilize the email addresses for 3rd party sites...
132 mail( $u->getEmail(), wfMsg( "passwordremindertitle" ), $m,
133 "MIME-Version: 1.0\r\n" .
134 "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" .
135 "Content-transfer-encoding: 8bit\r\n" .
136 "From: Wikipedia Mail <apache@www.wikipedia.org>\r\n" .
137 "Reply-To: webmaster@www.wikipedia.org" );
138 $m = str_replace( "$1", $u->getName(), wfMsg( "passwordsent" ) );
142 /* private */ function successfulLogin( $msg )
144 global $wgUser, $wgOut, $returnto;
145 global $wgDeferredUpdateList;
147 $wgUser->setCookies();
148 $up = new UserUpdate();
149 array_push( $wgDeferredUpdateList, $up );
151 $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
152 $wgOut->setRobotpolicy( "noindex,nofollow" );
153 $wgOut->setArticleFlag( false );
154 $wgOut->addHTML( $msg . "\n<p>" );
155 $wgOut->returnToMain();
158 /* private */ function mainLoginForm( $err )
160 global $wgUser, $wgOut, $wgLang, $returnto;
161 global $wpName, $wpPassword, $wpRetype, $wpRemember;
162 global $wpEmail, $HTTP_COOKIE_VARS;
164 $le = wfMsg( "loginerror" );
165 $yn = wfMsg( "yourname" );
166 $yp = wfMsg( "yourpassword" );
167 $ypa = wfMsg( "yourpasswordagain" );
168 $rmp = wfMsg( "remembermypassword" );
169 $ayn = wfMsg( "areyounew" );
170 $nuo = wfMsg( "newusersonly" );
171 $li = wfMsg( "login" );
172 $ca = wfMsg( "createaccount" );
173 $ye = wfMsg( "youremail" );
174 $efl = wfMsg( "emailforlost" );
175 $mmp = wfMsg( "mailmypassword" );
179 if ( 0 != $wgUser->getID() ) {
180 $name = $wgUser->getName();
182 $name = $HTTP_COOKIE_VARS["wcUserName"];
187 $wgOut->setPageTitle( wfMsg( "userlogin" ) );
188 $wgOut->setRobotpolicy( "noindex,nofollow" );
189 $wgOut->setArticleFlag( false );
192 $wgOut->addHTML( "<h2>$li:</h2>\n" );
194 $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1' color='red'>$err</font>\n" );
196 if ( 1 == $wgUser->getOption( "rememberpassword" ) ) {
197 $checked = " checked";
201 $q = "action=submit";
202 if ( "" != $returnto ) { $q .= "&returnto=" . wfUrlencode($returnto); }
203 $action = wfLocalUrlE( $wgLang->specialPage( "Userlogin" ), $q );
205 $wpName = wfEscapeHTML( $wpName );
206 $wpPassword = wfEscapeHTML( $wpPassword );
207 $wpRetype = wfEscapeHTML( $wpRetype );
208 $wpEmail = wfEscapeHTML( $wpEmail );
211 <form id=\"userlogin\" method=\"post\" action=\"{$action}\">
213 <td align=right>$yn:</td>
214 <td colspan=2 align=left>
215 <input tabindex=1 type=text name=\"wpName\" value=\"{$name}\" size=20>
217 <td align=right>$yp:</td>
219 <input tabindex=2 type=password name=\"wpPassword\" value=\"{$pwd}\" size=20>
222 <input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
224 <tr><td colspan=3> </td></tr><tr>
225 <td align=right>$ypa:</td>
227 <input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\" size=20>
228 </td><td>$nuo</td></tr>
230 <td align=right>$ye:</td>
232 <input tabindex=5 type=text name=\"wpEmail\" value=\"{$wpEmail}\" size=20>
234 <input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
237 <td colspan=3 align=left>
238 <input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\"$checked>$rmp
240 <tr><td colspan=3> </td></tr><tr>
241 <td colspan=3 align=left>
243 <input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">