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(); } ?>