Findpassword.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\controller\csmadmin;
  3. use think\Session;
  4. use app\admin\model\Admin;
  5. use app\common\library\Ems as Emslib;
  6. use addons\csmadmin\library\CsmBackend;
  7. /**
  8. * 找回密码
  9. *
  10. * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/findPassword/index
  11. */
  12. class Findpassword extends CsmBackend
  13. {
  14. public function index()
  15. {
  16. $this->success("Hello world!");
  17. }
  18. public function resetpassword()
  19. {}
  20. /**
  21. * 管理员找回密码发送邮件验证码
  22. */
  23. public function sendccode()
  24. {
  25. $email = strtolower($this->csmreq("email", true));
  26. $event = "csmadmin_findpassword";
  27. $last = Emslib::get($email, $event);
  28. if ($last && time() - $last['createtime'] < 60) {
  29. $this->error(__('发送频繁'));
  30. }
  31. // 判断邮箱是否存在
  32. if (true) {
  33. $admin = Admin::getByEmail($email);
  34. if ($admin == null) {
  35. $this->error(__('邮箱不存在,请重新输入!'));
  36. }
  37. }
  38. // 生成随机码,发送邮件
  39. $rand = mt_rand(1000, 9999);
  40. trace("Emslib.send({$email},{$rand},{$event})");
  41. \think\Hook::add('ems_send', function ($params) {
  42. $ip = $this->request->ip();
  43. $obj = \app\common\library\Email::instance();
  44. $result = $obj->to($params->email)
  45. ->subject('找回密码的验证码')
  46. ->message("您(IP:" . $ip . ")正在找回密码,验证码是:" . $params->code)
  47. ->send();
  48. return $result;
  49. });
  50. $ret = Emslib::send($email, $rand, $event);
  51. if ($ret) {
  52. session::set("csmadmin_findpassword", $rand);
  53. session::set("csmadmin_findpassword_email", $email);
  54. $this->success(__('发送成功'));
  55. } else {
  56. $this->error(__('发送失败'));
  57. }
  58. }
  59. }