mirror of
https://github.com/friendica/friendica
synced 2025-04-25 21:50:12 +00:00
Merge pull request #10275 from very-ape/authenticate-hook
Move the 'authenticate' hook deeper into the authentication flow so t…
This commit is contained in:
commit
09cf32926d
3 changed files with 51 additions and 34 deletions
|
@ -240,34 +240,12 @@ class Authentication
|
|||
{
|
||||
$record = null;
|
||||
|
||||
$addon_auth = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'authenticated' => 0,
|
||||
'user_record' => null
|
||||
];
|
||||
|
||||
/*
|
||||
* An addon indicates successful login by setting 'authenticated' to non-zero value and returning a user record
|
||||
* Addons should never set 'authenticated' except to indicate success - as hooks may be chained
|
||||
* and later addons should not interfere with an earlier one that succeeded.
|
||||
*/
|
||||
Hook::callAll('authenticate', $addon_auth);
|
||||
|
||||
try {
|
||||
if ($addon_auth['authenticated']) {
|
||||
$record = $addon_auth['user_record'];
|
||||
|
||||
if (empty($record)) {
|
||||
throw new Exception($this->l10n->t('Login failed.'));
|
||||
}
|
||||
} else {
|
||||
$record = $this->dba->selectFirst(
|
||||
'user',
|
||||
[],
|
||||
['uid' => User::getIdFromPasswordAuthentication($username, $password)]
|
||||
);
|
||||
}
|
||||
$record = $this->dba->selectFirst(
|
||||
'user',
|
||||
[],
|
||||
['uid' => User::getIdFromPasswordAuthentication($username, $password)]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->logger->warning('authenticate: failed login attempt', ['action' => 'login', 'username' => Strings::escapeTags($username), 'ip' => $_SERVER['REMOTE_ADDR']]);
|
||||
notice($this->l10n->t('Login failed. Please check your credentials.'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue