Ejemplo n.º 1
0
 public function testSystemLookupWithApiKey()
 {
     $app = App::find(1);
     $apiKey = $app->api_key;
     Lookup::create($this->systemLookup[0]);
     $this->call(Verbs::GET, '/api/v2/system/environment?api_key=' . $apiKey);
     $this->assertEquals(Arr::get($this->systemLookup, '0.value'), Session::get('lookup.host'));
 }
Ejemplo n.º 2
0
 /**
  * Returns system lookups cached, or reads from db if not present.
  * Pass in a key to return a portion/index of the cached data.
  *
  * @param null|string $key
  * @param null        $default
  *
  * @return mixed|null
  */
 public static function getCachedLookups($key = null, $default = null)
 {
     $cacheKey = 'system_lookups';
     try {
         $result = \Cache::remember($cacheKey, \Config::get('df.default_cache_ttl'), function () {
             return Lookup::all()->toArray();
         });
         if (is_null($result)) {
             return $default;
         }
     } catch (ModelNotFoundException $ex) {
         return $default;
     }
     if (is_null($key)) {
         return $result;
     }
     return isset($result[$key]) ? $result[$key] : $default;
 }
Ejemplo n.º 3
0
 public static function setSessionData($appId = null, $userId = null)
 {
     $appInfo = $appId ? App::getCachedInfo($appId) : null;
     $userInfo = $userId ? User::getCachedInfo($userId) : null;
     $roleId = null;
     if (!empty($userId) && !empty($appId)) {
         $roleId = static::getRoleIdByAppIdAndUserId($appId, $userId);
     }
     if (empty($roleId) && !empty($appInfo)) {
         $roleId = ArrayUtils::get($appInfo, 'role_id');
     }
     Session::setUserInfo($userInfo);
     Session::put('app.id', $appId);
     $roleInfo = $roleId ? Role::getCachedInfo($roleId) : null;
     if (!empty($roleInfo)) {
         Session::put('role.id', $roleId);
         Session::put('role.name', $roleInfo['name']);
         Session::put('role.services', $roleInfo['role_service_access_by_role_id']);
     }
     $systemLookup = Lookup::getCachedLookups();
     $systemLookup = !empty($systemLookup) ? $systemLookup : [];
     $appLookup = !empty($appInfo['app_lookup_by_app_id']) ? $appInfo['app_lookup_by_app_id'] : [];
     $roleLookup = !empty($roleInfo['role_lookup_by_role_id']) ? $roleInfo['role_lookup_by_role_id'] : [];
     $userLookup = !empty($userInfo['user_lookup_by_user_id']) ? $userInfo['user_lookup_by_user_id'] : [];
     $combinedLookup = LookupKey::combineLookups($systemLookup, $appLookup, $roleLookup, $userLookup);
     Session::put('lookup', ArrayUtils::get($combinedLookup, 'lookup'));
     Session::put('lookup_secret', ArrayUtils::get($combinedLookup, 'lookup_secret'));
 }