User last login logged

This commit is contained in:
Pierre 2017-06-03 14:53:47 +02:00
parent 97d7825426
commit 61942e34c4
2 changed files with 35 additions and 3 deletions

View File

@ -109,6 +109,9 @@ class userController
public function getCurrentUserID(){ public function getCurrentUserID(){
user_login_required(); user_login_required();
//Update last user activity
CS::get()->components->user->updateLastActivity(userID);
//Return userID //Return userID
return array("userID" => userID); return array("userID" => userID);
} }

View File

@ -6,6 +6,12 @@
*/ */
class User{ class User{
/**
* @var String $userTable The name of the user table
*/
private $userTable = "utilisateurs";
/** /**
* Try to login user with returning a service token * Try to login user with returning a service token
* *
@ -21,7 +27,7 @@ class User{
$email, $email,
$this->cryptPassword($password) $this->cryptPassword($password)
); );
$userInfos = CS::get()->db->select("utilisateurs", $conditions, $values); $userInfos = CS::get()->db->select($this->userTable, $conditions, $values);
//Check if there is anything //Check if there is anything
if(count($userInfos) == 0) if(count($userInfos) == 0)
@ -148,7 +154,7 @@ class User{
*/ */
public function getUserInfos($userID) : array { public function getUserInfos($userID) : array {
//Prepare database request //Prepare database request
$tablesName = "utilisateurs"; $tablesName = $this->userTable;
$conditions = "WHERE utilisateurs.ID = ?"; $conditions = "WHERE utilisateurs.ID = ?";
$conditionsValues = array( $conditionsValues = array(
$userID*1, $userID*1,
@ -173,7 +179,7 @@ class User{
*/ */
public function getMultipleUserInfos(array $usersID) : array { public function getMultipleUserInfos(array $usersID) : array {
//Prepare database request //Prepare database request
$tablesName = "utilisateurs"; $tablesName = $this->userTable;
$conditions = "WHERE (utilisateurs.ID < 0)"; $conditions = "WHERE (utilisateurs.ID < 0)";
$conditionsValues = array(); $conditionsValues = array();
@ -232,6 +238,29 @@ class User{
return $return; return $return;
} }
/**
* Update last user activity time on the network
*
* @param Integer $userID The ID of the user to update
* @return Boolean True for a success
*/
public function updateLastActivity($userID){
//Perform a request on the database
$tableName = $this->userTable;
$conditions = "ID = ?";
$whereValues = array(userID);
$modifs = array(
"last_activity" => time()
);
if(!CS::get()->db->updateDB($tableName, $conditions, $modifs, $whereValues))
return false;
//Success
return true;
}
/** /**
* Crypt user password * Crypt user password
* *