控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Member.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 前台会员api管理
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\common\library\Ems;
  16. use app\common\library\Sms;
  17. use app\member\controller\MemberApi;
  18. class Member extends MemberApi
  19. {
  20. protected $noNeedLogin = ['login', 'register'];
  21. protected $noNeedRight = [];
  22. //初始化
  23. protected function initialize()
  24. {
  25. parent::initialize();
  26. }
  27. /**
  28. * 会员中心
  29. */
  30. public function index()
  31. {
  32. $this->success('', ['welcome' => $this->auth->nickname]);
  33. }
  34. /**
  35. * 会员登录
  36. *
  37. * @ApiMethod (POST)
  38. * @param string $account 账号
  39. * @param string $password 密码
  40. */
  41. public function login()
  42. {
  43. $account = $this->request->post('account');
  44. $password = $this->request->post('password');
  45. if (!$account || !$password) {
  46. $this->error('未知参数');
  47. }
  48. $ret = $this->auth->loginLocal($account, $password);
  49. if ($ret) {
  50. $data = ['userinfo' => $this->auth->getUserinfo()];
  51. $this->success('登录成功', $data);
  52. } else {
  53. $this->error($this->auth->getError());
  54. }
  55. }
  56. /**
  57. * 注册会员
  58. */
  59. public function register()
  60. {
  61. if (empty($this->memberConfig['allowregister'])) {
  62. $this->error("系统不允许新会员注册!");
  63. }
  64. $extend = [];
  65. $data = $this->request->post();
  66. $rule = [
  67. 'username|用户名' => 'unique:member|require|alphaDash|length:3,20',
  68. 'nickname|昵称' => 'unique:member|chsDash|length:3,20',
  69. 'mobile|手机' => 'require|unique:member|mobile',
  70. 'password|密码' => 'require|length:3,20',
  71. 'email|邮箱' => 'unique:member|require|email',
  72. ];
  73. if ($this->memberConfig['password_confirm']) {
  74. $rule['password|密码'] = "require|length:3,20|confirm";
  75. }
  76. if ($this->memberConfig['register_mobile_verify']) {
  77. $rule['captcha_mobile|手机验证码'] = "require";
  78. }
  79. if ($this->memberConfig['register_email_verify']) {
  80. $rule['captcha_email|邮箱验证码'] = "require";
  81. }
  82. $result = $this->validate($data, $rule);
  83. if (true !== $result) {
  84. $this->error($result);
  85. }
  86. if ($this->memberConfig['register_mobile_verify']) {
  87. $result = Sms::check($data['mobile'], $data['captcha_mobile'], 'register');
  88. if (!$result) {
  89. $this->error('手机验证码错误!');
  90. }
  91. $extend['ischeck_mobile'] = 1;
  92. }
  93. if ($this->memberConfig['register_email_verify']) {
  94. $result = Ems::check($data['email'], $data['captcha_email'], 'register');
  95. if (!$result) {
  96. $this->error('邮箱验证码错误!');
  97. }
  98. $extend['ischeck_email'] = 1;
  99. }
  100. $ret = $this->auth->userRegister($data['username'], $data['password'], $data['email'], $data['mobile'], $extend);
  101. if ($ret) {
  102. $data = ['userinfo' => $this->auth->getUserinfo()];
  103. $this->success('注册成功', $data);
  104. } else {
  105. $this->error($this->auth->getError());
  106. }
  107. }
  108. /**
  109. * 退出登录
  110. * @ApiMethod (POST)
  111. */
  112. public function logout()
  113. {
  114. if (!$this->request->isPost()) {
  115. $this->error('未知参数');
  116. }
  117. $this->auth->logout();
  118. $this->success('注销成功');
  119. }
  120. }