Exemple #1
0
 public function register()
 {
     $accessToken = OAuthManager::getAccessToken();
     if (!$accessToken) {
         throw new Exception\ResourceConflictException('ERR_OAUTH_NO_ACCESS_TOKEN');
     }
     $register = new UserRegister();
     $register->username = $this->username;
     $register->email = $this->email;
     $register->status = 'active';
     $register->accountType = 'basic';
     $register->emailStatus = 'inactive';
     $register->providerType = $accessToken['adapterKey'] . '_' . $accessToken['version'];
     $user = $register->register(true);
     $accessTokenEntity = new AccessTokens();
     $accessTokenEntity->assign($accessToken);
     $accessTokenEntity->tokenStatus = 'active';
     $accessTokenEntity->userId = $user->id;
     if (!$accessTokenEntity->save()) {
         throw new Exception\RuntimeException('ERR_OAUTH_TOKEN_CREATE_FAILED');
     }
     return $user;
 }
Exemple #2
0
 public function loginAction()
 {
     if (!$this->request->isPost()) {
         return;
     }
     $user = new OAuthModels\Login();
     if ($this->request->isAjax()) {
         try {
             $user->connectWithPassword($this->request->getPost('identify'), $this->request->getPost('password'), OAuthManager::getAccessToken());
             OAuthManager::removeAccessToken();
             return $this->showResponseAsJson(UserModels\Login::getCurrentUser());
         } catch (\Exception $e) {
             OAuthManager::removeAccessToken();
             return $this->showExceptionAsJson($e, $user->getMessages());
         }
     } else {
         try {
             $accessToken = OAuthManager::getAccessToken();
             $user->connectWithPassword($accessToken);
             OAuthManager::removeAccessToken();
             return $this->redirectHandler($this->getDI()->getConfig()->oauth->loginSuccessRedirectUri);
         } catch (\Exception $e) {
             $this->showException($e, $user->getMessages());
             return $this->redirectHandler($this->getDI()->getConfig()->oauth->loginFailedRedirectUri);
         }
     }
 }
Exemple #3
0
 public static function getProviderType($platform, $providerChannel = 'manual', $accountType = 'email')
 {
     $platform = in_array($platform, [self::PROVIDER_PLATFORM_WEB, self::PROVIDER_PLATFORM_APP]) ? $platform : self::PROVIDER_PLATFORM_WEB;
     $accessToken = OAuthManager::getAccessToken();
     if (isset($accessToken)) {
         $accountType = $accessToken['adapterKey'];
     }
     $providerChannel = in_array($providerChannel, [self::PROVIDER_CHANNEL_OAUTH, self::PROVIDER_CHANNEL_MANUAL]) ? $providerChannel : self::PROVIDER_CHANNEL_MANUAL;
     return implode('_', [$platform, $providerChannel, $accountType]);
 }