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,22 +54,40 @@ class AuthController extends ControllerBase
|
||||||
// NOTE: Should pass $state here also.
|
// NOTE: Should pass $state here also.
|
||||||
$data = $client->authenticate($code);
|
$data = $client->authenticate($code);
|
||||||
|
|
||||||
$result = $this->auth->loginOauth($data);
|
// If user is authed already, we connect.
|
||||||
|
$user = $this->auth->getUser();
|
||||||
|
if ($user) {
|
||||||
|
|
||||||
// There was an error when creating the account
|
$name = ucfirst($provider_name);
|
||||||
if (is_array($result)) {
|
$user->{'set' . $name . 'Id'}($data->getId());
|
||||||
$msg = '';
|
$user->save();
|
||||||
foreach($result as $message) {
|
|
||||||
$msg .= '<li>' . $message->getMessage() . '</li>';
|
$this->flash->message('success', "<strong>{$name}</strong> was connected!");
|
||||||
|
$this->response->redirect('/settings');
|
||||||
|
}
|
||||||
|
// Perform Auth.
|
||||||
|
else {
|
||||||
|
$result = $this->auth->loginOauth($data);
|
||||||
|
|
||||||
|
// There was an error when creating the account
|
||||||
|
if (is_array($result)) {
|
||||||
|
$msg = '';
|
||||||
|
foreach ($result as $message) {
|
||||||
|
$msg .= '<li>' . $message->getMessage() . '</li>';
|
||||||
|
}
|
||||||
|
$this->flash->message('error', "Failed to create account: <ul>{$msg}</ul>");
|
||||||
|
$this->response->redirect('/login');
|
||||||
|
} else {
|
||||||
|
$this->response->redirect('/');
|
||||||
}
|
}
|
||||||
$this->flash->message('error', "Failed to create account: <ul>{$msg}</ul>");
|
|
||||||
$this->response->redirect('/login');
|
|
||||||
} else {
|
|
||||||
$this->response->redirect('/');
|
|
||||||
}
|
}
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->flash->message('error', 'Failed to authenticate.');
|
$this->flash->message('error', 'Failed to authenticate.');
|
||||||
$this->response->redirect('/login');
|
if ($this->auth->getUser()) {
|
||||||
|
$this->response->redirect('/settings');
|
||||||
|
} else {
|
||||||
|
$this->response->redirect('/login');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// No code
|
// No code
|
||||||
|
|
|
||||||
Reference in a new issue