Exemplo n.º 1
0
 public function connectWithPassword($identify, $password, array $accessToken)
 {
     $userModel = new UserLogin();
     $user = $userModel->loginByPassword($identify, $password);
     $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;
 }
Exemplo n.º 2
0
 public function bindUserOAuth($userId, array $accessToken)
 {
     $token = AccessTokens::findFirst(array("conditions" => "adapterKey = :adapterKey: AND version = :version: AND remoteUserId = :remoteUserId:", "bind" => array('adapterKey' => $accessToken['adapterKey'], 'version' => $accessToken['version'], 'remoteUserId' => $accessToken['remoteUserId'])));
     if ($token) {
         $token->userId = $userId;
         if (!$token->save()) {
             throw new Exception\RuntimeException('ERR_OAUTH_TOKEN_UPDATE_FAILED');
         }
         return $token;
     } else {
         $accessTokenEntity = new AccessTokens();
         $accessTokenEntity->assign($accessToken);
         $accessTokenEntity->tokenStatus = 'active';
         $accessTokenEntity->userId = $userId;
         if (!$accessTokenEntity->save()) {
             throw new Exception\RuntimeException('ERR_OAUTH_TOKEN_UPDATE_FAILED');
         }
         return $token;
     }
 }
Exemplo n.º 3
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;
 }