Logout fix

parent 15e2b726
...@@ -128,116 +128,111 @@ class CBController extends ControllerBase ...@@ -128,116 +128,111 @@ class CBController extends ControllerBase
public function authenticatePhase2($request, $authToken, $authVerifier) public function authenticatePhase2($request, $authToken, $authVerifier)
{ {
$taxis_userid = null; $taxis_userid = null;
$trx = $this->connection->startTransaction(); $trx = $this->connection->startTransaction();
try { try {
$oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI); $oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug(); $oauth->enableDebug();
$oauth->setToken($authToken, $this->requestTokenSecret); $oauth->setToken($authToken, $this->requestTokenSecret);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier); $accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']); $oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$oauth->fetch($this->api_url); $oauth->fetch($this->api_url);
$this->logger->warning($oauth->getLastResponse()); $this->logger->warning($oauth->getLastResponse());
$taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText'); $taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText');
$currentTime = time(); $currentTime = time();
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userid)); $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userid));
$epalUser = reset($epalUsers); $epalUser = reset($epalUsers);
$epalToken = md5(uniqid(mt_rand(), true)); $epalToken = md5(uniqid(mt_rand(), true));
if ($epalUser) { if ($epalUser) {
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id); $user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) { if ($user) {
// $user->setPassword('harispass'); $user->setPassword($epalToken);
// $user->setUsername('harisp'); $user->setUsername($epalToken);
$user->setPassword($epalToken); $user->save();
$user->setUsername($epalToken); $epalUser->set('authtoken', $epalToken);
$user->save(); $epalUser->set('accesstoken', $accessToken['oauth_token']);
$epalUser->set('authtoken', $epalToken); $epalUser->set('accesstoken_secret', $accessToken['oauth_token_secret']);
$epalUser->set('accesstoken', $accessToken['oauth_token']); $epalUser->set('requesttoken',$this->requestToken);
$epalUser->set('accesstoken_secret', $accessToken['oauth_token_secret']); $epalUser->set('requesttoken_secret', $this->requestTokenSecret);
$epalUser->set('requesttoken',$this->requestToken); $epalUser->set('timelogin', $currentTime);
$epalUser->set('requesttoken_secret', $this->requestTokenSecret); $epalUser->set('userip', $request->getClientIp());
$epalUser->set('timelogin', $currentTime);
$epalUser->set('userip', $request->getClientIp()); $epalUser->save();
}
$epalUser->save();
} }
}
if ($epalUser === null || !$epalUser) { if ($epalUser === null || !$epalUser) {
//Create a User
$user = User::create();
//Mandatory settings
$unique_id = uniqid('####');
$user->setPassword($epalToken);
$user->enforceIsNew();
$user->setEmail($unique_id);
$user->setUsername($epalToken); //This username must be unique and accept only a-Z,0-9, - _ @ .
$user->activate();
$user->set('init', $unique_id);
//Set Language
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$user->set('langcode', $language_interface->getId());
$user->set('preferred_langcode', $language_interface->getId());
$user->set('preferred_admin_langcode', $language_interface->getId());
//Adding default user role
$user->addRole('applicant');
$user->save();
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('mail' => $unique_id));
$user = reset($users);
if ($user) {
$this->logger->warning('userid 190='.$user->id().'*** name='.$user->name->value);
$epalUser = $this->entityTypeManager()->getStorage('epal_users')->create(array(
// 'langcode' => $language_interface->getId(),
'langcode' => 'el',
'user_id' => $user->id(),
'drupaluser_id' => $user->id(),
'taxis_userid' => $taxis_userid,
'taxis_taxid' => $unique_id,
'name' => $unique_id,
'surname' => $unique_id,
'fathername' => $unique_id,
'mothername' => $unique_id,
'accesstoken' => $accessToken['oauth_token'],
'accesstoken_secret' => $accessToken['oauth_token_secret'],
'authtoken' => $epalToken,
'requesttoken' => $this->requestToken,
'requesttoken_secret' => $this->requestTokenSecret,
'timelogin' => $currentTime,
'timeregistration' => $currentTime,
'timetokeninvalid' => 0,
'userip' => $request->getClientIp(),
'status' => 1
));
$epalUser->save();
} else {
return false;
}
} //Create a User
$this->oauthostSession->set('authtoken', $epalToken); $user = User::create();
$this->oauthostSession->save(); //Mandatory settings
// $this->oauthostSession->delete(); $unique_id = uniqid('####');
$user->setPassword($epalToken);
$user->enforceIsNew();
$user->setEmail($unique_id);
$user->setUsername($epalToken); //This username must be unique and accept only a-Z,0-9, - _ @ .
$user->activate();
$user->set('init', $unique_id);
//Set Language
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$user->set('langcode', $language_interface->getId());
$user->set('preferred_langcode', $language_interface->getId());
$user->set('preferred_admin_langcode', $language_interface->getId());
//Adding default user role
$user->addRole('applicant');
$user->save();
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('mail' => $unique_id));
$user = reset($users);
if ($user) {
$this->logger->warning('userid 190='.$user->id().'*** name='.$user->name->value);
$epalUser = $this->entityTypeManager()->getStorage('epal_users')->create(array(
'langcode' => 'el',
'user_id' => $user->id(),
'drupaluser_id' => $user->id(),
'taxis_userid' => $taxis_userid,
'taxis_taxid' => $unique_id,
'name' => $unique_id,
'surname' => $unique_id,
'fathername' => $unique_id,
'mothername' => $unique_id,
'accesstoken' => $accessToken['oauth_token'],
'accesstoken_secret' => $accessToken['oauth_token_secret'],
'authtoken' => $epalToken,
'requesttoken' => $this->requestToken,
'requesttoken_secret' => $this->requestTokenSecret,
'timelogin' => $currentTime,
'timeregistration' => $currentTime,
'timetokeninvalid' => 0,
'userip' => $request->getClientIp(),
'status' => 1
));
$epalUser->save();
} else {
return false;
}
return $epalToken; }
} catch (OAuthException $e) { $this->oauthostSession->set('authtoken', $epalToken);
$this->logger->warning($e->getMessage()); $this->oauthostSession->save();
$trx->rollback(); // $this->oauthostSession->delete();
return false;
} catch (\Exception $ee) { return $epalToken;
$this->logger->warning($ee->getMessage()); } catch (OAuthException $e) {
$trx->rollback(); $this->logger->warning($e->getMessage());
return false; $trx->rollback();
} return false;
} catch (\Exception $ee) {
$this->logger->warning($ee->getMessage());
$trx->rollback();
return false;
}
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment