From 2547ece0cacb7080060ad3bc32b879fee6b52230 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 14:59:22 +0300 Subject: pref-users: cleanup index --- classes/pref/users.php | 214 +++++++++++++++++++++---------------------------- 1 file changed, 93 insertions(+), 121 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index 5c622a9b1..0454a1292 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -251,12 +251,8 @@ class Pref_Users extends Handler_Protected { print T_sprintf("Added user %s with password %s", $login, $tmp_user_pwd); - $this->initialize_user($new_uid); - } else { - print T_sprintf("Could not create user %s", $login); - } } else { print T_sprintf("User %s already exists.", $login); @@ -303,10 +299,6 @@ class Pref_Users extends Handler_Protected { global $access_level_names; - print "
"; - print "
"; - print "
"; - $user_search = clean($_REQUEST["search"] ?? ""); if (array_key_exists("search", $_REQUEST)) { @@ -315,137 +307,117 @@ class Pref_Users extends Handler_Protected { $user_search = ($_SESSION["prefs_user_search"] ?? ""); } - print "
- - -
"; - $sort = clean($_REQUEST["sort"] ?? ""); if (!$sort || $sort == "undefined") { $sort = "login"; } - print "
". - "" . __('Select').""; - print "
"; - print "
".__('All')."
"; - print "
".__('None')."
"; - print "
"; - - print ""; - - print " - - - "; - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefUsersToolbar"); - - print "
"; #toolbar - print "
"; #pane - print "
"; - $sort = $this->validate_field($sort, ["login", "access_level", "created", "num_feeds", "created", "last_login"], "login"); if ($sort != "login") $sort = "$sort DESC"; - $sth = $this->pdo->prepare("SELECT - tu.id, - login,access_level,email, - ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login, - ".SUBSTRING_FOR_DATE."(created,1,16) as created, - (SELECT COUNT(id) FROM ttrss_feeds WHERE owner_uid = tu.id) AS num_feeds - FROM - ttrss_users tu - WHERE - (:search = '' OR login LIKE :search) AND tu.id > 0 - ORDER BY $sort"); - $sth->execute([":search" => $user_search ? "%$user_search%" : ""]); - - print ""; - - print " - - - - - - "; - - $lnum = 0; - - while ($line = $sth->fetch()) { - - $uid = $line["id"]; - - print ""; - - $line["login"] = htmlspecialchars($line["login"]); - $line["created"] = TimeHelper::make_local_datetime($line["created"], false); - $line["last_login"] = TimeHelper::make_local_datetime($line["last_login"], false); - - print ""; - - print ""; - - print ""; - print ""; - print ""; - print ""; - - print ""; - - ++$lnum; - } - - print "
 ".__('Login')."".__('Access Level')."".__('Subscribed feeds')."".__('Registered')."".__('Last login')."
person " . $line["login"] . "" . $access_level_names[$line["access_level"]] . "" . $line["num_feeds"] . "" . $line["created"] . "" . $line["last_login"] . "
"; - - if ($lnum == 0) { - if (!$user_search) { - print_warning(__('No users defined.')); - } else { - print_warning(__('No matching users found.')); - } - } - - print "
"; #pane - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefUsers"); - - print "
"; #container - - } + ?> + +
+
+
+ +
+ + +
+ +
+ +
+
+
+
+
+ + + + + + + + + + run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefUsersToolbar") ?> + +
+
+
+ + + + + + + + + + + + + pdo->prepare("SELECT + tu.id, + login,access_level,email, + ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login, + ".SUBSTRING_FOR_DATE."(created,1,16) as created, + (SELECT COUNT(id) FROM ttrss_feeds WHERE owner_uid = tu.id) AS num_feeds + FROM + ttrss_users tu + WHERE + (:search = '' OR login LIKE :search) AND tu.id > 0 + ORDER BY $sort"); + $sth->execute([":search" => $user_search ? "%$user_search%" : ""]); + + while ($row = $sth->fetch()) { ?> + + + + + + + + + + + +
+ + person
+
+ run_hooks(PluginHost::HOOK_PREFS_TAB, "prefUsers") ?> +
+ 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() { if (session_status() === PHP_SESSION_ACTIVE) session_destroy(); -- cgit v1.2.3 From a8cc43a0ff1cf6297577fae8536408287518baf4 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 15:31:03 +0300 Subject: move logout_user() to UserHelper --- classes/pref/users.php | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index 0454a1292..24d28e62a 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -418,15 +418,4 @@ class Pref_Users extends Handler_Protected { return $default; } - static function logout_user() { - if (session_status() === PHP_SESSION_ACTIVE) - session_destroy(); - - if (isset($_COOKIE[session_name()])) { - setcookie(session_name(), '', time()-42000, '/'); - - } - session_commit(); - } - } -- cgit v1.2.3 From 0fbf10991237b3f91ee5c77349637d7197a22bdc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 15:38:45 +0300 Subject: * remove users/filters toolbar edit button (just click on it) * fix title of edit filter dialog always showing create filter --- classes/pref/users.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index 24d28e62a..7adb09ab2 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -346,10 +346,6 @@ class Pref_Users extends Handler_Protected { - - -- cgit v1.2.3 From 33ea46c2bc5c91d7767f11c230a941cc635c0e67 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 15:42:12 +0300 Subject: pref-users/add: remove unused variable --- classes/pref/users.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index 7adb09ab2..9d9ea4d8e 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -246,8 +246,6 @@ class Pref_Users extends Handler_Protected { if ($new_uid = UserHelper::find_user_by_login($login)) { - $new_uid = $row['id']; - print T_sprintf("Added user %s with password %s", $login, $tmp_user_pwd); -- cgit v1.2.3 From 0b7377238a556708035b0cd51a9e58693fb648f6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 15:50:46 +0300 Subject: add Handler_Administrative --- classes/pref/users.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index 9d9ea4d8e..b34f85d88 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -1,16 +1,5 @@ Date: Sun, 14 Feb 2021 16:44:41 +0300 Subject: pref-users edit: use client dialog --- classes/pref/users.php | 112 +++++++------------------------------------------ 1 file changed, 16 insertions(+), 96 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index b34f85d88..bc125d0ce 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -1,7 +1,7 @@ "; + $id = (int)clean($_REQUEST["id"]); - print '
-
'; - - //print "
"; - - $id = (int) clean($_REQUEST["id"]); - - print_hidden("id", "$id"); - print_hidden("op", "pref-users"); - print_hidden("method", "editSave"); - - $sth = $this->pdo->prepare("SELECT * FROM ttrss_users WHERE id = ?"); + $sth = $this->pdo->prepare("SELECT id, login, access_level, email FROM ttrss_users WHERE id = ?"); $sth->execute([$id]); - if ($row = $sth->fetch()) { - - $login = $row["login"]; - $access_level = $row["access_level"]; - $email = $row["email"]; - - $sel_disabled = ($id == $_SESSION["uid"] || $login == "admin") ? "disabled" : ""; - - print "
".__("User")."
"; - print "
"; - - if ($sel_disabled) { - print_hidden("login", "$login"); - } - - print "
"; - print ""; - print ""; - print "
"; - - print "
"; - - print "
".__("Authentication")."
"; - print "
"; - - print "
"; - - print " "; - - if (!$sel_disabled) { - print_select_hash("access_level", $access_level, $access_level_names, - "dojoType=\"fox.form.Select\" $sel_disabled"); - } else { - print_select_hash("", $access_level, $access_level_names, - "dojoType=\"fox.form.Select\" $sel_disabled"); - print_hidden("access_level", "$access_level"); - } - - print "
"; - print "
"; - - print " "; - print ""; - - print "
"; - - print "
"; - - print "
".__("Options")."
"; - print "
"; - - print "
"; - print " "; - print ""; - print "
"; - - print "
"; - - print ""; - + if ($row = $sth->fetch(PDO::FETCH_ASSOC)) { + print json_encode([ + "user" => $row, + "access_level_names" => $access_level_names + ]); + } else { + print json_encode(["error" => "USER_NOT_FOUND"]); } - - print '
'; #tab - print "
"; - - print '
'; - print '
'; - - print "
- - -
"; - - print ""; - - return; } function userdetails() { @@ -186,6 +100,12 @@ class Pref_Users extends Handler_Administrative { $email = clean($_REQUEST["email"]); $password = clean($_REQUEST["password"]); + // no blank usernames + if (!$login) return; + + // forbid renaming admin + if ($uid == 1) $login = "admin"; + if ($password) { $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); $pwd_hash = encrypt_password($password, $salt, true); -- cgit v1.2.3 From 8e79f1717d5270558ffd30c20cc75840b0ecc955 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Feb 2021 16:07:22 +0300 Subject: prefs: unify naming --- classes/pref/users.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index bc125d0ce..d2dd06fd8 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -166,7 +166,7 @@ class Pref_Users extends Handler_Administrative { } } - static function resetUserPassword($uid, $format_output = false) { + static function _reset_password($uid, $format_output = false) { $pdo = Db::pdo(); @@ -199,7 +199,7 @@ class Pref_Users extends Handler_Administrative { function resetPass() { $uid = clean($_REQUEST["id"]); - self::resetUserPassword($uid); + self::_reset_password($uid); } function index() { @@ -220,7 +220,7 @@ class Pref_Users extends Handler_Administrative { $sort = "login"; } - $sort = $this->validate_field($sort, + $sort = $this->_validate_field($sort, ["login", "access_level", "created", "num_feeds", "created", "last_login"], "login"); if ($sort != "login") $sort = "$sort DESC"; @@ -314,7 +314,7 @@ class Pref_Users extends Handler_Administrative { Date: Mon, 15 Feb 2021 16:59:54 +0300 Subject: move reset_password to UserHelper --- classes/pref/users.php | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index d2dd06fd8..ab1694564 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -166,40 +166,8 @@ class Pref_Users extends Handler_Administrative { } } - static function _reset_password($uid, $format_output = false) { - - $pdo = Db::pdo(); - - $sth = $pdo->prepare("SELECT login FROM ttrss_users WHERE id = ?"); - $sth->execute([$uid]); - - if ($row = $sth->fetch()) { - - $login = $row["login"]; - - $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); - $tmp_user_pwd = make_password(); - - $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true); - - $sth = $pdo->prepare("UPDATE ttrss_users - SET pwd_hash = ?, salt = ?, otp_enabled = false - WHERE id = ?"); - $sth->execute([$pwd_hash, $new_salt, $uid]); - - $message = T_sprintf("Changed password of user %s to %s", "$login", "$tmp_user_pwd"); - - if ($format_output) - print_notice($message); - else - print $message; - - } - } - function resetPass() { - $uid = clean($_REQUEST["id"]); - self::_reset_password($uid); + UserHelper::reset_password(clean($_REQUEST["id"])); } function index() { -- cgit v1.2.3 From 75435aa960997fb4aa7a13c1a084ab3c53111e73 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 18 Feb 2021 13:00:20 +0300 Subject: user details: cleanup --- classes/pref/users.php | 64 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index ab1694564..5ac6a7990 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -38,7 +38,6 @@ class Pref_Users extends Handler_Administrative { $sth->execute([$id]); if ($row = $sth->fetch()) { - print ""; $last_login = TimeHelper::make_local_datetime( $row["last_login"], true); @@ -48,47 +47,62 @@ class Pref_Users extends Handler_Administrative { $stored_articles = $row["stored_articles"]; - print ""; - print ""; - $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"]; - print ""; - print ""; + $num_feeds = $row["num_feeds"]; - print "
".__('Registered')."$created
".__('Last logged in')."$last_login
".__('Subscribed feeds count')."$num_feeds
".__('Stored articles')."$stored_articles
"; + ?> - print "

".__('Subscribed feeds')."

"; +
+ + +
- $sth = $this->pdo->prepare("SELECT id,title,site_url FROM ttrss_feeds - WHERE owner_uid = ? ORDER BY title"); - $sth->execute([$id]); +
+ + +
- print "
    "; +
    + + +
    - while ($line = $sth->fetch()) { +
    + + +
    - $icon_file = ICONS_URL."/".$line["id"].".ico"; - - if (file_exists($icon_file) && filesize($icon_file) > 0) { - $feed_icon = ""; - } else { - $feed_icon = ""; - } + pdo->prepare("SELECT id,title,site_url FROM ttrss_feeds + WHERE owner_uid = ? ORDER BY title"); + $sth->execute([$id]); + ?> - print "
  • $feed_icon ".$line["title"]."
  • "; +
      + fetch()) { ?> +
    • + - } + - print "
    "; + "> + + + + +
+ ".__('User not found').""; + print_error(__('User not found')); } } -- cgit v1.2.3 From 211f699aa0c4211e4ee8a02446d51b9811d0c28c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Feb 2021 22:35:27 +0300 Subject: migrate the rest into Config:: --- classes/pref/users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index 5ac6a7990..f30abe001 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -86,7 +86,7 @@ class Pref_Users extends Handler_Administrative { fetch()) { ?>
  • -- cgit v1.2.3 From 8d2e3c2528e67f8650c122f014364a34bf690d2a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 23 Feb 2021 22:26:07 +0300 Subject: drop errors.php and simplify error handling --- classes/pref/users.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'classes/pref/users.php') diff --git a/classes/pref/users.php b/classes/pref/users.php index f30abe001..13f808cb3 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -19,8 +19,6 @@ class Pref_Users extends Handler_Administrative { "user" => $row, "access_level_names" => $access_level_names ]); - } else { - print json_encode(["error" => "USER_NOT_FOUND"]); } } -- cgit v1.2.3