/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function reset() { $external = true; $user = ExternalUser::model()->findByAttributes(array('name_usr' => $this->username)); if ($user === NULL) { // check internal $user = InternalUser::model()->findByAttributes(array('email_uin' => $this->username)); if ($user === NULL) { // no user found } $external = false; } if ($external) { $user->email_code_usr = md5(date('Y-m-d H:i:s') . self::SALT); $user->save(); ExternalUserHistory::addLog('Requested password reset!', $user->id_usr); $md5 = $user->id_usr . 'e;' . $user->email_code_usr; $name = $user->name_usr; $email = $user->email_usr; } else { $md5 = $user->id_uin . 'i;' . md5($user->fname_uin . $user->password_uin); $name = $user->fname_uin; $email = $user->email_uin; } ResetpasswordForm::send_first_email($md5, $name, $email, $external); }
/** * Find the user by their Facebook ID. * If there is no user found for the given id, returns null. */ public static function getUser($fbid) { $prefix = self::getPrefix(); // NOTE: Do not just pass this dbr into getUserByDB since that function prevents // rewriting of the database name for shared tables. $dbr = wfGetDB(DB_SLAVE, array(), self::sharedDB()); $id = $dbr->selectField(array("{$prefix}user_fbconnect"), array('user_id'), array('user_fbid' => $fbid), __METHOD__); if ($id) { /* Wikia change - begin */ global $wgExternalAuthType; $user = User::newFromId($id); if ($wgExternalAuthType) { $user->load(); if ($user->getId() == 0) { $mExtUser = ExternalUser::newFromId($id); if (is_object($mExtUser) && $mExtUser->getId() != 0) { $mExtUser->linkToLocal($mExtUser->getId()); $user->setId($id); } } } return $user; /* Wikia change - end */ } else { return null; } }
/** * Actually add a user to the database. * Give it a User object that has been initialised with a name. * * @param $tempUser User object. * @param $autocreate boolean -- true if this is an autocreation via auth plugin * @return User object. * @private */ function initUser( $tempUser, $autocreate = false ) { global $wgAuth; $tempUser->addToDatabase(); if ( $wgAuth->allowPasswordChange() ) { $tempUser->setPassword( $this->mPassword ); } $tempUser->setEmail( $this->mEmail ); $tempUser->setRealName( $this->mRealName ); $tempUser->setToken(); $wgAuth->initUser( $tempUser, $autocreate ); if ( $this->mExtUser ) { $this->mExtUser->linkToLocal( $tempUser->getId() ); $email = $this->mExtUser->getPref( 'emailaddress' ); if ( $email && !$this->mEmail ) { $tempUser->setEmail( $email ); } } $tempUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 ); $tempUser->saveSettings(); # Update user count $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); $ssUpdate->doUpdate(); $this->addToSourceTracking( $tempUser ); return $tempUser; }
/** * Attempt to automatically create a user on login. Only succeeds if there * is an external authentication method which allows it. * * @param $user User * * @return integer Status code */ function attemptAutoCreate($user) { global $wgAuth, $wgAutocreatePolicy; if ($this->getUser()->isBlockedFromCreateAccount()) { wfDebug(__METHOD__ . ": user is blocked from account creation\n"); return self::CREATE_BLOCKED; } /** * If the external authentication plugin allows it, automatically cre- * ate a new account for users that are externally defined but have not * yet logged in. */ if ($this->mExtUser) { # mExtUser is neither null nor false, so use the new ExternalAuth # system. if ($wgAutocreatePolicy == 'never') { return self::NOT_EXISTS; } if (!$this->mExtUser->authenticate($this->mPassword)) { return self::WRONG_PLUGIN_PASS; } } else { # Old AuthPlugin. if (!$wgAuth->autoCreate()) { return self::NOT_EXISTS; } if (!$wgAuth->userExists($user->getName())) { wfDebug(__METHOD__ . ": user does not exist\n"); return self::NOT_EXISTS; } if (!$wgAuth->authenticate($user->getName(), $this->mPassword)) { wfDebug(__METHOD__ . ": \$wgAuth->authenticate() returned false, aborting\n"); return self::WRONG_PLUGIN_PASS; } } $abortError = ''; if (!wfRunHooks('AbortAutoAccount', array($user, &$abortError))) { // Hook point to add extra creation throttles and blocks wfDebug("LoginForm::attemptAutoCreate: a hook blocked creation: {$abortError}\n"); $this->mAbortLoginErrorMsg = $abortError; return self::ABORTED; } wfDebug(__METHOD__ . ": creating account\n"); $status = $this->initUser($user, true); if (!$status->isOK()) { $errors = $status->getErrorsByType('error'); $this->mAbortLoginErrorMsg = $errors[0]['message']; return self::ABORTED; } return self::SUCCESS; }
public function postCreationSetup($params) { global $wgErrorLog, $wgServer, $wgInternalServer, $wgStatsDBEnabled; $wgServer = rtrim($params['url'], '/'); $wgInternalServer = $wgServer; $wgStatsDBEnabled = false; // disable any DW queries/hooks during wiki creation $wgErrorLog = false; if ($params['founderId']) { $this->info('loading founding user', ['founder_id' => $params['founderId']]); $this->founder = \User::newFromId($params['founderId']); $this->founder->load(); } if (!$this->founder || $this->founder->isAnon()) { $this->warning('cannot load founding user', ['founder_id' => $params['founderId']]); if (!empty($params['founderName'])) { $this->founder = \User::newFromName($params['founderName']); $this->founder->load(); } } if (!$this->founder || $this->founder->isAnon()) { global $wgExternalAuthType; if ($wgExternalAuthType) { $extUser = \ExternalUser::newFromName($params['founderName']); if (is_object($extUser)) { $extUser->linkToLocal($extUser->getId()); } } } $this->wikiName = isset($params['sitename']) ? $params['sitename'] : \WikiFactory::getVarValueByName('wgSitename', $params['city_id'], true); $this->wikiLang = isset($params['language']) ? $params['language'] : \WikiFactory::getVarValueByName('wgLanguageCode', $params['city_id']); $this->moveMainPage(); $this->changeStarterContributions($params); $this->setWelcomeTalkPage(); $this->populateCheckUserTables(); $this->protectKeyPages(); $this->sendRevisionToScribe(); $hookParams = ['title' => $params['sitename'], 'url' => $params['url'], 'city_id' => $params['city_id']]; if (empty($params['disableCompleteHook'])) { wfRunHooks('CreateWikiLocalJob-complete', array($hookParams)); } return true; }
public function actionReactivate($id) { if (ExternalUser::model()->findByPk($id)->sendActivationLink()) { Yii::app()->user->setFlash('_success', "Activation link has been sent to selected user!"); $this->redirect($_SERVER['HTTP_REFERER']); } else { Yii::app()->user->setFlash('_error', "User not found!"); $this->redirect($_SERVER['HTTP_REFERER']); } }
/** * @param $user User * @param $s ResultWrapper */ public static function onUserLoadFromDatabase($user, &$s) { /* wikia change */ global $wgExternalAuthType; if ($wgExternalAuthType) { $mExtUser = ExternalUser::newFromId($user->mId); if (is_object($mExtUser) && 0 != $mExtUser->getId()) { $mExtUser->linkToLocal($mExtUser->getId()); $s = $mExtUser->getLocalUser(false); } } return true; }
/** * Retrieves the results and creates a JSON string * * @param testId the id of the test to send * @param */ public function createJsonString($testId) { //if($comments==null or $comments==''){$comments = 'No Comments'; //We use curl to send the requests $httpCurl = curl_init(Config::get('kblis.sanitas-url')); curl_setopt($httpCurl, CURLOPT_RETURNTRANSFER, true); curl_setopt($httpCurl, CURLOPT_POST, true); //If testID is null we cannot handle this test as we cannot know the results if ($testId == null) { return null; } //Get the test and results $test = Test::find($testId); $testResults = $test->testResults; //Measures $testTypeId = $test->testType()->get()->lists('id')[0]; $testType = TestType::find($testTypeId); $testMeasures = $testType->measures; //Get external requests and all its children $externalDump = new ExternalDump(); $externRequest = ExternalDump::where('test_id', '=', $testId)->get(); if (!$externRequest->first()) { //Not a request we can send back return null; } $labNo = $externRequest->lists('lab_no')[0]; $externlabRequestTree = $externalDump->getLabRequestAndMeasures($labNo); $interpretation = ""; //IF the test has no children prepend the status to the result if ($externlabRequestTree->isEmpty()) { if ($test->test_status_id == Test::COMPLETED) { $interpretation = "Done: " . $test->interpretation; } elseif ($test->test_status_id == Test::VERIFIED) { $interpretation = "Tested and verified: " . $test->interpretation; } } else { if ($test->test_status_id == Test::COMPLETED) { $interpretation = "Done " . $test->interpretation; } elseif ($test->test_status_id == Test::VERIFIED) { $interpretation = "Tested and verified " . $test->interpretation; } } //TestedBy $tested_by = ExternalUser::where('internal_user_id', '=', $test->tested_by)->get()->first(); if ($tested_by == null) { $tested_by = "59"; } else { if ($tested_by->external_user_id == null) { $tested_by = "59"; } else { $tested_by = $tested_by->external_user_id; } } if ($test->verified_by == 0 || $test->verified_by == null) { $verified_by = "59"; } else { $verified_by = ExternalUser::where('internal_user_id', '=', $test->verified_by)->get()->first(); if ($verified_by == null) { $verified_by = "59"; } else { if ($verified_by->external_user_id == null) { $verified_by = "59"; } else { $verified_by = $verified_by->external_user_id; } } } //TODO - relate measure to test-result $range = Measure::getRange($test->visit->patient, $testResults->first()->measure_id); $unit = Measure::find($testResults->first()->measure_id)->unit; $result = $testResults->first()->result . " " . $range . " " . $unit; $jsonResponseString = sprintf('{"labNo": "%s","requestingClinician": "%s", "result": "%s", "verifiedby": "%s", "techniciancomment": "%s"}', $labNo, $tested_by, $result, $verified_by, trim($interpretation)); $this->sendRequest($httpCurl, urlencode($jsonResponseString), $labNo); //loop through labRequests and foreach of them get the result and put in an array foreach ($externlabRequestTree as $key => $externlabRequest) { $mKey = array_search($externlabRequest->investigation, $testMeasures->lists('name')); if ($mKey === false) { Log::error("MEASURE NOT FOUND: Measure {$externlabRequest->investigation} not found in our system"); } else { $measureId = $testMeasures->get($mKey)->id; $rKey = array_search($measureId, $testResults->lists('measure_id')); $matchingResult = $testResults->get($rKey); $range = Measure::getRange($test->visit->patient, $measureId); $unit = Measure::find($measureId)->unit; $result = $matchingResult->result . " " . $range . " " . $unit; $jsonResponseString = sprintf('{"labNo": "%s","requestingClinician": "%s", "result": "%s", "verifiedby": "%s", "techniciancomment": "%s"}', $externlabRequest->lab_no, $tested_by, $result, $verified_by, ""); $this->sendRequest($httpCurl, urlencode($jsonResponseString), $externlabRequest->lab_no); } } curl_close($httpCurl); }
/** * Returns a Wikia User object for the current (or passed) Facebook ID * * @param int|null $fbId [optional] A Facebook ID * * @return null|User * @throws MWException */ public function getWikiaUser($fbId = null) { if (empty($fbId)) { $fbId = $this->getUserId(); if (empty($fbId)) { return null; } } $map = FacebookMapModel::lookupFromFacebookID($fbId); if (empty($map)) { return null; } // Create a new mapping that includes the app ID. Leave the default App ID behind // as there is no way to tell what other apps this user had connected, and removing this // default mapping will force the user to reconnect on those apps. if ($map->isDefaultAppId()) { $this->migrateMapping($map); } // Update the business token for this user if not already set. The business token // gives us a unique ID across all apps that we can use to reference a user. if (!$map->getBizToken()) { $this->updateBizTokenMapping($map); } $wikiUserId = $map->getWikiaUserId(); if (!$wikiUserId) { return null; } $user = User::newFromId($wikiUserId); // This handles the case when a user record doesn’t exist on wikicities_c3 yet and it has to be created if (F::app()->wg->ExternalAuthType) { $user->load(); if ($user->getId() == 0) { $mExtUser = ExternalUser::newFromId($wikiUserId); if (is_object($mExtUser) && $mExtUser->getId() != 0) { $mExtUser->linkToLocal($mExtUser->getId()); $user->setId($wikiUserId); } } } return $user; }
public function initUser($u, $autocreate, $createTempUser = true) { global $wgAuth, $wgExternalAuthType; // for FBconnect we don't want to create temp users if ($createTempUser === false) { return parent::initUser($u, $autocreate); } // add TempUser, update User object, set TempUser session $tempUser = TempUser::createNewFromUser($u, $this->mReturnTo); if ($wgExternalAuthType) { $u = ExternalUser::addUser($u, "", "", ""); if (is_object($u)) { $this->mExtUser = ExternalUser::newFromName($this->mUsername); } } else { $u->addToDatabase(); } $u->setToken(); $wgAuth->initUser($u, $autocreate); if (is_object($this->mExtUser)) { $this->mExtUser->linkToLocal($u->getId()); } $u->setOption('rememberpassword', $this->mRemember ? 1 : 0); $u->setOption('marketingallowed', $this->mMarketingOptIn ? 1 : 0); if ($this->mLanguage) { $u->setOption('language', $this->mLanguage); } $u->setOption('skinoverwrite', 1); $u->setPassword($this->mPassword); $tempUser->setPassword($u->mPassword); $tempUser->setId($u->getId()); $tempUser->addToDatabase(); wfRunHooks('AddNewAccountTempUser', array($u, false)); $tempUser->saveSettingsTempUserToUser($u); $tempUser->setTempUserSession(); return $u; }
public function _findExternalUser($system = null, $idUser = null, $login = null) { $adapter = Base_Model_Table::getDefaultAdapter(); try { if ($system and $login) { $select = $adapter->select()->from('scan.dictionary', array())->joinLeft('scan.dictionary_entry', 'dictionary.id = dictionary_entry.dictionary_id', array())->joinLeft('scan.external_user', 'dictionary_entry.id = external_user.system_id', array('*'))->where("dictionary.code = 'SYST'")->where("dictionary_entry.code LIKE '" . $system . "'")->where("external_user.login = ?", strtoupper($login))->limit(1); $result = $select->query()->fetchAll(); $result = $result[0]; } else { if ($idUser) { $exUsr = new ExternalUser(); $result = $exUsr->findOne($idUser)->toArray(); } } } catch (Exception $e) { throw new Exception('Blad podczas wyszukiwania uzytkownika!'); } if (empty($result) || !isset($result)) { throw new Exception('Nieznany uzytkownik'); } return $result; }
/** * Tests whether the name is OK to use as a user name. */ public function userNameOK($name) { global $wgReservedUsernames; $name = trim($name); if (empty($name)) { return false; } $u = User::newFromName($name, 'creatable'); if (!is_object($u)) { return false; } if (!empty($wgReservedUsernames) && in_array($name, $wgReservedUsernames)) { return false; } $mExtUser = ExternalUser::newFromName($name); if (is_object($mExtUser) && 0 != $mExtUser->getId()) { return false; } elseif (0 != $u->idForName(true)) { return false; } return true; }
/** * Actually add a user to the database. * Give it a User object that has been initialised with a name. * * @param $oUser User object. * @param $autocreate boolean -- true if this is an autocreation via auth plugin * @return User object. * @private */ function initUser($oUser, $autocreate) { global $wgAuth, $wgExternalAuthType; wfProfileIn(__METHOD__); $oExtUser = null; if ($wgExternalAuthType) { $oUser = ExternalUser::addUser($oUser, $this->mPassword, $this->mEmail, ""); if (is_object($oUser)) { $oExtUser = ExternalUser::newFromName($this->mUsername); } } else { $oUser->addToDatabase(); } if ($wgAuth->allowPasswordChange()) { $oUser->setPassword($this->mPassword); } $oUser->setEmail($this->mEmail); $oUser->setToken(); $wgAuth->initUser($oUser, $autocreate); if (is_object($oExtUser)) { $oExtUser->linkToLocal($oUser->getId()); $email = $oExtUser->getPref('emailaddress'); if ($email && !$this->mEmail) { $oUser->setEmail($email); } } $oUser->setOption('rememberpassword', isset($this->mRemember) ? 1 : 0); $oUser->setOption('marketingallowed', isset($this->mMarketing) ? 1 : 0); $oUser->setOption('skinoverwrite', 1); $oUser->saveSettings(); # Update user count $ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1); $ssUpdate->doUpdate(); wfProfileOut(__METHOD__); return $oUser; }
/** * @param int $userID * @return null|User */ private function getUserObject($userID) { if (\F::app()->wg->ExternalAuthType) { $mExtUser = ExternalUser::newFromId($userID); if (is_object($mExtUser) && 0 != $mExtUser->getId()) { $mExtUser->linkToLocal($mExtUser->getId()); $user = $mExtUser->getLocalUser(); } else { $user = null; } } else { $user = User::newFromId($userID); } return $user; }
/** * Internally authenticate the login request. * * This may create a local account as a side effect if the * authentication plugin allows transparent local account * creation. */ public function authenticateUserData() { global $wgUser, $wgAuth; if ($this->mName == '') { return self::NO_NAME; } // We require a login token to prevent login CSRF // Handle part of this before incrementing the throttle so // token-less login attempts don't count towards the throttle // but wrong-token attempts do. // If the user doesn't have a login token yet, set one. if (!self::getLoginToken()) { self::setLoginToken(); return self::NEED_TOKEN; } // If the user didn't pass a login token, tell them we need one if (!$this->mToken) { return self::NEED_TOKEN; } global $wgPasswordAttemptThrottle; $throttleCount = 0; if (is_array($wgPasswordAttemptThrottle)) { $throttleKey = wfMemcKey('password-throttle', wfGetIP(), md5($this->mName)); $count = $wgPasswordAttemptThrottle['count']; $period = $wgPasswordAttemptThrottle['seconds']; global $wgMemc; $throttleCount = $wgMemc->get($throttleKey); if (!$throttleCount) { $wgMemc->add($throttleKey, 1, $period); // start counter } else { if ($throttleCount < $count) { $wgMemc->incr($throttleKey); } else { if ($throttleCount >= $count) { return self::THROTTLED; } } } } // Validate the login token if ($this->mToken !== self::getLoginToken()) { return self::WRONG_TOKEN; } // Load $wgUser now, and check to see if we're logging in as the same // name. This is necessary because loading $wgUser (say by calling // getName()) calls the UserLoadFromSession hook, which potentially // creates the user in the database. Until we load $wgUser, checking // for user existence using User::newFromName($name)->getId() below // will effectively be using stale data. if ($wgUser->getName() === $this->mName) { wfDebug(__METHOD__ . ": already logged in as {$this->mName}\n"); return self::SUCCESS; } $this->mExtUser = ExternalUser::newFromName($this->mName); # TODO: Allow some magic here for invalid external names, e.g., let the # user choose a different wiki name. $u = User::newFromName($this->mName); if (!$u instanceof User || !User::isUsableName($u->getName())) { return self::ILLEGAL; } $isAutoCreated = false; if (0 == $u->getID()) { $status = $this->attemptAutoCreate($u); if ($status !== self::SUCCESS) { return $status; } else { $isAutoCreated = true; } } else { global $wgExternalAuthType, $wgAutocreatePolicy; if ($wgExternalAuthType && $wgAutocreatePolicy != 'never' && is_object($this->mExtUser) && $this->mExtUser->authenticate($this->mPassword)) { # The external user and local user have the same name and # password, so we assume they're the same. $this->mExtUser->linkToLocal($u->getID()); } $u->load(); } // Give general extensions, such as a captcha, a chance to abort logins $abort = self::ABORTED; if (!wfRunHooks('AbortLogin', array($u, $this->mPassword, &$abort))) { return $abort; } global $wgBlockDisablesLogin; if (!$u->checkPassword($this->mPassword)) { if ($u->checkTemporaryPassword($this->mPassword)) { // The e-mailed temporary password should not be used for actu- // al logins; that's a very sloppy habit, and insecure if an // attacker has a few seconds to click "search" on someone's o- // pen mail reader. // // Allow it to be used only to reset the password a single time // to a new value, which won't be in the user's e-mail ar- // chives. // // For backwards compatibility, we'll still recognize it at the // login form to minimize surprises for people who have been // logging in with a temporary password for some time. // // As a side-effect, we can authenticate the user's e-mail ad- // dress if it's not already done, since the temporary password // was sent via e-mail. if (!$u->isEmailConfirmed()) { $u->confirmEmail(); $u->saveSettings(); } // At this point we just return an appropriate code/ indicating // that the UI should show a password reset form; bot inter- // faces etc will probably just fail cleanly here. $retval = self::RESET_PASS; } else { $retval = $this->mPassword == '' ? self::EMPTY_PASS : self::WRONG_PASS; } } elseif ($wgBlockDisablesLogin && $u->isBlocked()) { // If we've enabled it, make it so that a blocked user cannot login $retval = self::USER_BLOCKED; } else { $wgAuth->updateUser($u); $wgUser = $u; // Please reset throttle for successful logins, thanks! if ($throttleCount) { $wgMemc->delete($throttleKey); } if ($isAutoCreated) { // Must be run after $wgUser is set, for correct new user log wfRunHooks('AuthPluginAutoCreate', array($wgUser)); } $retval = self::SUCCESS; } wfRunHooks('LoginAuthenticateAudit', array($u, $this->mPassword, $retval)); return $retval; }
/** * main entry point * * @access public */ public function run() { global $wgUser, $wgErrorLog, $wgExtensionMessagesFiles, $wgDebugLogFile, $wgServer, $wgInternalServer; wfProfileIn(__METHOD__); /** * overwrite $wgServer. It is sometimes set as localhost which sends broken url * to purgers * * @see SquidUpdate::expand */ $wgServer = rtrim($this->mParams->url, "/"); $wgInternalServer = $wgServer; $wgExtensionMessagesFiles["AutoCreateWiki"] = dirname(__FILE__) . "/AutoCreateWiki.i18n.php"; /** * very verbose */ $debugLogFile = $wgDebugLogFile; $wgDebugLogFile = "php://stdout"; $wgErrorLog = false; /** * setup founder user */ if ($this->mParams->founderId) { Wikia::log(__METHOD__, "user", "Loading user with user_id = {$this->mParams->founderId}"); $this->mFounder = User::newFromId($this->mParams->founderId); $this->mFounder->load(); } else { Wikia::log(__METHOD__, "user", "Founder user_id is unknown {$this->mParams->founderId}"); } # check user name if (!$this->mFounder || $this->mFounder->isAnon()) { Wikia::log(__METHOD__, "user", "Cannot load user with user_id = {$this->mParams->founderId}"); if (!empty($this->mParams->founderName)) { $this->mFounder = User::newFromName($this->mParams->founderName); $this->mFounder->load(); } } # use ExternalUser to check if (!$this->mFounder || $this->mFounder->isAnon()) { global $wgExternalAuthType; if ($wgExternalAuthType) { $oExtUser = ExternalUser::newFromName($this->mParams->founderName); if (is_object($oExtUser)) { $oExtUser->linkToLocal($oExtUser->getId()); } } } $wgUser = User::newFromName("CreateWiki script"); /** * main page should be move in first stage of create wiki, but sometimes * is too early for that. This is fallback function */ $this->wikiaName = isset($this->mParams->sitename) ? $this->mParams->sitename : WikiFactory::getVarValueByName("wgSitename", $this->mParams->city_id, true); $this->wikiaLang = isset($this->mParams->language) ? $this->mParams->language : WikiFactory::getVarValueByName("wgLanguageCode", $this->mParams->city_id); $this->moveMainPage(); $this->changeStarterContributions(); $this->changeImagesTimestamps(); $this->setWelcomeTalkPage(); $this->sendWelcomeMail(); $this->populateCheckUserTables(); $this->protectKeyPages(); $this->queueReminderMail(); $this->sendRevisionToScribe(); $this->addStarterImagesToUploadLog(); /** * different things for different types */ switch ($this->mParams->type) { case "answers": $this->copyDefaultAvatars(); break; } $params = array('title' => $this->mParams->sitename, 'url' => $this->mParams->url, 'city_id' => $this->mParams->city_id); wfRunHooks('CreateWikiLocalJob-complete', array($params)); wfProfileOut(__METHOD__); $wgDebugLogFile = $debugLogFile; return true; }
public function actionResendactivation() { if (isset($_POST['resend_activation'])) { $model = ExternalUser::model()->findAllByAttributes(array('email_usr' => $_POST['email'])); if ($model) { $model = $model[0]; if ($model->status_usr != 0) { $model = false; Yii::app()->user->setFlash('_error', "Your email address has been already validated!"); } } else { Yii::app()->user->setFlash('_error', "Invalid email address!"); } if ($model) { $model->sendActivationLink(); ExternalUserHistory::addLog('Account created!', $model->id_usr); Yii::app()->user->setFlash('_success', "Your activation link has been sent! Check your email address to continue!"); $this->redirect(array('site/login')); header("Location: " . Yii::app()->getBaseUrl()); die; } } $this->render('resendactivation'); }
/** * main entry point * * @access public */ public function run() { global $wgUser, $wgErrorLog, $wgDebugLogFile, $wgServer, $wgInternalServer; // Set this flag to ensure that all select operations go against master // Slave lag can cause random errors during wiki creation process global $wgForceMasterDatabase; $wgForceMasterDatabase = true; wfProfileIn(__METHOD__); /** * overwrite $wgServer. It is sometimes set as localhost which sends broken url * to purgers * * @see SquidUpdate::expand */ $wgServer = rtrim($this->mParams->url, "/"); $wgInternalServer = $wgServer; /** * very verbose */ $debugLogFile = $wgDebugLogFile; $wgDebugLogFile = "php://stdout"; $wgErrorLog = false; /** * setup founder user */ if ($this->mParams->founderId) { Wikia::log(__METHOD__, "user", "Loading user with user_id = {$this->mParams->founderId}"); $this->mFounder = User::newFromId($this->mParams->founderId); $this->mFounder->load(); } else { Wikia::log(__METHOD__, "user", "Founder user_id is unknown {$this->mParams->founderId}"); } # check user name if (!$this->mFounder || $this->mFounder->isAnon()) { Wikia::log(__METHOD__, "user", "Cannot load user with user_id = {$this->mParams->founderId}"); if (!empty($this->mParams->founderName)) { $this->mFounder = User::newFromName($this->mParams->founderName); $this->mFounder->load(); } } # use ExternalUser to check if (!$this->mFounder || $this->mFounder->isAnon()) { global $wgExternalAuthType; if ($wgExternalAuthType) { $oExtUser = ExternalUser::newFromName($this->mParams->founderName); if (is_object($oExtUser)) { $oExtUser->linkToLocal($oExtUser->getId()); } } } $wgUser = User::newFromName("CreateWiki script"); /** * main page should be move in first stage of create wiki, but sometimes * is too early for that. This is fallback function */ $this->wikiaName = isset($this->mParams->sitename) ? $this->mParams->sitename : WikiFactory::getVarValueByName("wgSitename", $this->mParams->city_id, true); $this->wikiaLang = isset($this->mParams->language) ? $this->mParams->language : WikiFactory::getVarValueByName("wgLanguageCode", $this->mParams->city_id); $this->moveMainPage(); $this->changeStarterContributions(); $this->setWelcomeTalkPage(); if (empty($this->mParams->disableWelcome)) { $this->sendWelcomeMail(); } $this->populateCheckUserTables(); $this->protectKeyPages(); if (empty($this->mParams->disableReminder)) { $this->queueReminderMail(); } $this->sendRevisionToScribe(); $params = array('title' => $this->mParams->sitename, 'url' => $this->mParams->url, 'city_id' => $this->mParams->city_id); if (empty($this->mParams->disableCompleteHook)) { wfRunHooks('CreateWikiLocalJob-complete', array($params)); } wfProfileOut(__METHOD__); $wgDebugLogFile = $debugLogFile; return true; }
/** * Retrieves and shows the gathered info to the user * @param $target Mixed: user whose info we're looking up */ function showInfo($target, $emailUser = "") { global $wgOut, $wgLang, $wgScript, $wgEnableWallExt, $wgExternalSharedDB, $wgExternalAuthType; //Small Stuff Week - adding table from Special:LookupContribs --nAndy global $wgExtensionsPath, $wgJsMimeType, $wgResourceBasePath, $wgEnableLookupContribsExt; /** * look for @ in username */ $count = 0; $aUsers = array(); $userTarget = ""; if (strpos($target, '@') !== false) { /** * find username by email */ $emailUser = htmlspecialchars($emailUser); $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB); $oRes = $dbr->select('`user`', 'user_name', array('user_email' => $target), __METHOD__); $loop = 0; while ($oRow = $dbr->fetchObject($oRes)) { if ($loop === 0) { $userTarget = $oRow->user_name; } if (!empty($emailUser) && $emailUser == $oRow->user_name) { $userTarget = $emailUser; } $aUsers[] = $oRow->user_name; $loop++; } // Check for disabled accounts where we kept the email $dRows = $dbr->select(['`user`', 'user_properties'], ['user_name'], ['user_id = up_user', 'up_property' => 'disabled-user-email', 'up_value' => $target], __METHOD__); foreach ($dRows as $row) { if ($loop === 0) { $userTarget = $oRow->user_name; } if (!empty($emailUser) && $emailUser == $row->user_name) { $userTarget = $emailUser; } $aUsers[] = $row->user_name; $loop++; } $count = $loop; } $targetUserName = !empty($userTarget) ? $userTarget : $target; $extUser = null; $user = null; if ($wgExternalAuthType == 'ExternalUser_Wikia') { $extUser = ExternalUser::newFromName($targetUserName); } else { $user = User::newFromName($targetUserName); } if (is_object($extUser) && $extUser->getId() != 0) { $user = $extUser->mapToUser(); } elseif ($user == null || $user->getId() == 0) { $wgOut->addWikiText('<span class="error">' . wfMessage('lookupuser-nonexistent', $target)->text() . '</span>'); return; } if ($count > 1) { $options = array(); if (!empty($aUsers) && is_array($aUsers)) { foreach ($aUsers as $id => $userName) { $options[] = Xml::option($userName, $userName, $userName == $userTarget); } } $selectForm = Xml::openElement('select', array('id' => 'email_user', 'name' => "email_user")); $selectForm .= "\n" . implode("\n", $options) . "\n"; $selectForm .= Xml::closeElement('select'); $selectForm .= "({$count})"; $wgOut->addHTML(Xml::openElement('fieldset') . "\n" . Xml::openElement('form', array('method' => 'get', 'action' => $wgScript)) . "\n" . Html::hidden('title', $this->getTitle()->getPrefixedText()) . "\n" . Html::hidden('target', $target) . "\n" . Xml::openElement('table', array('border' => '0')) . "\n" . Xml::openElement('tr') . "\n" . Xml::openElement('td', array('align' => 'right')) . wfMessage('lookupuser-foundmoreusers')->escaped() . Xml::closeElement('td') . "\n" . Xml::openElement('td', array('align' => 'left')) . "\n" . $selectForm . Xml::closeElement('td') . "\n" . Xml::openElement('td', array('colspan' => '2', 'align' => 'center')) . Xml::submitButton(wfMessage('go')->escaped()) . Xml::closeElement('td') . "\n" . Xml::closeElement('tr') . "\n" . Xml::closeElement('table') . "\n" . Xml::closeElement('form') . "\n" . Xml::closeElement('fieldset')); } $authTs = $user->getEmailAuthenticationTimestamp(); if ($authTs) { $authenticated = wfMessage('lookupuser-authenticated', $wgLang->timeanddate($authTs, true))->text(); } else { $authenticated = wfMessage('lookupuser-not-authenticated')->text(); } $optionsString = ''; foreach ($user->getOptions() as $name => $value) { $optionsString .= "{$name} = {$value} <br />"; } $name = $user->getName(); $email = $user->getEmail() ?: $user->getGlobalAttribute('disabled-user-email'); if (!empty($email)) { $email_output = wfMessage('lookupuser-email', $email, urlencode($email))->text(); } else { $email_output = wfMessage('lookupuser-no-email')->text(); } if ($user->getRegistration()) { $registration = $wgLang->timeanddate($user->getRegistration(), true); } else { $registration = wfMessage('lookupuser-no-registration')->text(); } $wgOut->addWikiText('*' . wfMessage('username')->text() . ' [[User:'******'|' . $name . ']] (' . $wgLang->pipeList(array('<span id="lu-tools">[[' . (!empty($wgEnableWallExt) ? 'Message Wall:' . $name . '|' . wfMessage('wall-message-wall-shorten')->text() : 'User talk:' . $name . '|' . wfMessage('talkpagelinktext')->text()) . ']]', '[[Special:Contributions/' . $name . '|' . wfMessage('contribslink')->text() . ']]</span>)'))); $wgOut->addWikiText('*' . wfMessage('lookupuser-toollinks', $name, urlencode($name))->inContentLanguage()->text()); $wgOut->addWikiText('*' . wfMessage('lookupuser-id', $user->getId())->text()); $userStatus = wfMessage('lookupuser-account-status-realuser')->text(); $wgOut->addWikiText('*' . wfMessage('lookupuser-account-status')->text() . $userStatus); $wgOut->addWikiText('*' . $email_output); $wgOut->addWikiText('*' . wfMessage('lookupuser-realname', $user->getRealName())->text()); $wgOut->addWikiText('*' . wfMessage('lookupuser-registration', $registration)->text()); $wgOut->addWikiText('*' . wfMessage('lookupuser-touched', $wgLang->timeanddate($user->mTouched, true))->text()); $wgOut->addWikiText('*' . wfMessage('lookupuser-info-authenticated', $authenticated)->text()); if (isset($user->mBirthDate)) { $birthDate = $wgLang->date(date('Y-m-d H:i:s', strtotime($user->mBirthDate))); } else { $birthDate = wfMessage('lookupuser-no-birthdate')->text(); } $wgOut->addWikiText('*' . wfMessage('lookupuser-birthdate', $birthDate)->text()); $newEmail = $user->getGlobalAttribute('new_email'); if (!empty($newEmail)) { $wgOut->addWikiText('*' . wfMessage('lookupuser-email-change-requested', $newEmail)->plain()); } $allowedAdoption = $user->getGlobalFlag('AllowAdoption', true); $wgOut->addWikiText('*' . wfMessage('lookupuser-user' . (!$allowedAdoption ? '-not' : '') . '-allowed-adoption')->plain()); //Begin: Small Stuff Week - adding table from Special:LookupContribs --nAndy if (!empty($wgEnableLookupContribsExt)) { $wgOut->addExtensionStyle("{$wgExtensionsPath}/wikia/LookupContribs/css/table.css"); $wgOut->addExtensionStyle("{$wgExtensionsPath}/wikia/LookupUser/css/lookupuser.css"); $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgResourceBasePath}/resources/wikia/libraries/jquery/datatables/jquery.dataTables.min.js\"></script>\n"); //checking and setting User::mBlockedGlobally if needed //only for this instance of class User wfRunHooks('GetBlockedStatus', array(&$user)); $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/"); $oTmpl->set_vars(array('username' => $name, 'isUsernameGloballyBlocked' => $user->isBlockedGlobally())); $wgOut->addHTML($oTmpl->render('contribution.table')); } else { $wgOut->addWikiText('*' . wfMessage('lookupuser-table-cannot-be-displayed')->text()); } //End: Small Stuff Week $wgOut->addWikiText('*' . wfMessage('lookupuser-useroptions')->text() . '<br />' . $optionsString); }
public function authenticate() { // check external $external = true; $user = ExternalUser::model()->findByAttributes(array('name_usr' => $this->username)); if ($user === NULL) { // check internal $user = InternalUser::model()->findByAttributes(array('email_uin' => $this->username)); if ($user === NULL) { // no user found $this->errorCode = self::ERROR_USERNAME_INVALID; } $external = false; } if ($user) { if ($external) { if ($user->password_usr == ExternalUser::passwordHash($this->password)) { // password ok if ($user->status_usr == ExternalUser::ENABLED_ENABLED) { // account enabled $this->errorCode = self::ERROR_NONE; $this->setState('type', 'External'); $this->setState('userId', $user->id_usr); $this->setState('name', $user->name_usr); $this->setState('email', $user->email_usr); $this->setState('limitation_date', $user->limitation_date_usr); $this->setState('rights_daily', $user->rights_daily_usr); $this->setState('rights_monthly', $user->rights_monthly_usr); $this->setState('rights_clean', $user->rights_clean_usr); $user->last_login_date_usr = date('Y-m-d H:i:s'); $user->ip_usr = $_SERVER['REMOTE_ADDR']; $user->save(false); } else { $this->errorCode = 114 + $user->status_usr; if ($user->status_usr == 0) { $_POST['show_resend_activation'] = true; } } } else { $this->errorCode = self::ERROR_PASSWORD_INVALID; } } else { if ($user->password_uin == InternalUser::passwordHash($this->password)) { // password ok if ($user->enabled_uin == InternalUser::ENABLED_ENABLED) { // account enabled $this->errorCode = self::ERROR_NONE; $this->setState('type', 'Internal'); $this->setState('userId', $user->id_uin); $this->setState('name', $user->fname_uin . ' ' . $user->lname_uin); $this->setState('email', $user->email_uin); $user->last_login_date_uin = date('Y-m-d H:i:s'); $user->save(false); } else { $this->errorCode = self::ERROR_ENABLED_DISABLED; } } else { $this->errorCode = self::ERROR_PASSWORD_INVALID; } } } return !$this->errorCode; }
/** * @todo document */ protected function saveOptions() { global $wgAllowPrefChange; $extuser = ExternalUser::newFromUser($this); $this->loadOptions(); // wikia change global $wgExternalSharedDB, $wgSharedDB, $wgGlobalUserProperties; if (isset($wgSharedDB)) { $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); } else { $dbw = wfGetDB(DB_MASTER); } $insert_rows = array(); $saveOptions = $this->mOptions; // Allow hooks to abort, for instance to save to a global profile. // Reset options to default state before saving. if (!wfRunHooks('UserSaveOptions', array($this, &$saveOptions))) { return; } foreach ($saveOptions as $key => $value) { # Don't bother storing default values # <Wikia> if ($this->shouldOptionBeStored($key, $value)) { $insert_rows[] = array('up_user' => $this->getId(), 'up_property' => $key, 'up_value' => $value); } # </Wikia> if ($extuser && isset($wgAllowPrefChange[$key])) { switch ($wgAllowPrefChange[$key]) { case 'local': case 'message': break; case 'semiglobal': case 'global': $extuser->setPref($key, $value); } } } $dbw->delete('user_properties', array('up_user' => $this->getId()), __METHOD__); $dbw->insert('user_properties', $insert_rows, __METHOD__); if ($extuser) { $extuser->updateUser(); } }
<?php $this->headlineText = 'External Users'; Yii::app()->clientScript->registerScript('search', "\r\n\$('.search-button').click(function(){\r\n\t\$('.search-form').toggle();\r\n\treturn false;\r\n});\r\n\$('.search-form form').submit(function(){\r\n\t\$.fn.yiiGridView.update('external-user-grid', {\r\n\t\tdata: \$(this).serialize()\r\n\t});\r\n\treturn false;\r\n});\r\n"); ?> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'external-user-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'ajaxUpdate' => false, 'cssFile' => Yii::app()->request->baseUrl . '/css/gridview/styles.css', 'rowCssClassExpression' => '($row%2?"even ":"odd "). ($data->userStatus!="Enabled"?($data->userStatus=="Pending"?"Important":"Rescan"):"")', 'template' => '{summary}{pager}{items}', 'columns' => array(array('name' => 'id_usr', 'headerHtmlOptions' => array('style' => 'width:75px;'), 'cssClassExpression' => '"idcol"'), 'name_usr', 'email_usr', 'company_usr', array('name' => 'last_login_date_usr', 'value' => '$data->last_login_date_usr=="0000-00-00 00:00:00"?"n/a":$data->last_login_date_usr', 'htmlOptions' => array('style' => 'width:120px;padding:0;text-align:center;')), array('name' => 'userStatus', 'filter' => CHtml::listData(ExternalUser::userStatusList(), 'name', 'name'), 'htmlOptions' => array('style' => 'width:80px;padding:0;text-align:center;')), array('class' => 'CButtonColumn', 'header' => 'Actions', 'template' => '{enable} {disable} {update} {delete}', 'buttons' => array('enable' => array('label' => 'Enable account', 'url' => 'Yii::app()->createUrl("externaluser/enable", array("id"=>$data->id_usr))', 'imageUrl' => Yii::app()->request->baseUrl . '/images/icons/tick.png', 'visible' => '$data->status_usr != 2'), 'disable' => array('label' => 'Disable account', 'url' => 'Yii::app()->createUrl("externaluser/disable", array("id"=>$data->id_usr))', 'imageUrl' => Yii::app()->request->baseUrl . '/images/icons/minus-circle-frame.png', 'visible' => '$data->status_usr == 2'))))));
/** * @todo document */ protected function saveOptions() { global $wgAllowPrefChange; $extuser = ExternalUser::newFromUser($this); $this->loadOptions(); $dbw = wfGetDB(DB_MASTER); $insert_rows = array(); $saveOptions = $this->mOptions; // Allow hooks to abort, for instance to save to a global profile. // Reset options to default state before saving. if (!wfRunHooks('UserSaveOptions', array($this, &$saveOptions))) { return; } foreach ($saveOptions as $key => $value) { # Don't bother storing default values if (is_null(self::getDefaultOption($key)) && !($value === false || is_null($value)) || $value != self::getDefaultOption($key)) { $insert_rows[] = array('up_user' => $this->getId(), 'up_property' => $key, 'up_value' => $value); } if ($extuser && isset($wgAllowPrefChange[$key])) { switch ($wgAllowPrefChange[$key]) { case 'local': case 'message': break; case 'semiglobal': case 'global': $extuser->setPref($key, $value); } } } $dbw->delete('user_properties', array('up_user' => $this->getId()), __METHOD__); $dbw->insert('user_properties', $insert_rows, __METHOD__); }
<?php ini_set("include_path", dirname(__FILE__) . "/.."); require_once 'commandLine.inc'; $userid = isset($options['u']) ? $options['u'] : 0; if ($userid == 0) { die('invalid user ID'); } $mExtUser = ExternalUser::newFromId($userid); if (is_object($mExtUser) && 0 != $mExtUser->getId()) { $mExtUser->linkToLocal($mExtUser->getId()); }