Skip to content

Commit

Permalink
Merge branch 'release/3.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 11, 2020
2 parents 6b36d91 + a9183f8 commit 60f926e
Show file tree
Hide file tree
Showing 25 changed files with 249 additions and 101 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 3.0.6
## 02/11/2020

1. [](#new)
* Pass phpstan level 1 tests
* Updated 2FA library to v1.7.0
* [](#improved)
* Added some debugging messages (turned off by default)

# 3.0.5
## 01/02/2020

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Login
version: 3.0.5
version: 3.0.6
testing: false
description: Enables user authentication and login screen.
icon: sign-in
Expand Down
12 changes: 1 addition & 11 deletions classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ class Controller
*/
protected $prefix = 'task';

/**
* @var RememberMe\RememberMe
* @deprecated 2.0 Use $grav['login']->rememberMe() instead
*/
protected $rememberMe;

/**
* @var Login
*/
Expand All @@ -78,8 +72,6 @@ public function __construct(Grav $grav, $action, $post = null)
$this->action = $action;
$this->login = $this->grav['login'];
$this->post = $post ? $this->getPost($post) : [];

$this->rememberMe();
}

/**
Expand Down Expand Up @@ -554,9 +546,7 @@ protected function jsonDecode(array $data)
*/
public function rememberMe($var = null)
{
$this->rememberMe = $this->login->rememberMe($var);

return $this->rememberMe;
return $this->login->rememberMe($var);
}

/**
Expand Down
21 changes: 20 additions & 1 deletion classes/Events/UserLoginEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Grav\Common\Session;
use Grav\Common\User\Interfaces\UserCollectionInterface;
use Grav\Common\User\Interfaces\UserInterface;
use Grav\Plugin\Login\Login;
use RocketTheme\Toolbox\Event\Event;

/**
Expand Down Expand Up @@ -92,7 +93,17 @@ public function __construct(array $items = [])
if (!$this->offsetExists('user')) {
/** @var UserCollectionInterface $users */
$users = Grav::instance()['accounts'];
$this->offsetSet('user', $users->load($this['credentials']['username']));
$user = $users->load($this['credentials']['username']);
$this->offsetSet('user', $user);

if (Login::DEBUG) {
if ($user->exists()) {
Login::addDebugMessage('Login user:', $user);
} else {
Login::addDebugMessage("Login: user '{$this['credentials']['username']}' not found");
}
}

}
}

Expand Down Expand Up @@ -349,4 +360,12 @@ public function __unset($offset)
{
$this->offsetUnset($offset);
}

/**
* @return array
*/
public function __debugInfo(): array
{
return get_object_vars($this);
}
}
20 changes: 19 additions & 1 deletion classes/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Birke\Rememberme\Cookie;
use Grav\Common\Config\Config;
use Grav\Common\Data\Data;
use Grav\Common\Debugger;
use Grav\Common\Grav;
use Grav\Common\Language\Language;
use Grav\Common\Page\Interfaces\PageInterface;
Expand All @@ -32,6 +33,8 @@
*/
class Login
{
public const DEBUG = 1;

/** @var Grav */
protected $grav;

Expand Down Expand Up @@ -73,6 +76,17 @@ public function __construct(Grav $grav)
$this->uri = $this->grav['uri'];
}

/**
* @param string $message
* @param array $data
*/
public static function addDebugMessage(string $message, $data = [])
{
/** @var Debugger $debugger */
$debugger = Grav::instance()['debugger'];
$debugger->addMessage($message, 'debug', $data);
}

/**
* Login user.
*
Expand All @@ -95,6 +109,7 @@ public function login(array $credentials, array $options = [], array $extra = []
$grav->fireEvent('onUserLoginAuthenticate', $event);

if ($event->isSuccess()) {
static::DEBUG && static::addDebugMessage('Login onUserLoginAuthenticate: success', $event);

// Make sure that event didn't mess up with the user authorization.
$user = $event->getUser();
Expand All @@ -107,6 +122,8 @@ public function login(array $credentials, array $options = [], array $extra = []
}

if ($event->isSuccess()) {
static::DEBUG && static::addDebugMessage('Login onUserLoginAuthorize: success', $event);

// User has been logged in, let plugins know.
$event = new UserLoginEvent($event->toArray());
$grav->fireEvent('onUserLogin', $event);
Expand All @@ -117,6 +134,8 @@ public function login(array $credentials, array $options = [], array $extra = []
$user->authorized = !$event->isDelayed();

} else {
static::DEBUG && static::addDebugMessage('Login failed', $event);

// Allow plugins to log errors or do other tasks on failure.
$event = new UserLoginEvent($event->toArray());
$grav->fireEvent('onUserLoginFailure', $event);
Expand Down Expand Up @@ -650,5 +669,4 @@ public function getProviderLoginTemplates()
{
return $this->provider_login_templates;
}

}
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
},
"autoload": {
"psr-4": {
"Grav\\Plugin\\Login\\": "classes/"
}
"Grav\\Plugin\\Login\\": "classes/",
"Grav\\Plugin\\Console\\": "cli/"
},
"classmap": [
"login.php"
]
},
"config": {
"platform": {
Expand Down
22 changes: 13 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function pageVisibility(Event $e)

foreach ($pages->instances() as $page) {
$header = $page->header();
if (isset($header) && isset($header->access) && isset($header->login['visibility_requires_access']) && $header->login['visibility_requires_access'] === true) {
if ($header && isset($header->access) && isset($header->login['visibility_requires_access']) && $header->login['visibility_requires_access'] === true) {
$config = $this->mergeConfig($page);
$access = $this->login->isUserAuthorizedForPage($user, $page, $config);
if ($access === false) {
Expand Down Expand Up @@ -671,7 +671,6 @@ private function processUserRegistration($form, Event $event)
}

$form->validate();
$form->filter();

/** @var Data $form_data */
$form_data = $form->getData();
Expand Down Expand Up @@ -827,7 +826,6 @@ private function processUserProfile($form, Event $event)
$language = $this->grav['language'];

