id = $user->id; $authUser->name = $user->name; $authUser->avatar = $user->avatar; $authUser->admin_role = $user->admin_role; $authUser->edu_role = $user->edu_role; $authToken = $this->getRandToken($user->id); $cacheKey = $this->getCacheKey($authToken); $cache = $this->getCache(); $cache->save($cacheKey, $authUser); } public function clearAuthInfo() { $authToken = $this->getAuthToken(); $cacheKey = $this->getCacheKey($authToken); $cache = $this->getCache(); $cache->delete($cacheKey); } public function getAuthInfo() { $authToken = $this->getAuthToken(); $cacheKey = $this->getCacheKey($authToken); $cache = $this->getCache(); return $cache->get($cacheKey); } public function getAuthToken() { $authToken = $this->request->getHeader('Authorization'); return $authToken; } public function getCacheKey($token) { return "token:{$token}"; } public function getRandToken($userId) { $token = md5($userId . time() . rand(1000, 9999)); return $token; } /** * @return RedisCache */ public function getCache() { $cache = $this->getDI()->get('cache'); return $cache; } }