2012-08-16 11:30:35 +00:00
|
|
|
<?php
|
2021-02-08 16:11:31 +00:00
|
|
|
abstract class Auth_Base extends Plugin implements IAuthModule {
|
|
|
|
protected $pdo;
|
2013-04-18 11:36:54 +00:00
|
|
|
|
2019-11-01 10:03:06 +00:00
|
|
|
const AUTH_SERVICE_API = '_api';
|
|
|
|
|
2013-04-18 11:36:54 +00:00
|
|
|
function __construct() {
|
2017-12-01 14:40:53 +00:00
|
|
|
$this->pdo = Db::pdo();
|
2013-04-18 11:36:54 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 16:11:31 +00:00
|
|
|
function hook_auth_user(...$args) {
|
|
|
|
return $this->authenticate(...$args);
|
2012-08-16 11:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Auto-creates specified user if allowed by system configuration
|
|
|
|
// Can be used instead of find_user_by_login() by external auth modules
|
2021-02-11 07:22:27 +00:00
|
|
|
function auto_create_user(string $login, $password = false) {
|
2021-02-23 06:01:27 +00:00
|
|
|
if ($login && Config::get(Config::AUTH_AUTO_CREATE)) {
|
2021-02-11 07:22:27 +00:00
|
|
|
$user_id = UserHelper::find_user_by_login($login);
|
2013-05-07 08:36:09 +00:00
|
|
|
|
2012-08-16 11:30:35 +00:00
|
|
|
if (!$user_id) {
|
2021-02-11 07:22:27 +00:00
|
|
|
|
|
|
|
if (!$password) $password = make_password();
|
|
|
|
|
2021-03-01 16:32:27 +00:00
|
|
|
$user = ORM::for_table('ttrss_users')->create();
|
|
|
|
|
|
|
|
$user->salt = UserHelper::get_salt();
|
|
|
|
$user->login = mb_strtolower($login);
|
|
|
|
$user->pwd_hash = UserHelper::hash_password($password, $user->salt);
|
|
|
|
$user->access_level = 0;
|
2021-03-01 20:07:20 +00:00
|
|
|
$user->created = Db::NOW();
|
2021-03-01 16:32:27 +00:00
|
|
|
$user->save();
|
2012-08-16 11:30:35 +00:00
|
|
|
|
2021-02-11 07:22:27 +00:00
|
|
|
return UserHelper::find_user_by_login($login);
|
2012-08-16 11:30:35 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return $user_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-11 07:22:27 +00:00
|
|
|
return UserHelper::find_user_by_login($login);
|
2012-08-16 11:30:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 07:22:27 +00:00
|
|
|
// @deprecated
|
|
|
|
function find_user_by_login(string $login) {
|
|
|
|
return UserHelper::find_user_by_login($login);
|
2012-08-16 11:30:35 +00:00
|
|
|
}
|
|
|
|
}
|