Skip to content

Commit

Permalink
Added authorized support (2FA)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 10, 2018
1 parent 2c7d866 commit 2c82e15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions system/src/Grav/Common/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Grav\Common\Twig\TokenParser\TwigTokenParserSwitch;
use Grav\Common\Twig\TokenParser\TwigTokenParserTryCatch;
use Grav\Common\Twig\TokenParser\TwigTokenParserMarkdown;
use Grav\Common\User\User;
use Grav\Common\Utils;
use Grav\Common\Markdown\Parsedown;
use Grav\Common\Markdown\ParsedownExtra;
Expand Down Expand Up @@ -875,7 +876,10 @@ public function translateFunc()
*/
public function authorize($action)
{
if (!$this->grav['user']->authenticated) {
/** @var User $user */
$user = $this->grav['user'];

if (!$user->authenticated || (isset($user->authorized) && !$user->authorized)) {
return false;
}

Expand All @@ -884,7 +888,7 @@ public function authorize($action)
$prefix = is_int($key) ? '' : $key . '.';
$perms = $prefix ? (array) $perms : [$perms => true];
foreach ($perms as $action2 => $authenticated) {
if ($this->grav['user']->authorize($prefix . $action2)) {
if ($user->authorize($prefix . $action2)) {
return $authenticated;
}
}
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public static function find($query, $fields = ['username', 'email'])
$files = $account_dir ? array_diff(scandir($account_dir), ['.', '..']) : [];

// Try with username first, you never know!
if (in_array('username', $fields)) {
if (in_array('username', $fields, true)) {
$user = User::load($query);
unset($fields[array_search('username', $fields)]);
unset($fields[array_search('username', $fields, true)]);
} else {
$user = User::load('');
}
Expand Down

0 comments on commit 2c82e15

Please sign in to comment.