-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
$grav->login()
and $grav->logout()
functions with event hoo…
…ks for plugins Added events `onUserLoginAuthenticate`, `onUserLoginAuthorize`, `onUserLoginFailure`, `onUserLogin`, `onUserLogout`
- Loading branch information
Showing
6 changed files
with
217 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* @package Grav.Common.User | ||
* | ||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\User\Events; | ||
|
||
use Grav\Common\User\User; | ||
use RocketTheme\Toolbox\Event\Event; | ||
|
||
/** | ||
* Class UserLoginEvent | ||
* @package Grav\Common\User\Events | ||
* | ||
* @property int $status | ||
* @property array $credentials | ||
* @property array $options | ||
* @property User $user | ||
* @property string $message | ||
* | ||
*/ | ||
class UserLoginEvent extends Event | ||
{ | ||
/** | ||
* Undefined event state. | ||
*/ | ||
const AUTHENTICATION_UNDEFINED = 0; | ||
|
||
/** | ||
* onUserAuthenticate success. | ||
*/ | ||
const AUTHENTICATION_SUCCESS = 1; | ||
|
||
/** | ||
* onUserAuthenticate fails on bad username/password. | ||
*/ | ||
const AUTHENTICATION_FAILURE = 2; | ||
|
||
/** | ||
* onUserAuthenticate fails on auth cancellation. | ||
*/ | ||
const AUTHENTICATION_CANCELLED = 4; | ||
|
||
/** | ||
* onUserAuthorizeLogin fails on expired account. | ||
*/ | ||
const AUTHORIZATION_EXPIRED = 8; | ||
|
||
/** | ||
* onUserAuthorizeLogin fails for other reasons. | ||
*/ | ||
const AUTHORIZATION_DENIED = 16; | ||
|
||
public function __construct(array $items = []) | ||
{ | ||
$defaults = [ | ||
'credentials' => ['username' => '', 'password' => ''], | ||
'options' => ['remember_me' => false], | ||
'status' => static::AUTHENTICATION_UNDEFINED, | ||
'user' => null, | ||
'message' => '' | ||
]; | ||
|
||
parent::__construct(array_merge_recursive($defaults, $items)); | ||
|
||
$username = $this['credentials']['username']; | ||
$this['user'] = $username ? User::load($username, false) : new User; | ||
} | ||
|
||
public function removeCredentials() | ||
{ | ||
unset($this['credentials']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.