Exemplo n.º 1
0
 /**
  * Get count of user sessions
  *
  * @return int
  */
 public function getCount()
 {
     return Table\UserSessions::findAll()->count();
 }
Exemplo n.º 2
0
 /**
  * Validate attempted session
  *
  * @param  mixed $config
  * @param  mixed $user
  * @param  mixed $data
  * @return boolean
  */
 public static function validate($config, $user, $data)
 {
     $result = true;
     // Check for multiple sessions
     if (!$config->multiple_sessions && isset(Table\UserSessions::findBy(['user_id' => $user->id])->id)) {
         $result = false;
     }
     // Check for too many failed attempts
     if ($config->allowed_attempts > 0) {
         if (isset($data->user_id) && $data->failed_attempts >= $config->allowed_attempts) {
             $result = false;
         }
     }
     // Check IP allowed
     if (!empty($config->ip_allowed)) {
         $ipAllowed = explode(',', $config->ip_allowed);
         if (!in_array($_SERVER['REMOTE_ADDR'], $ipAllowed)) {
             $result = false;
         }
     }
     // Check IP blocked
     if (!empty($config->ip_blocked)) {
         $ipBlocked = explode(',', $config->ip_blocked);
         if (in_array($_SERVER['REMOTE_ADDR'], $ipBlocked)) {
             $result = false;
         }
     }
     return $result;
 }