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; }
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; } }
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; }