|
<?php |
|
|
|
namespace Kanboard\Model; |
|
|
|
use Kanboard\Core\Base; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LastLoginModel extends Base |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
const TABLE = 'last_logins'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
const NB_LOGINS = 10; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function create($auth_type, $user_id, $ip, $user_agent) |
|
{ |
|
$this->cleanup($user_id); |
|
|
|
return $this->db |
|
->table(self::TABLE) |
|
->insert(array( |
|
'auth_type' => $auth_type, |
|
'user_id' => $user_id, |
|
'ip' => $ip, |
|
'user_agent' => substr($user_agent, 0, 255), |
|
'date_creation' => time(), |
|
)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function cleanup($user_id) |
|
{ |
|
$connections = $this->db |
|
->table(self::TABLE) |
|
->eq('user_id', $user_id) |
|
->desc('id') |
|
->findAllByColumn('id'); |
|
|
|
if (count($connections) >= self::NB_LOGINS) { |
|
$this->db->table(self::TABLE) |
|
->eq('user_id', $user_id) |
|
->notIn('id', array_slice($connections, 0, self::NB_LOGINS - 1)) |
|
->remove(); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getAll($user_id) |
|
{ |
|
return $this->db |
|
->table(self::TABLE) |
|
->eq('user_id', $user_id) |
|
->desc('id') |
|
->columns('id', 'auth_type', 'ip', 'user_agent', 'date_creation') |
|
->findAll(); |
|
} |
|
} |
|
|