move reset_password to UserHelper
This commit is contained in:
parent
5d42ce553f
commit
39604bedef
|
@ -950,7 +950,7 @@ class Handler_Public extends Handler {
|
|||
WHERE id = ?");
|
||||
$sth->execute([$id]);
|
||||
|
||||
Pref_Users::_reset_password($id, true);
|
||||
UserHelper::reset_password($id, true);
|
||||
|
||||
print "<p>"."Completed."."</p>";
|
||||
|
||||
|
|
|
@ -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", "<strong>$login</strong>", "<strong>$tmp_user_pwd</strong>");
|
||||
|
||||
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() {
|
||||
|
|
|
@ -169,4 +169,34 @@ class UserHelper {
|
|||
session_commit();
|
||||
}
|
||||
|
||||
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", "<strong>$login</strong>", "<strong>$tmp_user_pwd</strong>");
|
||||
|
||||
if ($format_output)
|
||||
print_notice($message);
|
||||
else
|
||||
print $message;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue