/** * Set a user's email * @param $email Mixed: email address to set to the user * @param $changeReason String: reason for change * @return Boolean: true on success, false on failure (i.e. if we were given an invalid email address) */ function setEmail($email, $changeReason = '') { $oldEmail = $this->mUser->getEmail(); if (Sanitizer::validateEmail($email) || $email == '') { $this->mUser->setEmail($email); if ($email != '') { UserLoginHelper::removeNotConfirmedFlag($this->mUser); $this->mUser->confirmEmail(); $this->mUser->setGlobalAttribute('new_email', null); } else { if ($this->mUser->getGlobalFlag(UserLoginSpecialController::NOT_CONFIRMED_SIGNUP_OPTION_NAME)) { // User not confirmed on signup can't has empty email // @TODO introduce new message since usecase here is same as temp user empty email but it's not temp user anymore $this->mStatusMsg = wfMsg('editaccount-error-tempuser-email'); return false; } $this->mUser->invalidateEmail(); } $this->mUser->saveSettings(); // Check if everything went through OK, just in case if ($this->mUser->getEmail() == $email) { global $wgUser, $wgTitle; $log = new LogPage('editaccnt'); $log->addEntry('mailchange', $wgTitle, $changeReason, array($this->mUser->getUserPage())); if ($email == '') { $this->mStatusMsg = wfMsg('editaccount-success-email-blank', $this->mUser->mName); } else { $this->mStatusMsg = wfMsg('editaccount-success-email', $this->mUser->mName, $email); } wfRunHooks('EditAccountEmailChanged', array($this->mUser)); return true; } else { $this->mStatusMsg = wfMsg('editaccount-error-email', $this->mUser->mName); return false; } } else { $this->mStatusMsg = wfMsg('editaccount-invalid-email', $email); return false; } }
/** * Confirm email page. * @requestParam string code - on GET, POST * @requestParam string username - on POST * @requestParam string password - on POST * @responseParam string result [ok/error] * @responseParam string msg - result messages * @responseParam string errParam - error param */ public function index() { $this->response->addAsset('extensions/wikia/UserLogin/css/UserLogin.scss'); // hide things in the skin $this->wg->SuppressWikiHeader = false; $this->wg->SuppressPageHeader = false; $this->wg->SuppressFooter = true; $this->wg->SuppressAds = true; $this->wg->SuppressToolbar = true; $this->getOutput()->disallowUserJs(); // just in case... $this->wg->Out->setPageTitle(wfMessage('wikiaconfirmemail-heading')->plain()); $par = $this->request->getVal('par', ''); $this->code = $this->request->getVal('code', $par); $this->username = $this->request->getVal('username', ''); $this->password = $this->request->getVal('password', ''); $this->editToken = $this->wg->User->getEditToken(); $this->loginToken = UserLoginHelper::getLoginToken(); $editTokenReq = $this->request->getVal('editToken', ''); $loginTokenReq = $this->request->getVal('loginToken', ''); if ($this->code == '') { $this->result = 'error'; $this->msg = wfMessage('wikiaconfirmemail-error-empty-code')->escaped(); return; } if ($this->wg->request->wasPosted() && $this->wg->User->matchEditToken($editTokenReq)) { if ($this->wg->User->isAnon() && $loginTokenReq !== UserLoginHelper::getLoginToken()) { $this->result = 'error'; $this->msg = wfMessage('sessionfailure')->escaped(); return; } if ($this->username == '') { $this->result = 'error'; $this->msg = wfMessage('userlogin-error-noname')->escaped(); $this->errParam = 'username'; return; } if ($this->password == '') { $this->result = 'error'; $this->msg = wfMessage('userlogin-error-wrongpasswordempty')->escaped(); $this->errParam = 'password'; return; } $expUser = User::newFromConfirmationCode($this->code); if (!$expUser instanceof User) { $this->result = 'error'; $this->msg = wfMessage('wikiaconfirmemail-error-invalid-code')->escaped(); return; } // User - activate user, confirm email and redirect to user page or create new wiki $user = User::newFromName($this->username); if (!$user instanceof User) { $this->result = 'error'; $this->msg = wfMessage('userlogin-error-noname')->escaped(); return; } if ($user->getId() != $expUser->getId()) { $this->result = 'error'; $this->msg = wfMessage('wikiaconfirmemail-error-user-not-match')->parse(); $this->errParam = 'username'; return; } $userLoginHelper = new UserLoginHelper(); /* @var UserLoginHelper $userLoginHelper */ if ($userLoginHelper->isPasswordThrottled($this->username)) { $this->result = 'error'; $this->msg = wfMessage('userlogin-error-login-throttled')->escaped(); $this->errParam = 'password'; return; } if ($user->checkPassword($this->password)) { $this->wg->User = $user; if ($user->getGlobalFlag(UserLoginSpecialController::NOT_CONFIRMED_SIGNUP_OPTION_NAME) != null) { // Signup confirm // Log user in manually $this->wg->User->setCookies(); LoginForm::clearLoginToken(); UserLoginHelper::clearNotConfirmedUserSession(); $userLoginHelper->clearPasswordThrottle($this->username); // Confirm UserLoginHelper::removeNotConfirmedFlag($user); $user->confirmEmail(); // Get and clear redirect page $userSignupRedirect = $user->getGlobalAttribute(UserLoginSpecialController::SIGNUP_REDIRECT_OPTION_NAME); $user->setGlobalAttribute(UserLoginSpecialController::SIGNUP_REDIRECT_OPTION_NAME, null); $user->saveSettings(); $userLoginHelper->addNewUserLogEntry($user); // send welcome email $emailParams = array('$USERNAME' => $user->getName(), '$EDITPROFILEURL' => $user->getUserPage()->getFullURL(), '$LEARNBASICURL' => 'http://community.wikia.com/wiki/Help:Wikia_Basics', '$EXPLOREWIKISURL' => 'http://www.wikia.com'); $userLoginHelper->sendEmail($user, 'WelcomeMail', 'usersignup-welcome-email-subject', 'usersignup-welcome-email-body', $emailParams, 'welcome-email', 'WelcomeMail'); // redirect user if (!empty($userSignupRedirect)) { // Redirect user to the point where he finished (when signup on create wiki) $titleObj = SpecialPage::getTitleFor('CreateNewWiki'); $query = $userSignupRedirect; } else { $titleObj = $this->wg->User->getUserPage(); $query = ''; } $this->wg->out->redirect($titleObj->getFullURL($query)); return; } else { // Email change // Log user in through standard method $response = $this->app->sendRequest('UserLoginSpecial', 'login'); $result = $response->getVal('result', ''); $optionNewEmail = $this->wg->User->getGlobalAttribute('new_email'); if (!empty($optionNewEmail)) { $user->setEmail($optionNewEmail); } $user->confirmEmail(); $user->setGlobalAttribute('new_email', null); $user->saveSettings(); // redirect user if ($result === 'closurerequested') { $response = $this->app->sendRequest('UserLoginSpecial', 'getCloseAccountRedirectUrl'); $redirectUrl = $response->getVal('redirectUrl'); $this->wg->Out->redirect($redirectUrl); } else { $userPage = $user->getUserPage(); $this->wg->out->redirect($userPage->getFullURL()); } wfRunHooks('EmailChangeConfirmed', array($user)); return; } } else { $this->result = 'error'; $this->msg = wfMessage('userlogin-error-wrongpassword')->escaped(); $this->errParam = 'password'; return; } } }
echo wfWikiID() . ": Creating User:{$username}..."; # Validate username and check it doesn't exist $user = User::newFromName($username); if (!is_object($user)) { echo "invalid username.\n"; die(1); } elseif (0 != $user->idForName()) { echo "account exists.\n"; die(1); } # Insert the account into the database $user->addToDatabase(); $user->setEmail($email); $user->setPassword($password); $user->confirmEmail(); UserLoginHelper::removeNotConfirmedFlag($user); // this calls saveSettings(); if (!ExternalUser_Wikia::addUser($user, $password, $email, $username)) { echo "error creating external user\n"; die(1); } # Increment site_stats.ss_users $ssu = new SiteStatsUpdate(0, 0, 0, 0, 1); $ssu->doUpdate(); echo "done.\n"; function showHelp() { echo <<<EOT Create a new user account USAGE: php createUser.php [--help] <username> <password> <email>