예제 #1
0
파일: Fwd.php 프로젝트: minutephp/auth
 public function index(string $jwt, string $url = '')
 {
     if ($payload = $this->jwtEx->decode($jwt)) {
         if ($user_id = $payload->user_id ?? 0) {
             if ($user = User::find($user_id)) {
                 if (!empty($payload->authorize)) {
                     /** @var User $user */
                     if ($user->verified == 'n') {
                         $user->ip_addr = $this->sniffer->getUserIP();
                         $user->verified = 'y';
                         $user->save();
                     }
                     $this->session->startSession($user_id);
                 }
                 if (!empty($payload->eventName)) {
                     $event = new UserEvent($user_id, $user->toArray());
                     $event->setData($payload->eventData ?? '');
                     $this->dispatcher->fire($payload->eventName, $event);
                 }
             }
         }
     } else {
         $params = ['msg' => 'Sorry this link has expired'];
     }
     return new Redirection($url ?: '/', $params ?? []);
 }
예제 #2
0
 public function startSession(int $userId, $su = false)
 {
     $expiry = $this->config->get('private/site/session_length', '+1 day');
     $jwtValue = $this->jwt->encode((object) ['user_id' => $userId], $expiry);
     $this->response->setCookie($su ? self::ADMIN_COOKIE_NAME : self::COOKIE_NAME, $jwtValue, $expiry);
 }