Пример #1
0
 public function logout()
 {
     if (User::isLoggedIn()) {
         Activity::log("logged out.");
         //remove our token, if we got one.
         if ($_COOKIE['token']) {
             $data = unserialize(base64_decode($_COOKIE['token']));
             $token = Token::byToken($data['token']);
             $token->delete();
         }
         //unset specific variables.
         setcookie('token', '', time() - 420000, '/', SITE_HOSTNAME, FORCE_SSL, true);
         unset($_SESSION['userid']);
         //nuke the session.
         if (isset($_COOKIE[session_name()])) {
             setcookie(session_name(), '', time() - 420000, '/', SITE_HOSTNAME, FORCE_SSL, true);
         }
         session_unset();
         session_destroy();
         $this->forwardToUrl("/");
     }
 }
Пример #2
0
 public function checkToken($t)
 {
     $token = Token::byToken($t);
     if ($token->isHydrated() && $token->get('user_id') == $this->id) {
         return true;
     } else {
         return false;
     }
 }
Пример #3
0
 public function loginandregister()
 {
     $this->setTitle('Login or register a new account.');
     //did we get a redirect payload or anything?
     if ($this->args('payload')) {
         $payload = unserialize(base64_decode($this->args('payload')));
         if (is_array($payload) && $payload['type'] && $payload['data']) {
             $_SESSION['payload'] = $payload;
         }
     }
     //did we get a token?
     if ($this->args('token')) {
         //try to login with it.
         User::loginWithToken($this->args('token'));
         if (User::isLoggedIn()) {
             //fully log them in.
             $data = unserialize(base64_decode($this->args('token')));
             $token = Token::byToken($data['token']);
             $token->setCookie();
             //to our dashboard
             $this->forwardToUrl("/");
         }
     }
 }