summaryrefslogtreecommitdiff
path: root/models/last_login.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-05-22 12:28:28 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-05-22 12:28:28 -0400
commit2230dd4e6b148346c0ec596b9e3e12996a762ed8 (patch)
treeef99ccde4f8b18592a3fb06a6ec45162c501fe38 /models/last_login.php
parenta750b8ab2a0cb715da6fd9025a7ec8375db68a4d (diff)
Code refactoring (add autoloader and change files organization)
Diffstat (limited to 'models/last_login.php')
-rw-r--r--models/last_login.php93
1 files changed, 0 insertions, 93 deletions
diff --git a/models/last_login.php b/models/last_login.php
deleted file mode 100644
index a991ee30..00000000
--- a/models/last_login.php
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-
-namespace Model;
-
-require_once __DIR__.'/base.php';
-
-/**
- * LastLogin model
- *
- * @package model
- * @author Frederic Guillot
- */
-class LastLogin extends Base
-{
- /**
- * SQL table name
- *
- * @var string
- */
- const TABLE = 'last_logins';
-
- /**
- * Number of connections to keep for history
- *
- * @var integer
- */
- const NB_LOGINS = 10;
-
- /**
- * Authentication methods
- *
- * @var string
- */
- const AUTH_DATABASE = 'database';
- const AUTH_REMEMBER_ME = 'remember_me';
- const AUTH_LDAP = 'ldap';
- const AUTH_GOOGLE = 'google';
-
- /**
- * Create a new record
- *
- * @access public
- * @param string $auth_type Authentication method
- * @param integer $user_id User id
- * @param string $ip IP Address
- * @param string $user_agent User Agent
- * @return array
- */
- public function create($auth_type, $user_id, $ip, $user_agent)
- {
- // Cleanup old sessions if necessary
- $connections = $this->db
- ->table(self::TABLE)
- ->eq('user_id', $user_id)
- ->desc('date_creation')
- ->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();
- }
-
- 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(),
- ));
- }
-
- /**
- * Get the last connections for a given user
- *
- * @access public
- * @param integer $user_id User id
- * @return array
- */
- public function getAll($user_id)
- {
- return $this->db
- ->table(self::TABLE)
- ->eq('user_id', $user_id)
- ->desc('date_creation')
- ->columns('id', 'auth_type', 'ip', 'user_agent', 'date_creation')
- ->findAll();
- }
-}