78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 13/gen/2016
|
|
*/
|
|
|
|
abstract class LoginManager {
|
|
|
|
/**
|
|
* Restituisce true se la login è avvenuta con successo
|
|
* @param string $login
|
|
* @param string $pass in chiaro
|
|
* @return boolean
|
|
*/
|
|
public static function login($login,$pass){
|
|
$rval = false;
|
|
$dao = GlobalVariables::get("dao");
|
|
|
|
$user = $dao->getFirst(static::getRelatedModel(),array("username"=>$login, "password"=>sha1($pass), "active"=>true));
|
|
|
|
if (!is_null($user) && is_object($user)){
|
|
ASDSessionHandler::setSessionValue(static::getSessionVariableName(), $user);
|
|
|
|
$user->lastConnection = new stdClass();
|
|
// $user->lastConnection->date = new MongoDate();
|
|
$user->lastConnection->date = new MongoDB\BSON\UTCDateTime(time()*1000);
|
|
$user->lastConnection->ip = $_SERVER['REMOTE_ADDR'];
|
|
$dao->save($user);
|
|
|
|
$details = new stdClass();
|
|
$details->ip = $_SERVER['REMOTE_ADDR'];
|
|
$details->related = new stdClass();
|
|
$details->related->id = $user->id;
|
|
$details->related->class = static::getRelatedModel();
|
|
|
|
$accessModel = new AccessModel($details);
|
|
$dao->save($accessModel);
|
|
|
|
$rval = true;
|
|
}
|
|
return $rval;
|
|
}
|
|
|
|
/**
|
|
* Slogga l'utente
|
|
*/
|
|
public static function logout(){
|
|
ASDSessionHandler::unsetSessionValue(static::getSessionVariableName());
|
|
}
|
|
|
|
/**
|
|
* Restituisce true se l'utente è loggato
|
|
* @return bool
|
|
*/
|
|
public static function isLogged(){
|
|
return ASDSessionHandler::sessionValueExists(static::getSessionVariableName());
|
|
}
|
|
|
|
/**
|
|
* Restituisce l'utente loggato
|
|
* @return Model
|
|
*/
|
|
public static function getLogged(){
|
|
return ASDSessionHandler::getSessionValue(static::getSessionVariableName());
|
|
}
|
|
|
|
/**
|
|
* Restituisce il nome della classe model da utilizzare
|
|
* @return string
|
|
*/
|
|
protected static abstract function getRelatedModel();
|
|
/**
|
|
* Restituisce il nome della variabile di sessione da utilizzare
|
|
*/
|
|
protected static abstract function getSessionVariableName();
|
|
}
|
|
|
|
?>
|