コード例 #1
0
 public function onSuccess()
 {
     $v = $this->getValues();
     /** @var Auth $presenter */
     $presenter = $this->presenter;
     try {
         $userEntity = $this->orm->users->getByEmail($v->email);
         if ($userEntity && !$userEntity->registered) {
             $presenter->redirect('Auth:registration', ['email' => $v->email]);
         }
         $guest = NULL;
         if ($presenter->user->isPersistedGuest()) {
             // If guest user is persisted, link to it
             // locally so we dont override it with login.
             $guest = $presenter->getUserEntity();
         }
         $presenter->user->login($v->email, $v->password);
         if ($guest && $guest instanceof User) {
             $this->userMerger->mergeUserInto($guest, $presenter->getUserEntity());
             $this->orm->flush();
         }
         $presenter->onLogin($userEntity, NULL, 'password');
     } catch (AuthenticationException $e) {
         $presenter->flashError($e->getMessage());
     }
 }
コード例 #2
0
 /**
  * @param StdClass|ProfileInfo $me
  * @param callable $findById
  * @param callable $update
  * @param NULL|string $service for logging
  * @return User
  */
 private function registerOrLogin($me, $findById, $update, $service = NULL)
 {
     /** @var User $userEntity */
     $userEntity = $findById($me->id);
     $newUser = FALSE;
     if (!$userEntity) {
         $userEntity = $this->orm->users->getByEmail($me->email);
     }
     if (!$userEntity) {
         $newUser = TRUE;
         $userEntity = new User();
         $this->orm->users->attach($userEntity);
         $userEntity->email = Strings::lower($me->email);
     }
     $isGoogle = $me instanceof ProfileInfo;
     $firstName = $isGoogle ? $me->givenName : $me->{'first_name'};
     $userEntity->gender = $me->gender ?: $this->orm->users->getGender($firstName);
     $userEntity->name = $me->name;
     $userEntity->familyName = $isGoogle ? $me->familyName : $me->{'last_name'};
     $userEntity->firstName = $firstName;
     $userEntity->avatar = $isGoogle ? "{$me->picture}?sz=100" : "https://graph.facebook.com/{$me->id}/picture/?type=square&height=50&width=50";
     // intentionally 50, fb returns 2x
     $update($userEntity, $me);
     $guest = NULL;
     if ($this->user->getId() && !$this->userEntity->registered) {
         $guest = $this->userEntity;
     }
     $this->orm->flush();
     $this->user->login(new Identity($userEntity->id));
     if ($newUser) {
         $this->iLog("auth.registration.{$service}");
     }
     if ($guest) {
         $this->userMerger->mergeUserInto($guest, $userEntity);
     }
     $this->orm->flush();
     $this->onLogin($userEntity, $newUser, $service);
 }