summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-18 21:46:56 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-18 21:46:56 -0500
commite73334a7e0738d6e46bae7dec1e903232550c964 (patch)
treeacb3c29aba803ea774459375394bd299028ca805 /app
parentddb73063a7889c8dad79dd7148c01c9bc845d9f0 (diff)
Add unit test for LastLogin class
Diffstat (limited to 'app')
-rw-r--r--app/Model/LastLogin.php36
1 files changed, 23 insertions, 13 deletions
diff --git a/app/Model/LastLogin.php b/app/Model/LastLogin.php
index 0f148ead..f5be020e 100644
--- a/app/Model/LastLogin.php
+++ b/app/Model/LastLogin.php
@@ -36,11 +36,31 @@ class LastLogin extends Base
*/
public function create($auth_type, $user_id, $ip, $user_agent)
{
- // Cleanup old sessions if necessary
+ $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(),
+ ));
+ }
+
+ /**
+ * Cleanup login history
+ *
+ * @access public
+ * @param integer $user_id
+ */
+ public function cleanup($user_id)
+ {
$connections = $this->db
->table(self::TABLE)
->eq('user_id', $user_id)
- ->desc('date_creation')
+ ->desc('id')
->findAllByColumn('id');
if (count($connections) >= self::NB_LOGINS) {
@@ -49,16 +69,6 @@ class LastLogin extends Base
->notin('id', array_slice($connections, 0, self::NB_LOGINS - 1))
->remove();
}
-
- return $this->db
- ->table(self::TABLE)
- ->insert(array(
- 'auth_type' => $auth_type,
- 'user_id' => $user_id,
- 'ip' => $ip,
- 'user_agent' => $user_agent,
- 'date_creation' => time(),
- ));
}
/**
@@ -73,7 +83,7 @@ class LastLogin extends Base
return $this->db
->table(self::TABLE)
->eq('user_id', $user_id)
- ->desc('date_creation')
+ ->desc('id')
->columns('id', 'auth_type', 'ip', 'user_agent', 'date_creation')
->findAll();
}