/** * Checks the user credentials * * @param array $credentials */ public function check($credentials) { $user = Users::findFirst(array(array("login" => $credentials['login']))); if ($user == null) { $this->registerUserThrottling(null); throw new Exception('Wrong email/password combination'); } // Check the password if (!$this->security->checkHash($credentials['password'], $user->password)) { $user = $this->registerUserThrottling($user); $user->save(); throw new Exception('Wrong email/password combination'); } // Clean user tokens $user->tokens = $this->cleanUserTokens($user->tokens); $user->save(); // Check if the user was flagged $this->checkUserFlags($user); // Register the successful login $this->saveSuccessLogin($user); // Check if the remember me was selected if (isset($credentials['remember'])) { $this->createRememberEnviroment($user); } $this->session->set('auth-identity', array('id' => $user->_id, 'name' => $user->login)); }
/** * Search user in database by conditions and returns result if any user found * @param array $conditions MongoDB conditions query to search in users collection * @return bool True if any user found by conditions query */ private function isUserFoundByConditions($conditions) { if (!is_array($conditions)) { throw new \Exception("First parameter should be conditions array"); } $user = Users::findFirst(array($conditions)); return $user != false; }