This commit is contained in:
doudoudzj 2019-07-01 19:50:09 +08:00
parent 421d79cc5c
commit 73061adf62
2 changed files with 21 additions and 12 deletions

View file

@ -32,20 +32,29 @@ if (isset($_POST["reset_request"])) {
setMsg("errors", $errors); setMsg("errors", $errors);
redirect("clientarea", "forget_password"); redirect("clientarea", "forget_password");
} else { } else {
$code = md5(crypt(rand(), "aa")); $reset_code = md5(crypt(rand(), "aa"));
$stmt = $objDB->prepare( $data = [
"UPDATE users SET is_active = 0, reset_code=? WHERE email=?" "is_active" => 0,
); "reset_code" => $reset_code,
$stmt->bind_param("ss", $code, $email); ];
if ($stmt->execute()) { $res = $dbpdo->update("users", $data, "`email` = '$email'");
if ($res) {
$data = ["email" => $email];
setMsg("msg_notify", "You made a password request, please check email to reset your password.", "success"); setMsg("msg_notify", "You made a password request, please check email to reset your password.", "success");
$message = "Hi! You requested password reset, . You need to click here to <a href='" . setURL('clientarea', 'reset_password') . "&reset_code=$code'>reset your password.</a>"; $message = "Hi! You requested password reset, . You need to click <a href='" . setURL('clientarea', 'reset_password', ['reset_code' => $reset_code]) . "'>here</a> to reset your password.";
echo $message; $msg_email = [
send_mail([
"to" => $email, "to" => $email,
"message" => $message, "message" => $message,
"subject" => "Reset Password Requested" "subject" => "Reset Password Requested"
]); ];
if (send_mail($msg_email)) {
$dbpdo->add("emails", [
"date" => time(),
"subject" => "Reset Password Requested",
"body" => $message,
"user_id" => 1,
]);
};
} else { } else {
setMsg("msg_notify", "reset password request, Please try again later.", "warning"); setMsg("msg_notify", "reset password request, Please try again later.", "warning");
} }

View file

@ -26,9 +26,9 @@ CREATE TABLE IF NOT EXISTS `emails`(
`id` INT(11) NOT NULL AUTO_INCREMENT, `id` INT(11) NOT NULL AUTO_INCREMENT,
`date` VARCHAR(255) NOT NULL, `date` VARCHAR(255) NOT NULL,
`subject` VARCHAR(255) NOT NULL, `subject` VARCHAR(255) NOT NULL,
`body` VARCHAR(255) NOT NULL, `body` VARCHAR(5000) NOT NULL,
`user_id` INT(11) NOT NULL, `user_id` INT(11) NOT NULL,
`is_active` TINYINT(4) NOT NULL, `read` TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY(`id`) PRIMARY KEY(`id`)
) ENGINE = MyISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT = 100; ) ENGINE = MyISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT = 100;