/** * Set local user * * @param string $user_id user id * @param string $email user email * @param string $name user name * */ public static function setUser($applicationName, $applicationSecret, $email, $name = null) { if (is_null($email)) { // Virtually closes the local session self::$attributes = null; } else { self::$attributes = array('application_name' => $applicationName, 'application_secret' => $applicationSecret, 'email' => array($email), 'name' => $name); } }
/** * This function allows to know if the user is authentified * * @return boolean True if authentified, false otherwhise */ public static function user() { if (is_null(self::$attributes)) { // Not already cached // Used to break infinite loop on Exceptions self::$attributes = array(); if (!self::getFromCache()) { // Authentication logic if (AuthLocalApplication::isAuthenticated()) { // SP self::$attributes = AuthLocalApplication::attributes(); self::$isLocal = true; } else { if (AuthSP::isAuthenticated()) { // SP self::$attributes = AuthSP::attributes(); self::$isSP = true; } } if (!self::$attributes || !array_key_exists('email', self::$attributes)) { return false; } self::$user = User::fromAttributes(self::$attributes); if (Config::get('use_application_cache')) { $currentTime = time(); self::$creationTime = $currentTime; self::$expiredTime = $currentTime + Config::get('notes_auth_cache_expired'); self::$sessionKey = Utilities::generateSessionKey(56); } self::storeCache(); } } return self::$user; }