/** * 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); } }
public function attempt_number($email) { $ip = \Input::ip(); //Check the number of log in attempts for this user and this ip $lastGood = Model_Log_In_Attempt::query()->select('time')->where('status', Model_Log_In_Attempt::$ATTEMPT_GOOD)->and_where_open()->where('email', $email)->or_where('ip', $ip)->and_where_close()->order_by('time', 'DESC')->limit(1); $attempts = Model_Log_In_Attempt::query()->where('time', '>', $lastGood->get_query(false))->and_where_open()->where('email', $email)->or_where('ip', $ip)->and_where_close()->order_by('time', 'DESC')->get(); if (count($attempts) == 0) { //There was no good last login so get all of them instead $attempts = Model_Log_In_Attempt::find('all', array('where' => array('or' => array(array('ip', $ip), array('email', $email))), 'order_by' => array(array('time', 'DESC')))); } return count($attempts); }