Archived
1
0
Fork 0

app/controllers/AuthController.php: in oauthAction() if we have an authed user then we should connect accounts.

This commit is contained in:
Henrik Hautakoski 2018-06-10 20:54:02 +02:00
parent 29e42c7641
commit adb98241c7

View file

@ -54,22 +54,40 @@ class AuthController extends ControllerBase
// NOTE: Should pass $state here also.
$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
if (is_array($result)) {
$msg = '';
foreach($result as $message) {
$msg .= '<li>' . $message->getMessage() . '</li>';
$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);
// 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) {
$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