/** * @brief 邮箱找回密码进行 */ function find_password_email() { $username = IReq::get('username'); if ($username === null || !Util::is_username($username)) { IError::show(403, "请输入正确的用户名"); } $email = IReq::get("email"); if ($email === null || !IValidate::email($email)) { IError::show(403, "请输入正确的邮箱地址"); } $tb_user = new IModel("user"); $username = IFilter::act($username); $email = IFilter::act($email); $user = $tb_user->getObj(" username='******' AND email='{$email}' "); if (!$user) { IError::show(403, "对不起,用户不存在"); } $hash = IHash::md5(microtime(true) . mt_rand()); //重新找回密码的数据 $tb_find_password = new IModel("find_password"); $tb_find_password->setData(array('hash' => $hash, 'user_id' => $user['id'], 'addtime' => time())); if ($tb_find_password->query("`hash` = '{$hash}'") || $tb_find_password->add()) { $url = IUrl::getHost() . IUrl::creatUrl("/simple/restore_password/hash/{$hash}"); $content = mailTemplate::findPassword(array("{url}" => $url)); $smtp = new SendMail(); $result = $smtp->send($user['email'], "您的密码找回", $content); if ($result === false) { IError::show(403, "发信失败,请重试!或者联系管理员查看邮件服务是否开启"); } } else { IError::show(403, "生成HASH重复,请重试"); } $message = "恭喜您,密码重置邮件已经发送!请到您的邮箱中去激活"; $this->redirect("/site/success/message/" . urlencode($message)); }