app/controllers/AuthController.php: in oauthAction() if we have an authed user then we should connect accounts.
This commit is contained in:
parent
29e42c7641
commit
adb98241c7
1 changed files with 29 additions and 11 deletions
|
|
@ -54,6 +54,19 @@ class AuthController extends ControllerBase
|
||||||
// NOTE: Should pass $state here also.
|
// NOTE: Should pass $state here also.
|
||||||
$data = $client->authenticate($code);
|
$data = $client->authenticate($code);
|
||||||
|
|
||||||
|
// If user is authed already, we connect.
|
||||||
|
$user = $this->auth->getUser();
|
||||||
|
if ($user) {
|
||||||
|
|
||||||
|
$name = ucfirst($provider_name);
|
||||||
|
$user->{'set' . $name . 'Id'}($data->getId());
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$this->flash->message('success', "<strong>{$name}</strong> was connected!");
|
||||||
|
$this->response->redirect('/settings');
|
||||||
|
}
|
||||||
|
// Perform Auth.
|
||||||
|
else {
|
||||||
$result = $this->auth->loginOauth($data);
|
$result = $this->auth->loginOauth($data);
|
||||||
|
|
||||||
// There was an error when creating the account
|
// There was an error when creating the account
|
||||||
|
|
@ -67,11 +80,16 @@ class AuthController extends ControllerBase
|
||||||
} else {
|
} else {
|
||||||
$this->response->redirect('/');
|
$this->response->redirect('/');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->flash->message('error', 'Failed to authenticate.');
|
$this->flash->message('error', 'Failed to authenticate.');
|
||||||
|
if ($this->auth->getUser()) {
|
||||||
|
$this->response->redirect('/settings');
|
||||||
|
} else {
|
||||||
$this->response->redirect('/login');
|
$this->response->redirect('/login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// No code
|
// No code
|
||||||
else {
|
else {
|
||||||
// redirect to provider and acquire code.
|
// redirect to provider and acquire code.
|
||||||
|
|
|
||||||
Reference in a new issue