Hook: Add hook for check login credentials - refs BT#15992

pull/3127/head
Angel Fernando Quiroz Campos 7 years ago
parent 5b0288f3cc
commit 94b7402812
  1. 37
      main/inc/lib/hook/CheckLoginCredentialsHook.php
  2. 15
      main/inc/lib/hook/interfaces/CheckLoginCredentialsHookEventInterface.php
  3. 15
      main/inc/lib/hook/interfaces/CheckLoginCredentialsHookObserverInterface.php
  4. 13
      main/inc/local.inc.php

@ -0,0 +1,37 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class CheckLoginCredentialsHook.
*/
class CheckLoginCredentialsHook extends HookEvent implements CheckLoginCredentialsHookEventInterface
{
/**
* CheckLoginCredentialsHook constructor.
*
* @throws Exception
*/
protected function __construct()
{
parent::__construct('CheckLoginCredentialsHook');
}
/**
* Call to all observers.
*
* @return bool
*/
public function notifyLoginCredentials()
{
/** @var CheckLoginCredentialsHookObserverInterface $observer */
foreach ($this->observers as $observer) {
$isChecked = $observer->checkLoginCredentials($this);
if ($isChecked) {
return true;
}
}
return false;
}
}

@ -0,0 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface CheckLoginCredentialsHookEventInterface.
*/
interface CheckLoginCredentialsHookEventInterface extends HookEventInterface
{
/**
* Call to all observers.
*
* @return bool
*/
public function notifyLoginCredentials();
}

@ -0,0 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface CheckLoginCredentialsHookObserverInterface.
*/
interface CheckLoginCredentialsHookObserverInterface extends HookObserverInterface
{
/**
* @param CheckLoginCredentialsHookEventInterface $event
*
* @return bool
*/
public function checkLoginCredentials(CheckLoginCredentialsHookEventInterface $event);
}

@ -376,6 +376,19 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) {
$checkUserFromExternalWebservice = true;
}
}
$checkLoginCredentialHook = CheckLoginCredentialsHook::create();
if (!empty($checkLoginCredentialHook)) {
$checkLoginCredentialHook->setEventData([
'user' => $uData,
'credentials' => [
'username' => $login,
'password' => $password,
]
]);
$validPassword = $checkLoginCredentialHook->notifyLoginCredentials();
}
}
// Check the user's password

Loading…
Cancel
Save