12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\admin\controller\csmadmin;
- use think\Session;
- use app\admin\model\Admin;
- use app\common\library\Ems as Emslib;
- use addons\csmadmin\library\CsmBackend;
- /**
- * 找回密码
- *
- * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/findPassword/index
- */
- class Findpassword extends CsmBackend
- {
- public function index()
- {
- $this->success("Hello world!");
- }
- public function resetpassword()
- {}
- /**
- * 管理员找回密码发送邮件验证码
- */
- public function sendccode()
- {
- $email = strtolower($this->csmreq("email", true));
- $event = "csmadmin_findpassword";
- $last = Emslib::get($email, $event);
- if ($last && time() - $last['createtime'] < 60) {
- $this->error(__('发送频繁'));
- }
- // 判断邮箱是否存在
- if (true) {
- $admin = Admin::getByEmail($email);
- if ($admin == null) {
- $this->error(__('邮箱不存在,请重新输入!'));
- }
- }
- // 生成随机码,发送邮件
-
- $rand = mt_rand(1000, 9999);
- trace("Emslib.send({$email},{$rand},{$event})");
- \think\Hook::add('ems_send', function ($params) {
- $ip = $this->request->ip();
- $obj = \app\common\library\Email::instance();
- $result = $obj->to($params->email)
- ->subject('找回密码的验证码')
- ->message("您(IP:" . $ip . ")正在找回密码,验证码是:" . $params->code)
- ->send();
- return $result;
- });
- $ret = Emslib::send($email, $rand, $event);
- if ($ret) {
- session::set("csmadmin_findpassword", $rand);
- session::set("csmadmin_findpassword_email", $email);
- $this->success(__('发送成功'));
- } else {
- $this->error(__('发送失败'));
- }
- }
- }
|