Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | fastadmin: https://www.fastadmin.net/
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 邮箱验证码接口
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\common\controller\Api;
  16. use app\common\library\Ems as Emslib;
  17. use app\member\model\Member;
  18. use think\facade\Hook;
  19. use think\facade\Validate;
  20. /**
  21. * @title 邮箱验证码接口
  22. * @controller api\controller\Ems
  23. * @group base
  24. */
  25. class Ems extends Api
  26. {
  27. /**
  28. * @title 发送验证码
  29. * @desc 最基础的接口注释写法
  30. * @author 御宅男
  31. * @url /api/Ems/send
  32. * @method GET
  33. * @tag 邮箱 验证码
  34. * @param name:email type:string require:1 desc:邮箱
  35. * @param name:event type:string require:1 desc:事件名称
  36. * @return name:data type:array ref:definitions\dictionary
  37. */
  38. public function send()
  39. {
  40. $email = $this->request->request("email");
  41. $event = $this->request->request("event");
  42. $event = $event ? $event : 'register';
  43. if (!$email || !Validate::isEmail($email)) {
  44. $this->error('邮箱格式不正确!');
  45. }
  46. $last = Emslib::get($email, $event);
  47. if ($last && time() - $last['create_time'] < 60) {
  48. $this->error('发送频繁');
  49. }
  50. if ($event) {
  51. $userinfo = Member::getByEmail($email);
  52. if ($event == 'register' && $userinfo) {
  53. $this->error('已被注册');
  54. } elseif (in_array($event, ['changeemail']) && $userinfo) {
  55. $this->error('已被占用');
  56. } elseif (in_array($event, ['changepwd', 'resetpwd', 'actemail']) && !$userinfo) {
  57. $this->error('未注册');
  58. }
  59. }
  60. if (!Hook::get('ems_send')) {
  61. $this->error('请在后台插件管理安装邮箱验证插件');
  62. }
  63. $ret = Emslib::send($email, null, $event);
  64. if ($ret) {
  65. $this->success('发送成功');
  66. } else {
  67. $this->error('发送失败');
  68. }
  69. }
  70. /**
  71. * @title 检测验证码
  72. * @desc 最基础的接口注释写法
  73. * @author 御宅男
  74. * @url /api/Ems/check
  75. * @method GET
  76. * @tag 邮箱 验证码
  77. * @param name:email type:string require:1 desc:邮箱
  78. * @param name:event type:string require:1 desc:事件名称
  79. * @param name:captcha type:string require:1 desc:验证码
  80. * @return name:data type:array ref:definitions\dictionary
  81. */
  82. public function check()
  83. {
  84. }
  85. }