Skip to content

Commit

Permalink
Because of B/C issues, login/logout code needed to be moved into the …
Browse files Browse the repository at this point in the history
…Login plugin
  • Loading branch information
mahagr committed Aug 10, 2017
1 parent 6e511d0 commit dbebd14
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 191 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* Added `Grav\Framework\ContentBlock` classes for nested HTML blocks with CSS/JS assets
* Added `Grav\Framework\Object` classes for creating collections of objects
* Added `Grav\Framework\Page` interfaces
* Added `$grav->login()` and `$grav->logout()` functions with event hooks for plugins
* Added events `onUserLoginAuthenticate`, `onUserLoginAuthorize`, `onUserLoginFailure`, `onUserLogin`, `onUserLogout`
* Added `|nicenumber` Twig filter
* Deprecated GravTrait
1. [](#improved)
Expand Down
40 changes: 0 additions & 40 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use Grav\Common\Page\Medium\ImageMedium;
use Grav\Common\Page\Medium\Medium;
use Grav\Common\Page\Page;
use Grav\Common\User\Authentication;
use Grav\Common\User\User;
use RocketTheme\Toolbox\DI\Container;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\Event\EventDispatcher;
Expand Down Expand Up @@ -218,44 +216,6 @@ public function redirectLangSafe($route, $code = null)
}
}

/**
* Login user.
*
* @param array $credentials
* @param array $options
* @return User
*/
public function login(array $credentials, array $options = [])
{
if (isset($this['user']) && $this['user']->authenticated) {
return null;
}

unset($this['user']);

$user = Authentication::login($credentials, $options);
if ($user) {
$this['user'] = $user;
}

return $user;
}

/**
* Logout user.
*
* @param array $options
*/
public function logout(array $options = [])
{
if (isset($this['user'])) {
$user = Authentication::logout($this['user'], $options);

unset($this['user']);
$this['user'] = $user;
}
}

/**
* Set response header.
*/
Expand Down
73 changes: 0 additions & 73 deletions system/src/Grav/Common/User/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,8 @@

namespace Grav\Common\User;

use Grav\Common\Grav;
use Grav\Common\User\Events\UserLoginEvent;

abstract class Authentication
{
/**
* Login user.
*
* @param array $credentials
* @param array $options
* @return User
*/
public static function login(array $credentials, array $options = [])
{
$grav = Grav::instance();

$eventOptions = [
'credentials' => $credentials,
'options' => $options
];

// Attempt to authenticate the user.
$event = new UserLoginEvent($eventOptions);
$grav->fireEvent('onUserLoginAuthenticate', $event);

// Allow plugins to prevent login after successful authentication.
if ($event->status === UserLoginEvent::AUTHENTICATION_SUCCESS) {
$event = new UserLoginEvent($event->toArray());
$grav->fireEvent('onUserLoginAuthorize', $event);
}

if ($event->status !== UserLoginEvent::AUTHENTICATION_SUCCESS) {
// Allow plugins to log errors or do other tasks on failure.
$event = new UserLoginEvent($event->toArray());
$grav->fireEvent('onUserLoginFailure', $event);

$event->user->authenticated = false;

} else {
// User has been logged in, let plugins know.
$event = new UserLoginEvent($event->toArray());
$grav->fireEvent('onUserLogin', $event);

$event->user->authenticated = true;
}

return $event->user;
}

/**
* Logout user.
*
* @param User $user
* @param array $options
* @return User
*/
public static function logout(User $user, array $options = [])
{
$grav = Grav::instance();

$eventOptions = [
'user' => $user,
'options' => $options
];

$event = new UserLoginEvent($eventOptions);

// Logout the user.
$grav->fireEvent('onUserLogout', $event);

$event->user->authenticated = false;

return $event->user;
}

/**
* Create password hash from plaintext password.
*
Expand Down
76 changes: 0 additions & 76 deletions system/src/Grav/Common/User/Events/UserLoginEvent.php

This file was deleted.

0 comments on commit dbebd14

Please sign in to comment.