Exemplo n.º 1
0
 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 ?? []);
 }
Exemplo n.º 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);
 }