diff --git a/clientarea/controllers/forget_password.php b/clientarea/controllers/forget_password.php index 90cb77b..9d5be89 100644 --- a/clientarea/controllers/forget_password.php +++ b/clientarea/controllers/forget_password.php @@ -32,20 +32,29 @@ if (isset($_POST["reset_request"])) { setMsg("errors", $errors); redirect("clientarea", "forget_password"); } else { - $code = md5(crypt(rand(), "aa")); - $stmt = $objDB->prepare( - "UPDATE users SET is_active = 0, reset_code=? WHERE email=?" - ); - $stmt->bind_param("ss", $code, $email); - if ($stmt->execute()) { + $reset_code = md5(crypt(rand(), "aa")); + $data = [ + "is_active" => 0, + "reset_code" => $reset_code, + ]; + $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"); - $message = "Hi! You requested password reset, . You need to click here to reset your password."; - echo $message; - send_mail([ + $message = "Hi! You requested password reset, . You need to click $reset_code]) . "'>here to reset your password."; + $msg_email = [ "to" => $email, "message" => $message, "subject" => "Reset Password Requested" - ]); + ]; + if (send_mail($msg_email)) { + $dbpdo->add("emails", [ + "date" => time(), + "subject" => "Reset Password Requested", + "body" => $message, + "user_id" => 1, + ]); + }; } else { setMsg("msg_notify", "reset password request, Please try again later.", "warning"); } diff --git a/data/demo.sql b/data/demo.sql index 8c133c9..625e1db 100644 --- a/data/demo.sql +++ b/data/demo.sql @@ -26,9 +26,9 @@ CREATE TABLE IF NOT EXISTS `emails`( `id` INT(11) NOT NULL AUTO_INCREMENT, `date` 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, - `is_active` TINYINT(4) NOT NULL, + `read` TINYINT(1) NOT NULL DEFAULT '0', PRIMARY KEY(`id`) ) ENGINE = MyISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT = 100;