2011-12-13 10:00:36 +00:00
|
|
|
<?php
|
2012-08-17 10:20:55 +00:00
|
|
|
class Pref_Users extends Handler_Protected {
|
2012-07-05 18:43:44 +00:00
|
|
|
function before($method) {
|
|
|
|
if (parent::before($method)) {
|
2011-12-13 10:00:36 +00:00
|
|
|
if ($_SESSION["access_level"] < 10) {
|
|
|
|
print __("Your access level is insufficient to open this tab.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-26 08:02:52 +00:00
|
|
|
function csrf_ignore($method) {
|
2013-06-11 08:11:02 +00:00
|
|
|
$csrf_ignored = array("index", "edit", "userdetails");
|
2011-12-26 08:02:52 +00:00
|
|
|
|
|
|
|
return array_search($method, $csrf_ignored) !== false;
|
|
|
|
}
|
|
|
|
|
2011-12-13 10:00:36 +00:00
|
|
|
function edit() {
|
|
|
|
global $access_level_names;
|
|
|
|
|
2019-02-23 05:01:29 +00:00
|
|
|
print "<form id='user_edit_form' onsubmit='return false' dojoType='dijit.form.Form'>";
|
2017-12-11 15:41:32 +00:00
|
|
|
|
2015-08-12 17:19:38 +00:00
|
|
|
print '<div dojoType="dijit.layout.TabContainer" style="height : 400px">
|
|
|
|
<div dojoType="dijit.layout.ContentPane" title="'.__('Edit user').'">';
|
|
|
|
|
2017-12-11 15:41:32 +00:00
|
|
|
//print "<form id=\"user_edit_form\" onsubmit='return false' dojoType=\"dijit.form.Form\">";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-03 20:35:38 +00:00
|
|
|
$id = (int) clean($_REQUEST["id"]);
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-02-10 11:36:21 +00:00
|
|
|
print_hidden("id", "$id");
|
|
|
|
print_hidden("op", "pref-users");
|
|
|
|
print_hidden("method", "editSave");
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT * FROM ttrss_users WHERE id = ?");
|
|
|
|
$sth->execute([$id]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
if ($row = $sth->fetch()) {
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$login = $row["login"];
|
|
|
|
$access_level = $row["access_level"];
|
|
|
|
$email = $row["email"];
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sel_disabled = ($id == $_SESSION["uid"] || $login == "admin") ? "disabled" : "";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "<header>".__("User")."</header>";
|
|
|
|
print "<section>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
if ($sel_disabled) {
|
|
|
|
print_hidden("login", "$login");
|
|
|
|
}
|
2013-06-11 08:04:29 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "<fieldset>";
|
|
|
|
print "<label>" . __("Login:") . "</label>";
|
|
|
|
print "<input style='font-size : 16px'
|
|
|
|
dojoType='dijit.form.ValidationTextBox' required='1'
|
2019-02-23 05:01:29 +00:00
|
|
|
$sel_disabled name='login' value=\"$login\">";
|
2019-02-22 07:48:56 +00:00
|
|
|
print "</fieldset>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "</section>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "<header>".__("Authentication")."</header>";
|
|
|
|
print "<section>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-20 11:37:59 +00:00
|
|
|
print "<fieldset>";
|
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "<label>" . __('Access level: ') . "</label> ";
|
2017-12-02 09:23:41 +00:00
|
|
|
|
|
|
|
if (!$sel_disabled) {
|
|
|
|
print_select_hash("access_level", $access_level, $access_level_names,
|
2019-04-13 20:36:15 +00:00
|
|
|
"dojoType=\"fox.form.Select\" $sel_disabled");
|
2017-12-02 09:23:41 +00:00
|
|
|
} else {
|
|
|
|
print_select_hash("", $access_level, $access_level_names,
|
2019-04-13 20:36:15 +00:00
|
|
|
"dojoType=\"fox.form.Select\" $sel_disabled");
|
2017-12-02 09:23:41 +00:00
|
|
|
print_hidden("access_level", "$access_level");
|
|
|
|
}
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-20 11:37:59 +00:00
|
|
|
print "</fieldset>";
|
|
|
|
print "<fieldset>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "<label>" . __("New password:") . "</label> ";
|
|
|
|
print "<input dojoType='dijit.form.TextBox' type='password' size='20' placeholder='Change password'
|
2019-02-23 05:01:29 +00:00
|
|
|
name='password'>";
|
2019-02-20 11:37:59 +00:00
|
|
|
|
|
|
|
print "</fieldset>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "</section>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "<header>".__("Options")."</header>";
|
|
|
|
print "<section>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "<fieldset>";
|
|
|
|
print "<label>" . __("E-mail:") . "</label> ";
|
|
|
|
print "<input dojoType='dijit.form.TextBox' size='30' name='email'
|
|
|
|
value=\"$email\">";
|
|
|
|
print "</fieldset>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "</section>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
print "</table>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
}
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2015-08-12 17:19:38 +00:00
|
|
|
print '</div>'; #tab
|
|
|
|
print "<div href=\"backend.php?op=pref-users&method=userdetails&id=$id\"
|
|
|
|
dojoType=\"dijit.layout.ContentPane\" title=\"".__('User details')."\">";
|
|
|
|
|
|
|
|
print '</div>';
|
|
|
|
print '</div>';
|
|
|
|
|
2019-02-22 07:48:56 +00:00
|
|
|
print "<footer>
|
2019-02-23 05:01:29 +00:00
|
|
|
<button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick=\"dijit.byId('userEditDlg').execute()\">".
|
2015-08-12 17:19:38 +00:00
|
|
|
__('Save')."</button>
|
2019-02-23 05:01:29 +00:00
|
|
|
<button dojoType='dijit.form.Button' onclick=\"dijit.byId('userEditDlg').hide()\">".
|
2019-02-22 07:48:56 +00:00
|
|
|
__('Cancel')."</button>
|
|
|
|
</footer>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-11 15:41:32 +00:00
|
|
|
print "</form>";
|
|
|
|
|
2011-12-13 10:00:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
print "<table width='100%'>";
|
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
|
|
|
print "<tr><td>".__('Registered')."</td><td>$created</td></tr>";
|
|
|
|
print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>";
|
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();
|
|
|
|
$num_feeds = $row["num_feeds"];
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>";
|
|
|
|
print "<tr><td>".__('Stored articles')."</td><td>$stored_articles</td></tr>";
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
print "</table>";
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
print "<h1>".__('Subscribed feeds')."</h1>";
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT id,title,site_url FROM ttrss_feeds
|
|
|
|
WHERE owner_uid = ? ORDER BY title");
|
|
|
|
$sth->execute([$id]);
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2018-12-07 11:03:33 +00:00
|
|
|
print "<ul class=\"panel panel-scrollable list list-unstyled\">";
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
while ($line = $sth->fetch()) {
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$icon_file = ICONS_URL."/".$line["id"].".ico";
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
if (file_exists($icon_file) && filesize($icon_file) > 0) {
|
2018-12-05 17:26:27 +00:00
|
|
|
$feed_icon = "<img class=\"icon\" src=\"$icon_file\">";
|
2017-12-02 09:23:41 +00:00
|
|
|
} else {
|
2018-12-05 17:26:27 +00:00
|
|
|
$feed_icon = "<img class=\"icon\" src=\"images/blank_icon.gif\">";
|
2017-12-02 09:23:41 +00:00
|
|
|
}
|
2015-08-12 17:19:38 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
|
2015-08-12 17:19:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
print "</ul>";
|
2018-11-03 12:08:43 +00:00
|
|
|
|
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
} else {
|
|
|
|
print "<h1>".__('User not found')."</h1>";
|
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-02-05 20:41:32 +00:00
|
|
|
$login = clean($_REQUEST["login"]);
|
2017-12-03 20:35:38 +00:00
|
|
|
$uid = clean($_REQUEST["id"]);
|
|
|
|
$access_level = (int) clean($_REQUEST["access_level"]);
|
2021-02-05 20:41:32 +00:00
|
|
|
$email = clean($_REQUEST["email"]);
|
2017-12-03 20:35:38 +00:00
|
|
|
$password = clean($_REQUEST["password"]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
if ($password) {
|
2012-01-23 18:04:01 +00:00
|
|
|
$salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
|
2012-01-23 08:20:09 +00:00
|
|
|
$pwd_hash = encrypt_password($password, $salt, true);
|
2018-11-03 12:08:43 +00:00
|
|
|
$pass_query_part = "pwd_hash = ".$this->pdo->quote($pwd_hash).",
|
2017-12-02 09:23:41 +00:00
|
|
|
salt = ".$this->pdo->quote($salt).",";
|
2011-12-13 10:00:36 +00:00
|
|
|
} else {
|
|
|
|
$pass_query_part = "";
|
|
|
|
}
|
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_users SET $pass_query_part login = ?,
|
|
|
|
access_level = ?, email = ?, otp_enabled = false WHERE id = ?");
|
|
|
|
$sth->execute([$login, $access_level, $email, $uid]);
|
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"]);
|
2019-03-05 17:16:50 +00:00
|
|
|
$tmp_user_pwd = make_password();
|
2012-01-23 18:04:01 +00:00
|
|
|
$salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
|
2012-01-23 08:20:09 +00:00
|
|
|
$pwd_hash = encrypt_password($tmp_user_pwd, $salt, true);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2018-12-02 13:17:36 +00:00
|
|
|
if (!$login) return; // no blank usernames
|
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE
|
|
|
|
login = ?");
|
|
|
|
$sth->execute([$login]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
if (!$sth->fetch()) {
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("INSERT INTO ttrss_users
|
2012-01-23 08:20:09 +00:00
|
|
|
(login,pwd_hash,access_level,last_login,created, salt)
|
2017-12-02 09:23:41 +00:00
|
|
|
VALUES (?, ?, 0, null, NOW(), ?)");
|
|
|
|
$sth->execute([$login, $pwd_hash, $salt]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE
|
|
|
|
login = ? AND pwd_hash = ?");
|
|
|
|
$sth->execute([$login, $pwd_hash]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
if ($row = $sth->fetch()) {
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$new_uid = $row['id'];
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2018-12-02 13:17:36 +00:00
|
|
|
print T_sprintf("Added user %s with password %s",
|
|
|
|
$login, $tmp_user_pwd);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2020-09-22 06:04:33 +00:00
|
|
|
$this->initialize_user($new_uid);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 17:09:06 +00:00
|
|
|
static function resetUserPassword($uid, $format_output = false) {
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$pdo = Db::pdo();
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-03-05 17:09:06 +00:00
|
|
|
$sth = $pdo->prepare("SELECT login FROM ttrss_users WHERE id = ?");
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth->execute([$uid]);
|
2018-11-03 12:08:43 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
if ($row = $sth->fetch()) {
|
2012-01-23 08:20:09 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$login = $row["login"];
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
|
2019-03-05 17:16:50 +00:00
|
|
|
$tmp_user_pwd = make_password();
|
2012-01-23 08:20:09 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2018-11-03 12:08:43 +00:00
|
|
|
$sth = $pdo->prepare("UPDATE ttrss_users
|
2017-12-02 09:23:41 +00:00
|
|
|
SET pwd_hash = ?, salt = ?, otp_enabled = false
|
|
|
|
WHERE id = ?");
|
|
|
|
$sth->execute([$pwd_hash, $new_salt, $uid]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-03-05 17:09:06 +00:00
|
|
|
$message = T_sprintf("Changed password of user %s to %s", "<strong>$login</strong>", "<strong>$tmp_user_pwd</strong>");
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-03-05 17:09:06 +00:00
|
|
|
if ($format_output)
|
|
|
|
print_notice($message);
|
|
|
|
else
|
|
|
|
print $message;
|
2018-11-03 12:08:43 +00:00
|
|
|
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
2013-03-22 10:50:02 +00:00
|
|
|
}
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2013-03-22 10:50:02 +00:00
|
|
|
function resetPass() {
|
2017-12-03 20:35:38 +00:00
|
|
|
$uid = clean($_REQUEST["id"]);
|
2020-09-22 11:54:15 +00:00
|
|
|
self::resetUserPassword($uid);
|
2011-12-13 10:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
|
|
|
|
global $access_level_names;
|
|
|
|
|
2018-12-07 11:03:33 +00:00
|
|
|
print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>";
|
|
|
|
print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>";
|
2019-04-07 10:21:52 +00:00
|
|
|
print "<div dojoType='fox.Toolbar'>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
print "<div style='float : right; padding-right : 4px;'>
|
2019-02-23 05:01:29 +00:00
|
|
|
<input dojoType='dijit.form.TextBox' id='user_search' size='20' type='search'
|
2011-12-13 10:00:36 +00:00
|
|
|
value=\"$user_search\">
|
2019-02-23 05:01:29 +00:00
|
|
|
<button dojoType='dijit.form.Button' onclick='Users.reload()'>".
|
2011-12-13 10:00:36 +00:00
|
|
|
__('Search')."</button>
|
|
|
|
</div>";
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2019-04-13 20:36:15 +00:00
|
|
|
print "<div dojoType='fox.form.DropDownButton'>".
|
2011-12-13 10:00:36 +00:00
|
|
|
"<span>" . __('Select')."</span>";
|
2019-02-23 05:01:29 +00:00
|
|
|
print "<div dojoType='dijit.Menu' style='display: none'>";
|
2021-02-06 13:24:40 +00:00
|
|
|
print "<div onclick=\"Tables.select('users-list', true)\"
|
2019-02-23 05:01:29 +00:00
|
|
|
dojoType='dijit.MenuItem'>".__('All')."</div>";
|
2021-02-06 13:24:40 +00:00
|
|
|
print "<div onclick=\"Tables.select('users-list', false)\"
|
2019-02-23 05:01:29 +00:00
|
|
|
dojoType='dijit.MenuItem'>".__('None')."</div>";
|
2011-12-13 10:00:36 +00:00
|
|
|
print "</div></div>";
|
|
|
|
|
2019-02-23 05:01:29 +00:00
|
|
|
print "<button dojoType='dijit.form.Button' onclick='Users.add()'>".__('Create user')."</button>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
print "
|
2019-02-23 05:01:29 +00:00
|
|
|
<button dojoType='dijit.form.Button' onclick='Users.editSelected()'>".
|
2011-12-13 10:00:36 +00:00
|
|
|
__('Edit')."</button dojoType=\"dijit.form.Button\">
|
2019-02-23 05:01:29 +00:00
|
|
|
<button dojoType='dijit.form.Button' onclick='Users.removeSelected()'>".
|
2011-12-13 10:00:36 +00:00
|
|
|
__('Remove')."</button dojoType=\"dijit.form.Button\">
|
2019-02-23 05:01:29 +00:00
|
|
|
<button dojoType='dijit.form.Button' onclick='Users.resetSelected()'>".
|
2011-12-13 10:00:36 +00:00
|
|
|
__('Reset password')."</button dojoType=\"dijit.form.Button\">";
|
|
|
|
|
2013-05-22 08:02:43 +00:00
|
|
|
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
|
|
|
|
"hook_prefs_tab_section", "prefUsersToolbar");
|
|
|
|
|
2011-12-13 10:00:36 +00:00
|
|
|
print "</div>"; #toolbar
|
|
|
|
print "</div>"; #pane
|
2018-12-07 11:03:33 +00:00
|
|
|
print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-06-20 05:40:02 +00:00
|
|
|
$sort = $this->validate_field($sort,
|
2017-12-03 10:54:03 +00:00
|
|
|
["login", "access_level", "created", "num_feeds", "created", "last_login"], "login");
|
|
|
|
|
|
|
|
if ($sort != "login") $sort = "$sort DESC";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT
|
2015-08-12 13:01:47 +00:00
|
|
|
tu.id,
|
|
|
|
login,access_level,email,
|
2011-12-13 10:00:36 +00:00
|
|
|
".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login,
|
2015-08-12 13:01:47 +00:00
|
|
|
".SUBSTRING_FOR_DATE."(created,1,16) as created,
|
2015-08-12 15:24:16 +00:00
|
|
|
(SELECT COUNT(id) FROM ttrss_feeds WHERE owner_uid = tu.id) AS num_feeds
|
2011-12-13 10:00:36 +00:00
|
|
|
FROM
|
2015-08-12 13:01:47 +00:00
|
|
|
ttrss_users tu
|
2011-12-13 10:00:36 +00:00
|
|
|
WHERE
|
2017-12-02 09:23:41 +00:00
|
|
|
(:search = '' OR login LIKE :search) AND tu.id > 0
|
2017-12-03 10:54:03 +00:00
|
|
|
ORDER BY $sort");
|
|
|
|
$sth->execute([":search" => $user_search ? "%$user_search%" : ""]);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2021-02-06 13:24:40 +00:00
|
|
|
print "<table width='100%' class='users-list' id='users-list'>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2019-02-23 05:01:29 +00:00
|
|
|
print "<tr class='title'>
|
|
|
|
<td align='center' width='5%'> </td>
|
|
|
|
<td width='20%'><a href='#' onclick=\"Users.reload('login')\">".__('Login')."</a></td>
|
|
|
|
<td width='20%'><a href='#' onclick=\"Users.reload('access_level')\">".__('Access Level')."</a></td>
|
|
|
|
<td width='10%'><a href='#' onclick=\"Users.reload('num_feeds')\">".__('Subscribed feeds')."</a></td>
|
|
|
|
<td width='20%'><a href='#' onclick=\"Users.reload('created')\">".__('Registered')."</a></td>
|
|
|
|
<td width='20%'><a href='#' onclick=\"Users.reload('last_login')\">".__('Last login')."</a></td></tr>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
$lnum = 0;
|
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
while ($line = $sth->fetch()) {
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
$uid = $line["id"];
|
|
|
|
|
2019-02-23 05:01:29 +00:00
|
|
|
print "<tr data-row-id='$uid' onclick='Users.edit($uid)'>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
$line["login"] = htmlspecialchars($line["login"]);
|
2020-09-23 10:04:26 +00:00
|
|
|
$line["created"] = TimeHelper::make_local_datetime($line["created"], false);
|
|
|
|
$line["last_login"] = TimeHelper::make_local_datetime($line["last_login"], false);
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2018-12-02 13:17:36 +00:00
|
|
|
print "<td align='center'><input onclick='Tables.onRowChecked(this); event.stopPropagation();'
|
2019-02-23 05:01:29 +00:00
|
|
|
dojoType='dijit.form.CheckBox' type='checkbox'></td>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2018-12-05 18:40:46 +00:00
|
|
|
print "<td title='".__('Click to edit')."'><i class='material-icons'>person</i> " . $line["login"] . "</td>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
2018-12-02 13:17:36 +00:00
|
|
|
print "<td>" . $access_level_names[$line["access_level"]] . "</td>";
|
|
|
|
print "<td>" . $line["num_feeds"] . "</td>";
|
|
|
|
print "<td>" . $line["created"] . "</td>";
|
|
|
|
print "<td>" . $line["last_login"] . "</td>";
|
2011-12-13 10:00:36 +00:00
|
|
|
|
|
|
|
print "</tr>";
|
|
|
|
|
|
|
|
++$lnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
print "</table>";
|
|
|
|
|
2017-12-02 09:23:41 +00:00
|
|
|
if ($lnum == 0) {
|
2011-12-13 10:00:36 +00:00
|
|
|
if (!$user_search) {
|
|
|
|
print_warning(__('No users defined.'));
|
|
|
|
} else {
|
|
|
|
print_warning(__('No matching users found.'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print "</div>"; #pane
|
2012-12-23 12:15:34 +00:00
|
|
|
|
2013-04-18 08:27:34 +00:00
|
|
|
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
|
2012-12-23 12:15:34 +00:00
|
|
|
"hook_prefs_tab", "prefUsers");
|
|
|
|
|
2011-12-13 10:00:36 +00:00
|
|
|
print "</div>"; #container
|
|
|
|
|
|
|
|
}
|
2019-06-20 05:40:02 +00:00
|
|
|
|
|
|
|
function validate_field($string, $allowed, $default = "") {
|
|
|
|
if (in_array($string, $allowed))
|
|
|
|
return $string;
|
|
|
|
else
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
2020-09-22 06:04:33 +00:00
|
|
|
// this is called after user is created to initialize default feeds, labels
|
|
|
|
// or whatever else
|
|
|
|
// user preferences are checked on every login, not here
|
|
|
|
static function initialize_user($uid) {
|
|
|
|
|
|
|
|
$pdo = Db::pdo();
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("insert into ttrss_feeds (owner_uid,title,feed_url)
|
|
|
|
values (?, 'Tiny Tiny RSS: Forum',
|
|
|
|
'https://tt-rss.org/forum/rss.php')");
|
|
|
|
$sth->execute([$uid]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function logout_user() {
|
2021-02-05 21:12:15 +00:00
|
|
|
if (session_status() === PHP_SESSION_ACTIVE)
|
|
|
|
session_destroy();
|
|
|
|
|
2020-09-22 06:04:33 +00:00
|
|
|
if (isset($_COOKIE[session_name()])) {
|
|
|
|
setcookie(session_name(), '', time()-42000, '/');
|
2021-02-05 21:12:15 +00:00
|
|
|
|
2020-09-22 06:04:33 +00:00
|
|
|
}
|
|
|
|
session_commit();
|
|
|
|
}
|
|
|
|
|
2019-06-20 05:40:02 +00:00
|
|
|
}
|