config = $config; $this->session = $session; $this->cache = $cache; } /** * Set the current user. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @return void */ public function setUser(NamiUser $user) { $this->user = $user; } public function user() { if (! is_null($this->user)) { return $this->user; } $cache = $this->resolveCache(); if (!$cache) { return; } return NamiUser::fromCredentials($cache['credentials']); } public function attempt(array $credentials = [], $remember = false) { $api = Nami::login($credentials['mglnr'], $credentials['password']); $payload = [ 'cookie' => $api->cookie->toArray(), 'credentials' => $credentials ]; $this->setUser(new NamiUser($payload)); $key = $this->newCacheKey(); Cache::forever("namiauth-{$key}", $payload); $this->updateSession($key); return true; } protected function updateSession($data) { $this->session->put($this->getName(), $data); $this->session->migrate(true); } public function getName() { return 'auth_key'; } private function resolveCache() { return $this->cache->get($this->session->get($this->getName())); } private function newCacheKey() { return Str::random(16); } }