/** * Logs an attempt to log in in the database so things like the numner of * log in attempts can be recorded. * * @param int $status One of $ATTEMPT_GOOD, $ATTEMPT_NO_SUCH_USER or $ATTEMPT_BAD_CRIDENTIALS from Model_Log_In_Attempt * @param string $email The email that's trying to log in. */ public function log_log_in_attempt($status, $email) { if (!$this->logging_enabled()) { return; } $logEntry = new Model_Log_In_Attempt(); $logEntry->email = is_null($email) ? '' : $email; $logEntry->status = $status; $logEntry->save(); //If the entry failed then add a ban too if ($status != Model_Log_In_Attempt::$ATTEMPT_GOOD) { Banner::instance()->auto_ban($email); } }
/** * Bans an email address and/or an ip for the given time * * @param string|int $time Number of seconds to ban for or something like "+1 Day" * @param null|string|true $ip Null to ignore IP, string to specify the ip, true to automatically load the ip * @param null|string $email */ public function ban($time, $ip = null, $email = null) { Banner::instance()->ban($time, $ip, $email); }
/** * Attemps an oAuth login. Will create a new user if one does not already * exist with the given email. If a user is logged in the 3rd party account * is linked with the logged in user. * * @param string $email The email passed back from the 3rd party * @param string $driver Name of the driver the email is from * @return Ethanol\Model_User */ protected function perform_login($email, $driver) { //This is the first point that we have an email do make a check for //banned users if (Banner::instance()->is_banned($email)) { throw new LogInFailed(\Lang::get('ethanol.errors.exceededLoginTries')); } //Check if a user exists yet. $oauth = Model_User_Oauth::find('first', array('related' => array('user'), 'where' => array(array('driver', $driver), array('email', $email)))); //if not create if (is_null($oauth)) { //Check if we have a guest user or not. if (Ethanol::instance()->is_guest()) { $user = new Model_User(); $user->activated = Model_User::$USER_ACTIVATED; $user->email = $email; } else { //Not a guest user so get the current user. $user = Ethanol::instance()->current_user(); } //And assocate the new oauth with it. $oauth = new Model_User_Oauth(); $oauth->driver = $driver; $oauth->email = $email; $user->oauth[] = $oauth; $user->save(); } else { $user = $oauth->user; } return $user; }