Beispiel #1
0
 public function __construct(Github\OAuth\Login $login, Github\Api $api, Nette\Http\Session $session)
 {
     $session = $session->getSection('milo.github.nette-extension.user');
     if ($login->hasToken()) {
         $token = $login->getToken();
         $hash = sha1($token->getValue());
         if ($session->hash !== $hash) {
             $info = $this->defaults;
             $user = $api->decode($api->get('/user'));
             $info['id'] = $user->id;
             $info['login'] = $user->login;
             $info['name'] = $user->name;
             $info['avatarUrl'] = $user->avatar_url;
             if ($token->hasScope('user:email')) {
                 $emails = $api->decode($api->get('/user/emails'));
                 foreach ($emails as $email) {
                     $info['email'] = $email->email;
                     if ($email->primary) {
                         break;
                     }
                 }
             }
             $session->info = $info;
             $session->hash = $hash;
         }
         $this->isLoggedIn = TRUE;
     } else {
         $session->remove();
         $session->info = $this->defaults;
     }
     $this->info = $session->info;
 }
Beispiel #2
0
 /**
  * Signs out the user (drops the token).
  */
 public function actionSignOut()
 {
     $this->login->dropToken();
     $this->forward('signOutRedirect');
 }