mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2026-02-10 16:01:33 +00:00
fix hierarchy of authentication modules, make everything extend Auth_Base and implement hook_auth_user() for pluginhost
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
class Auth_Base {
|
||||
private $pdo;
|
||||
abstract class Auth_Base extends Plugin implements IAuthModule {
|
||||
protected $pdo;
|
||||
|
||||
const AUTH_SERVICE_API = '_api';
|
||||
|
||||
@@ -8,18 +8,9 @@ class Auth_Base {
|
||||
$this->pdo = Db::pdo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(unused)
|
||||
*/
|
||||
function check_password($owner_uid, $password, $service = '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(unused)
|
||||
*/
|
||||
function authenticate($login, $password, $service = '') {
|
||||
return false;
|
||||
// compatibility wrapper, because of how pluginhost works (hook name == method name)
|
||||
function hook_auth_user(...$args) {
|
||||
return $this->authenticate(...$args);
|
||||
}
|
||||
|
||||
// Auto-creates specified user if allowed by system configuration
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
interface IAuthModule {
|
||||
function authenticate($login, $password); // + optional third parameter: $service
|
||||
function hook_auth_user(...$args); // compatibility wrapper due to how hooks work
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ class UserHelper {
|
||||
$user_id = false;
|
||||
$auth_module = false;
|
||||
|
||||
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_AUTH_USER) as $plugin) {
|
||||
|
||||
$user_id = (int) $plugin->authenticate($login, $password, $service);
|
||||
|
||||
if ($user_id) {
|
||||
$auth_module = strtolower(get_class($plugin));
|
||||
break;
|
||||
}
|
||||
}
|
||||
PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_AUTH_USER,
|
||||
function ($result, $plugin) use (&$user_id, &$auth_module) {
|
||||
if ($result) {
|
||||
$user_id = (int)$result;
|
||||
$auth_module = strtolower(get_class($plugin));
|
||||
return true;
|
||||
}
|
||||
},
|
||||
$login, $password, $service);
|
||||
|
||||
if ($user_id && !$check_only) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user