$form->validate();
$form->filter();

/** @var Data $form_data */
$form_data = $form->getData();
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
$baseDir = dirname($vendorDir);

return array(
'Grav\\Plugin\\LoginPlugin' => $baseDir . '/login.php',
);
1 change: 1 addition & 0 deletions vendor/composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
return array(
'RobThree\\Auth\\' => array($vendorDir . '/robthree/twofactorauth/lib'),
'Grav\\Plugin\\Login\\' => array($baseDir . '/classes'),
'Grav\\Plugin\\Console\\' => array($baseDir . '/cli'),
'Birke\\' => array($vendorDir . '/birke/rememberme/src'),
);
10 changes: 10 additions & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ComposerStaticIniteed5e5cf0aa1e2139f2db7445511e366
'G' =>
array (
'Grav\\Plugin\\Login\\' => 18,
'Grav\\Plugin\\Console\\' => 20,
),
'B' =>
array (
Expand All @@ -34,6 +35,10 @@ class ComposerStaticIniteed5e5cf0aa1e2139f2db7445511e366
array (
0 => __DIR__ . '/../..' . '/classes',
),
'Grav\\Plugin\\Console\\' =>
array (
0 => __DIR__ . '/../..' . '/cli',
),
'Birke\\' =>
array (
0 => __DIR__ . '/..' . '/birke/rememberme/src',
Expand All @@ -50,12 +55,17 @@ class ComposerStaticIniteed5e5cf0aa1e2139f2db7445511e366
),
);

public static $classMap = array (
'Grav\\Plugin\\LoginPlugin' => __DIR__ . '/../..' . '/login.php',
);

public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticIniteed5e5cf0aa1e2139f2db7445511e366::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticIniteed5e5cf0aa1e2139f2db7445511e366::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticIniteed5e5cf0aa1e2139f2db7445511e366::$prefixesPsr0;
$loader->classMap = ComposerStaticIniteed5e5cf0aa1e2139f2db7445511e366::$classMap;

}, null, ClassLoader::class);
}
Expand Down
14 changes: 7 additions & 7 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,26 @@
},
{
"name": "robthree/twofactorauth",
"version": "1.6.1",
"version_normalized": "1.6.1.0",
"version": "1.7.0",
"version_normalized": "1.7.0.0",
"source": {
"type": "git",
"url": "https://github.com/RobThree/TwoFactorAuth.git",
"reference": "a77e7d822343bb88112baef808839cfae7bc5abb"
"reference": "37983bf675c5baca09d19d6705170489d0df0002"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/RobThree/TwoFactorAuth/zipball/a77e7d822343bb88112baef808839cfae7bc5abb",
"reference": "a77e7d822343bb88112baef808839cfae7bc5abb",
"url": "https://api.github.com/repos/RobThree/TwoFactorAuth/zipball/37983bf675c5baca09d19d6705170489d0df0002",
"reference": "37983bf675c5baca09d19d6705170489d0df0002",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "@stable"
},
"time": "2017-11-06T17:55:56+00:00",
"time": "2020-01-02T19:56:46+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down
17 changes: 7 additions & 10 deletions vendor/robthree/twofactorauth/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
language: php

dist: trusty
matrix:
include:
- php: 5.3
dist: precise

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
- 7.2
- 7.3
- 7.4

before_script:
- composer install

script:
- if [[ "$TRAVIS_PHP_VERSION" == '5.6' ]]; then phpunit --coverage-text tests ; fi
- vendor/bin/phpunit --coverage-text tests
Loading

0 comments on commit 60f926e

Please sign in to comment.