2011-12-13 10:00:36 +00:00
|
|
|
<?php
|
2021-02-14 12:50:46 +00:00
|
|
|
class Pref_Users extends Handler_Administrative {
|
2021-11-12 02:01:31 +00:00
|
|
|
function csrf_ignore(string $method): bool {
|
2021-03-01 16:03:21 +00:00
|
|
|
return $method == "index";
|
2011-12-26 08:02:52 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 10:00:36 +00:00
|
|
|
function edit() {
|
2021-03-01 16:03:21 +00:00
|
|
|
$user = ORM::for_table('ttrss_users')
|
2021-03-02 10:29:54 +00:00
|
|
|
->select_expr("id,login,access_level,email,full_name,otp_enabled")
|
2021-03-01 16:03:21 +00:00
|
|
|
->find_one((int)$_REQUEST["id"])
|
|
|
|
->as_array();
|
2017-12-11 15:41:32 +00:00
|
|
|
|
2021-03-01 16:03:21 +00:00
|
|
|
global $access_level_names;
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2021-03-01 16:03:21 +00:00
|
|
|
if ($user) {
|
2021-02-14 13:44:41 +00:00
|
|
|
print json_encode([
|
2021-03-01 16:03:21 +00:00
|
|
|
"user" => $user,
|
|
|
|
"access_level_names" => $access_level_names
|
|
|
|
]);
|
2017-12-02 09:23:41 +00:00
|
|
|
}
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 17:19:38 +00:00
|
|
|
function userdetails() {
|
2017-12-03 20:35:38 +00:00
|
|
|
$id = (int) clean($_REQUEST["id"]);
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT login,
|
2015-08-12 17:19:38 +00:00
|
|
|
".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login,
|
|
|
|
access_level,
|
|
|
|
(SELECT COUNT(int_id) FROM ttrss_user_entries
|
|
|
|
WHERE owner_uid = id) AS stored_articles,
|
|
|
|
".SUBSTRING_FOR_DATE."(created,1,16) AS created
|
|
|
|
FROM ttrss_users
|
2017-12-02 09:23:41 +00:00
|
|
|
WHERE id = ?");
|
|
|
|
$sth->execute([$id]);
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
if ($row = $sth->fetch()) {
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2020-09-23 10:04:26 +00:00
|
|
|
$last_login = TimeHelper::make_local_datetime(
|
2017-12-02 09:23:41 +00:00
|
|
|
$row["last_login"], true);
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2020-09-23 10:04:26 +00:00
|
|
|
$created = TimeHelper::make_local_datetime(
|
2017-12-02 09:23:41 +00:00
|
|
|
$row["created"], true);
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$stored_articles = $row["stored_articles"];
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT COUNT(id) as num_feeds FROM ttrss_feeds
|
|
|
|
WHERE owner_uid = ?");
|
|
|
|
$sth->execute([$id]);
|
|
|
|
$row = $sth->fetch();
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2021-02-18 10:00:20 +00:00
|
|
|
$num_feeds = $row["num_feeds"];
|
2018-11-03 12:08:43 +00:00
|
|
|
|
2021-02-18 10:00:20 +00:00
|
|
|
?>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label><?= __('Registered') ?>:</label>
|
|
|
|
<?= $created ?>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label><?= __('Last logged in') ?>:</label>
|
|
|
|
<?= $last_login ?>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label><?= __('Subscribed feeds') ?>:</label>
|
|
|
|
<?= $num_feeds ?>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label><?= __('Stored articles') ?>:</label>
|
|
|
|
<?= $stored_articles ?>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
$sth = $this->pdo->prepare("SELECT id,title,site_url FROM ttrss_feeds
|
|
|
|
WHERE owner_uid = ? ORDER BY title");
|
|
|
|
$sth->execute([$id]);
|
|
|
|
?>
|
|
|
|
|
|
|
|
<ul class="panel panel-scrollable list list-unstyled">
|
|
|
|
<?php while ($row = $sth->fetch()) { ?>
|
|
|
|
<li>
|
|
|
|
<?php
|
2021-02-22 19:35:27 +00:00
|
|
|
$icon_file = Config::get(Config::ICONS_URL) . "/" . $row["id"] . ".ico";
|
2021-02-18 10:00:20 +00:00
|
|
|
$icon = file_exists($icon_file) ? $icon_file : "images/blank_icon.gif";
|
|
|
|
?>
|
|
|
|
|
|
|
|
<img class="icon" src="<?= $icon_file ?>">
|
|
|
|
|
|
|
|
<a target="_blank" href="<?= htmlspecialchars($row["site_url"]) ?>">
|
|
|
|
<?= htmlspecialchars($row["title"]) ?>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<?php } ?>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<?php
|
2018-11-03 12:08:43 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
} else {
|
2021-02-18 10:00:20 +00:00
|
|
|
print_error(__('User not found'));
|
2015-08-12 17:19:38 +00:00
|
|
|
}
|
2018-11-03 12:08:43 +00:00
|
|
|
|
2015-08-12 17:19:38 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 10:00:36 +00:00
|
|
|
function editSave() {
|
2021-03-01 15:36:47 +00:00
|
|
|
$id = (int)$_REQUEST['id'];
|
2017-12-03 20:35:38 +00:00
|
|
|
$password = clean($_REQUEST["password"]);
|
2021-03-01 15:36:47 +00:00
|
|
|
$user = ORM::for_table('ttrss_users')->find_one($id);
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
$login = clean($_REQUEST["login"]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2021-03-01 15:36:47 +00:00
|
|
|
if ($id == 1) $login = "admin";
|
|
|
|
if (!$login) return;
|
2021-02-14 13:44:41 +00:00
|
|
|
|
2021-03-01 16:32:27 +00:00
|
|
|
$user->login = mb_strtolower($login);
|
2021-03-01 15:36:47 +00:00
|
|
|
$user->access_level = (int) clean($_REQUEST["access_level"]);
|
|
|
|
$user->email = clean($_REQUEST["email"]);
|
2021-03-12 19:26:24 +00:00
|
|
|
$user->otp_enabled = checkbox_to_sql_bool($_REQUEST["otp_enabled"] ?? "");
|
2021-02-14 13:44:41 +00:00
|
|
|
|
2021-03-05 14:40:17 +00:00
|
|
|
// force new OTP secret when next enabled
|
|
|
|
if (Config::get_schema_version() >= 143 && !$user->otp_enabled) {
|
|
|
|
$user->otp_secret = null;
|
|
|
|
}
|
|
|
|
|
2021-03-01 15:36:47 +00:00
|
|
|
$user->save();
|
|
|
|
}
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2021-03-01 12:24:18 +00:00
|
|
|
if ($password) {
|
2021-03-01 16:03:21 +00:00
|
|
|
UserHelper::reset_password($id, false, $password);
|
2021-03-01 12:24:18 +00:00
|
|
|
}
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove() {
|
2017-12-03 20:35:38 +00:00
|
|
|
$ids = explode(",", clean($_REQUEST["ids"]));
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
if ($id != $_SESSION["uid"] && $id != 1) {
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE owner_uid = ?");
|
|
|
|
$sth->execute([$id]);
|
|
|
|
|
|
|
|
$sth = $this->pdo->prepare("DELETE FROM ttrss_feeds WHERE owner_uid = ?");
|
|
|
|
$sth->execute([$id]);
|
|
|
|
|
|
|
|
$sth = $this->pdo->prepare("DELETE FROM ttrss_users WHERE id = ?");
|
|
|
|
$sth->execute([$id]);
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function add() {
|
2021-02-05 20:41:32 +00:00
|
|
|
$login = clean($_REQUEST["login"]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2018-12-02 13:17:36 +00:00
|
|
|
if (!$login) return; // no blank usernames
|
|
|
|
|
2021-02-11 07:22:27 +00:00
|
|
|
if (!UserHelper::find_user_by_login($login)) {
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2021-03-01 16:32:27 +00:00
|
|
|
$new_password = make_password();
|
2021-03-01 16:03:21 +00:00
|
|
|
|
2021-03-01 16:32:27 +00:00
|
|
|
$user = ORM::for_table('ttrss_users')->create();
|
2021-03-01 16:03:21 +00:00
|
|
|
|
2021-03-01 16:32:27 +00:00
|
|
|
$user->salt = UserHelper::get_salt();
|
|
|
|
$user->login = mb_strtolower($login);
|
|
|
|
$user->pwd_hash = UserHelper::hash_password($new_password, $user->salt);
|
2021-03-01 16:03:21 +00:00
|
|
|
$user->access_level = 0;
|
2021-03-01 20:07:20 +00:00
|
|
|
$user->created = Db::NOW();
|
2021-03-01 16:03:21 +00:00
|
|
|
$user->save();
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2021-11-01 20:33:46 +00:00
|
|
|
if (!is_null(UserHelper::find_user_by_login($login))) {
|
2018-12-02 13:17:36 +00:00
|
|
|
print T_sprintf("Added user %s with password %s",
|
2021-03-01 16:32:27 +00:00
|
|
|
$login, $new_password);
|
2011-12-13 10:00:36 +00:00
|
|
|
} else {
|
2018-12-02 13:17:36 +00:00
|
|
|
print T_sprintf("Could not create user %s", $login);
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-12-02 13:17:36 +00:00
|
|
|
print T_sprintf("User %s already exists.", $login);
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 10:50:02 +00:00
|
|
|
function resetPass() {
|
2021-02-15 13:59:54 +00:00
|
|
|
UserHelper::reset_password(clean($_REQUEST["id"]));
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
|
|
|
|
global $access_level_names;
|
|
|
|
|
2021-02-05 20:41:32 +00:00
|
|
|
$user_search = clean($_REQUEST["search"] ?? "");
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
if (array_key_exists("search", $_REQUEST)) {
|
|
|
|
$_SESSION["prefs_user_search"] = $user_search;
|
|
|
|
} else {
|
2021-02-06 13:13:11 +00:00
|
|
|
$user_search = ($_SESSION["prefs_user_search"] ?? "");
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
|
|
|
|
2021-02-05 20:41:32 +00:00
|
|
|
$sort = clean($_REQUEST["sort"] ?? "");
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
if (!$sort || $sort == "undefined") {
|
|
|
|
$sort = "login";
|
|
|
|
}
|
|
|
|
|
2021-03-01 15:36:47 +00:00
|
|
|
if (!in_array($sort, ["login", "access_level", "created", "num_feeds", "created", "last_login"]))
|
|
|
|
$sort = "login";
|
2017-12-03 10:54:03 +00:00
|
|
|
|
|
|
|
if ($sort != "login") $sort = "$sort DESC";
|
2021-02-14 11:59:22 +00:00
|
|
|
?>
|
|
|
|
|
|
|
|
<div dojoType='dijit.layout.BorderContainer' gutters='false'>
|
|
|
|
<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>
|
|
|
|
<div dojoType='fox.Toolbar'>
|
|
|
|
|
|
|
|
<div style='float : right'>
|
|
|
|
<input dojoType='dijit.form.TextBox' id='user_search' size='20' type='search'
|
|
|
|
value="<?= htmlspecialchars($user_search) ?>">
|
|
|
|
<button dojoType='dijit.form.Button' onclick='Users.reload()'>
|
|
|
|
<?= __('Search') ?>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div dojoType='fox.form.DropDownButton'>
|
|
|
|
<span><?= __('Select') ?></span>
|
|
|
|
<div dojoType='dijit.Menu' style='display: none'>
|
|
|
|
<div onclick="Tables.select('users-list', true)"
|
|
|
|
dojoType='dijit.MenuItem'><?= __('All') ?></div>
|
|
|
|
<div onclick="Tables.select('users-list', false)"
|
|
|
|
dojoType='dijit.MenuItem'><?= __('None') ?></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button dojoType='dijit.form.Button' onclick='Users.add()'>
|
|
|
|
<?= __('Create user') ?>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button dojoType='dijit.form.Button' onclick='Users.removeSelected()'>
|
|
|
|
<?= __('Remove') ?>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button dojoType='dijit.form.Button' onclick='Users.resetSelected()'>
|
|
|
|
<?= __('Reset password') ?>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefUsersToolbar") ?>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>
|
|
|
|
|
|
|
|
<table width='100%' class='users-list' id='users-list'>
|
|
|
|
|
2021-03-06 17:03:36 +00:00
|
|
|
<tr>
|
|
|
|
<th></th>
|
|
|
|
<th><a href='#' onclick="Users.reload('login')"><?= ('Login') ?></a></th>
|
|
|
|
<th><a href='#' onclick="Users.reload('access_level')"><?= ('Access Level') ?></a></th>
|
|
|
|
<th><a href='#' onclick="Users.reload('num_feeds')"><?= ('Subscribed feeds') ?></a></th>
|
|
|
|
<th><a href='#' onclick="Users.reload('created')"><?= ('Registered') ?></a></th>
|
|
|
|
<th><a href='#' onclick="Users.reload('last_login')"><?= ('Last login') ?></a></th>
|
2021-02-14 11:59:22 +00:00
|
|
|
</tr>
|
|
|
|
|
|
|
|
<?php
|
2021-03-01 15:36:47 +00:00
|
|
|
$users = ORM::for_table('ttrss_users')
|
|
|
|
->table_alias('u')
|
|
|
|
->left_outer_join("ttrss_feeds", ["owner_uid", "=", "u.id"], 'f')
|
|
|
|
->select_expr('u.*,COUNT(f.id) AS num_feeds')
|
|
|
|
->where_like("login", $user_search ? "%$user_search%" : "%")
|
|
|
|
->order_by_expr($sort)
|
|
|
|
->group_by_expr('u.id')
|
|
|
|
->find_many();
|
|
|
|
|
|
|
|
foreach ($users as $user) { ?>
|
|
|
|
|
|
|
|
<tr data-row-id='<?= $user["id"] ?>' onclick='Users.edit(<?= $user["id"] ?>)' title="<?= __('Click to edit') ?>">
|
2021-03-06 17:03:36 +00:00
|
|
|
<td class='checkbox'>
|
2021-02-14 11:59:22 +00:00
|
|
|
<input onclick='Tables.onRowChecked(this); event.stopPropagation();'
|
|
|
|
dojoType='dijit.form.CheckBox' type='checkbox'>
|
|
|
|
</td>
|
|
|
|
|
2021-03-06 17:03:36 +00:00
|
|
|
<td width='30%'>
|
|
|
|
<i class='material-icons'>person</i>
|
|
|
|
<strong><?= htmlspecialchars($user["login"]) ?></strong>
|
|
|
|
</td>
|
2021-03-01 15:36:47 +00:00
|
|
|
<td><?= $access_level_names[$user["access_level"]] ?></td>
|
|
|
|
<td><?= $user["num_feeds"] ?></td>
|
2021-03-06 17:03:36 +00:00
|
|
|
<td class='text-muted'><?= TimeHelper::make_local_datetime($user["created"], false) ?></td>
|
|
|
|
<td class='text-muted'><?= TimeHelper::make_local_datetime($user["last_login"], false) ?></td>
|
2021-02-14 11:59:22 +00:00
|
|
|
</tr>
|
|
|
|
<?php } ?>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
<?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefUsers") ?>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
2019-06-20 05:40:02 +00:00
|
|
|
|
|
|
|
}
|