/**
  * 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);
     }
 }
示例#2
0
<?php

/**
 * This file is part of the Notes project.
 * 2013 - 2015 / RENATER
 */
define('NOTES_BASE', dirname(dirname(__FILE__)));
require_once NOTES_BASE . '/autoload.php';
require_once NOTES_BASE . '/config/ConfigValidation.php';
define('site_url', Config::get('site_url'));
date_default_timezone_set(Config::get('default_timezone'));
if (php_sapi_name() === 'cli') {
    // Command Line Interface
    include NOTES_BASE . '/includes/init/init_cli.php';
} else {
    // Default, GUI
    include NOTES_BASE . '/includes/init/init_gui.php';
}
if (getenv('HTTP_X_AUTH_APPLICATIONNAME') && getenv('HTTP_X_AUTH_APPLICATIONSECRET')) {
    // LocalApplication call
    AuthLocalApplication::setUser(getenv('HTTP_X_AUTH_APPLICATIONNAME'), getenv('HTTP_X_AUTH_APPLICATIONSECRET'), getenv('HTTP_X_AUTH_USEREMAIL'));
}
示例#3
0
 /**
  * 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;
 }