Skip to content

Commit

Permalink
Migrate to Grav core messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Cosgrove committed Dec 6, 2017
1 parent 5ac90e1 commit 1c89549
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function execute()
{
/** @var \Grav\Common\Language\Language */
$t = $this->grav['language'];
$messages = $this->grav['messages'];
$provider = strtolower($this->action);
$config = $this->grav['config']->get('plugins.login-oauth.providers.' . $this->action, []);

Expand All @@ -95,7 +96,7 @@ public function execute()
$this->service = $this->factory->createService($this->action, $credentials, $this->storage, $scope);
}
if (!$this->service || empty($config)) {
$this->login->setMessage($t->translate(['PLUGIN_LOGIN_OAUTH.OAUTH_PROVIDER_NOT_SUPPORTED', $this->action]));
$messages->add($t->translate(['PLUGIN_LOGIN_OAUTH.OAUTH_PROVIDER_NOT_SUPPORTED', $this->action]));

return true;
}
Expand All @@ -106,9 +107,9 @@ public function execute()
if (is_bool($authenticated)) {
$this->reset();
if ($authenticated) {
$this->login->setMessage($t->translate('PLUGIN_LOGIN.LOGIN_SUCCESSFUL'));
$messages->add($t->translate('PLUGIN_LOGIN.LOGIN_SUCCESSFUL'));
} else {
$this->login->setMessage($t->translate('PLUGIN_LOGIN.ACCESS_DENIED'));
$messages->add($t->translate('PLUGIN_LOGIN.ACCESS_DENIED'));
}

// Redirect to current URI
Expand All @@ -118,7 +119,7 @@ public function execute()
}
$this->setRedirect($redirect);
} elseif (!$this->grav['session']->oauth) {
$this->login->setMessage($t->translate(['PLUGIN_LOGIN_OAUTH.OAUTH_PROVIDER_NOT_SUPPORTED', $this->action]));
$messages->add($t->translate(['PLUGIN_LOGIN_OAUTH.OAUTH_PROVIDER_NOT_SUPPORTED', $this->action]));
}

return true;
Expand Down Expand Up @@ -241,6 +242,7 @@ public function oauthGoogle()
return $this->genericOAuthProvider(function () {
/** @var \Grav\Common\Language\Language */
$t = $this->grav['language'];
$messages = $this->grav['messages'];

// Get fullname, email and language
$data = json_decode($this->service->request('userinfo'), true);
Expand All @@ -251,7 +253,7 @@ public function oauthGoogle()
$domain = isset($data['hd'])?$data['hd']:'gmail.com';

if ( !in_array($domain, $whitelist) ) {
$this->login->setMessage($t->translate(['PLUGIN_LOGIN_OAUTH.EMAIL_DOMAIN_NOT_PERMITTED', $domain]));
$messages->add($t->translate(['PLUGIN_LOGIN_OAUTH.EMAIL_DOMAIN_NOT_PERMITTED', $domain]));
return null;
}
}
Expand All @@ -261,7 +263,7 @@ public function oauthGoogle()
$domain = isset($data['hd'])?$data['hd']:'gmail.com';

if( in_array($domain, $blacklist)) {
$this->login->setMessage($t->translate(['PLUGIN_LOGIN_OAUTH.EMAIL_DOMAIN_NOT_PERMITTED', $domain]));
$messages->add($t->translate(['PLUGIN_LOGIN_OAUTH.EMAIL_DOMAIN_NOT_PERMITTED', $domain]));
return null;
}
}
Expand Down

0 comments on commit 1c89549

Please sign in to comment.