/** * Authentication check. * * @return bool */ public static function isAuthenticated() { if (is_null(self::$isAuthenticated)) { self::$isAuthenticated = !is_null(self::$attributes); } return self::$isAuthenticated; }
/** * 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; }