public function req_pass() { $errors = array(); $token = uniqid() . '&' . (time() + 3600); $mail = new \CODOF\Forum\Notification\Mail(); //update the user's password with the generated password $user = \CODOF\User\User::getByMailOrUsername($_GET['ident'], $_GET['ident']); $gen = false; if (!$user) { $errors[] = _t("User does not exist with the given username/mail"); } else { $old_token = $user->token; if ($old_token != null) { $parts = explode("&", $old_token); $expiry = (int) $parts[1]; if ($expiry > time()) { $gen = true; } } else { $gen = true; } } if (empty($errors) && $gen) { \DB::table(PREFIX . 'codo_users')->where('id', $user->id)->update(array('token' => $token)); $body = \CODOF\Util::get_opt('password_reset_message'); $sub = \CODOF\Util::get_opt('password_reset_subject'); $mail->user = array("token" => $token, "link" => RURI . 'user/reset'); $message = $mail->replace_tokens($body); $subject = $mail->replace_tokens($sub); $mail->to = $user->mail; $mail->subject = $subject; $mail->message = $message; $mail->send_mail(); if (!$mail->sent) { $errors[] = $mail->error; } } $resp = array("status" => "success", "msg" => _t("E-mail sent successfully")); if (!empty($errors)) { $resp = array("status" => "fail", "msg" => $errors); } echo json_encode($resp); }