1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-11 17:24:46 +02:00

Add 4 new hookable methods to ProcessLogin

This commit is contained in:
Ryan Cramer
2023-07-21 10:06:02 -04:00
parent 1c70f8b5e3
commit 3b1e349a4a

View File

@@ -8,7 +8,7 @@
* For more details about how Process modules work, please see: * For more details about how Process modules work, please see:
* /wire/core/Process.php * /wire/core/Process.php
* *
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* @property bool $allowForgot Whether the ProcessForgotPassword module is installed. * @property bool $allowForgot Whether the ProcessForgotPassword module is installed.
@@ -32,6 +32,10 @@
* @method void login($name, $pass) #pw-hooker * @method void login($name, $pass) #pw-hooker
* @method void loginFailed($name, $message = '') #pw-hooker * @method void loginFailed($name, $message = '') #pw-hooker
* @method void loginSuccess(User $user) #pw-hooker * @method void loginSuccess(User $user) #pw-hooker
* @method void loginAttemptReady($name) #pw-hooker 3.0.223+
* @method void loginAttempted($user, $name) #pw-hooker 3.0.223+
* @method void loginFormProcessReady($form) #pw-hooker 3.0.223+
* @method void loginFormProcessed($form, $name) #pw-hooker 3.0.223+
* @method array getBeforeLoginVars() #pw-hooker * @method array getBeforeLoginVars() #pw-hooker
* @method array getLoginLinks() #pw-hooker * @method array getLoginLinks() #pw-hooker
* @method string renderLoginLinks() #pw-hooker * @method string renderLoginLinks() #pw-hooker
@@ -360,16 +364,19 @@ class ProcessLogin extends Process implements ConfigurableModule {
$this->buildLoginForm(); $this->buildLoginForm();
$loginSubmit = $input->post('login_submit'); $loginSubmit = $input->post('login_submit');
if($loginSubmit) { if(!$loginSubmit) {
$this->form->processInput($input->post);
} else {
$this->beforeLogin(); $this->beforeLogin();
return $this->renderLoginForm(); return $this->renderLoginForm();
} }
$this->loginFormProcessReady($this->form);
$this->form->processInput($input->post);
// at this point login form has been submitted // at this point login form has been submitted
$name = $this->getLoginName(); $name = $this->getLoginName();
$pass = substr($this->passField->attr('value'), 0, 128); $pass = substr($this->passField->attr('value'), 0, 128);
$this->loginFormProcessed($this->form, $name);
if(!$name || !$pass) return $this->renderLoginForm(); if(!$name || !$pass) return $this->renderLoginForm();
@@ -542,12 +549,16 @@ class ProcessLogin extends Process implements ConfigurableModule {
$session = $this->wire()->session; $session = $this->wire()->session;
$input = $this->wire()->input; $input = $this->wire()->input;
$this->loginAttemptReady($name);
if($name && $pass) { if($name && $pass) {
$loginUser = $session->login($name, $pass); $loginUser = $session->login($name, $pass);
} else { } else {
$loginUser = false; $loginUser = false;
} }
$this->loginAttempted($loginUser, $name);
if($loginUser && $loginUser->id) { if($loginUser && $loginUser->id) {
$this->loginSuccess($loginUser); $this->loginSuccess($loginUser);
$url = $input->urlSegment1 === 'navJSON' ? '../' : './'; $url = $input->urlSegment1 === 'navJSON' ? '../' : './';
@@ -960,6 +971,52 @@ class ProcessLogin extends Process implements ConfigurableModule {
return $vars; return $vars;
} }
/**
* Hook called right before a login is attempted
*
* #pw-hooker
*
* @param string $name
* @since 3.0.223
*
*/
protected function ___loginAttemptReady($name) {}
/**
* Hook called immediately after a login was attempted
*
* #pw-hooker
*
* @param User|false $user This will be User object on success, or false on fail
* @param string $name Attempted login name
* @since 3.0.223
*
*/
protected function ___loginAttempted($user, $name) {}
/**
* Hook called immediately before the login form in processed
*
* #pw-hooker
*
* @param InputfieldForm $form
* @since 3.0.223
*
*/
protected function ___loginFormProcessReady($form) {}
/**
* Hook called immediately after login form processed and user name/pass identified as present
*
* #pw-hooker
*
* @param InputfieldForm $form
* @param string $name Attempted user name
* @since 3.0.223
*
*/
protected function ___loginFormProcessed($form, $name) {}
/** /**
* Hook called on login fail * Hook called on login fail
* *
@@ -1207,4 +1264,3 @@ class ProcessLogin extends Process implements ConfigurableModule {
} }
} }