Adds branching for when social login user wasn't created

This commit is contained in:
Maxi Redigonda 2020-08-20 16:23:30 -03:00
parent 5d2e4fcb1f
commit 0518b0ac17
1 changed files with 10 additions and 15 deletions

View File

@ -55,24 +55,19 @@ class LoginController extends Controller {
$client = new Google_Client(['client_id' => '50174278643-gtvjdpm5rmkv75lf3jsp95iv77a2usgu.apps.googleusercontent.com']); // Specify the CLIENT_ID of the app that accesses the backend $client = new Google_Client(['client_id' => '50174278643-gtvjdpm5rmkv75lf3jsp95iv77a2usgu.apps.googleusercontent.com']); // Specify the CLIENT_ID of the app that accesses the backend
$payload = $client->verifyIdToken(Controller::request('googleId')); $payload = $client->verifyIdToken(Controller::request('googleId'));
if ($payload) { if ($payload) {
// $userid = $payload['sub'];
// ob_start();
// var_dump($payload);
// $result = ob_get_clean();
$this->userInstance = User::getUser($payload['email'], 'email'); $this->userInstance = User::getUser($payload['email'], 'email');
if ($this->userInstance->isNull()) {
// Here I should create a new user with this email...
throw new Exception("Creating of new user by Google login yet to be done");
} else {
Session::getInstance()->createSession($this->userInstance->id, false); Session::getInstance()->createSession($this->userInstance->id, false);
Response::respondSuccess($this->getUserData()); Response::respondSuccess($this->getUserData());
return; return;
} else {
echo "Invalid token" . PHP_EOL;
} }
} else {
Response::respondSuccess(array( throw new Exception("Invalid GoogleID token");
'userId' => -1, }
));
return;
} }
if ($this->checkInputCredentials() || $this->checkRememberToken()) { if ($this->checkInputCredentials() || $this->checkRememberToken()) {