Login.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\admin\controller\index;
  3. use app\admin\controller\BaseController;
  4. use app\admin\server\index\IndexServer;
  5. use app\admin\server\index\LoginServer;
  6. use Gregwar\Captcha\CaptchaBuilder;
  7. use support\Redis;
  8. use support\Request;
  9. class Login extends BaseController
  10. {
  11. /**
  12. * Notes:管理员登录
  13. * User: yym
  14. * Date: 2022/8/02
  15. */
  16. public function login()
  17. {
  18. $user_name = (string)$this->request->post('user_name');//账户
  19. $password = (string)$this->request->post('password');//密码
  20. $captcha = $this->request->post('captcha', '');//验证码
  21. $this->validateCheck('index\LoginValidate',['user_name' => $user_name, 'password' => $password], 'login_admin');
  22. return json_success(LoginServer::login($user_name, $password, $captcha), '登录成功');
  23. }
  24. /**
  25. * Notes:获取图形验证码
  26. * @return \support\Response
  27. * User: yym
  28. * Date: 2022/8/2
  29. */
  30. public function getCaptcha()
  31. {
  32. // 初始化验证码类
  33. $builder = new CaptchaBuilder();
  34. // 生成验证码
  35. $builder->build();
  36. // 将验证码的值存储到session中
  37. $this->request->session()->set('captcha', strtolower($builder->getPhrase()));
  38. // 获得验证码图片二进制数据
  39. $img_content = $builder->get();
  40. // 输出验证码二进制数据
  41. return response($img_content, 200, ['Content-Type' => 'image/jpeg']);
  42. }
  43. /**
  44. * Notes:管理员修改密码
  45. * @return \support\Response
  46. * @throws \Exception
  47. * User: yym
  48. * Date: 2022/8/3
  49. */
  50. public function updatePwd()
  51. {
  52. $old_pwd = (string)$this->request->post('old_pwd');//旧密码
  53. $new_pwd = (string)$this->request->post('new_pwd');//新密码
  54. $confirm_pwd = (string)$this->request->post('confirm_pwd');//确认密码
  55. $admin_id = (int)$this->request->admin_id;
  56. $this->validateCheck('index\IndexValidate', ['old_pwd' => $old_pwd, 'new_pwd' => $new_pwd, 'confirm_pwd' => $confirm_pwd], 'up_pwd');
  57. IndexServer::updatePwd($admin_id, $old_pwd, $new_pwd, $confirm_pwd);
  58. return json_success([], '修改成功');
  59. }
  60. /**
  61. * Notes:退出登录
  62. * @return \support\Response
  63. * User: yym
  64. * Date: 2022/8/3
  65. */
  66. public function loginOut()
  67. {
  68. LoginServer::loginOut($this->request->admin_token);
  69. return json_success([], '退出成功');
  70. }
  71. }