Login.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User: 林志杰
  5. * Email: 598287049@qq.com
  6. * Time: 2020/1/2 12:58
  7. */
  8. namespace app\admin\controller;
  9. use app\BaseController;
  10. use app\common\model\mysql\AdminUser;
  11. use think\facade\View;
  12. class Login extends BaseController
  13. {
  14. public function index()
  15. {
  16. return View::fetch();
  17. }
  18. public function md5()
  19. {
  20. echo md5('admin_singwa_abc');
  21. }
  22. public function check()
  23. {
  24. if (!$this->request->isPost()) {
  25. return show(config('status.error'), '请求方式错误');
  26. }
  27. // 参数校验 1、原生方式 2、TP6 验证机制
  28. $username = $this->request->param('username', '', 'trim');
  29. $password = $this->request->param('password', '', 'trim');
  30. $captcha = $this->request->param('captcha', '', 'trim');
  31. if (empty($username) || empty($password) || empty($captcha)) {
  32. return show(config('status.error'), '参数不能为空');
  33. }
  34. // 验证码校验
  35. if (!captcha_check($captcha)) {
  36. // 验证码校验失败
  37. return show(config('status.error'), '验证码不正确');
  38. }
  39. $adminUserObj = new AdminUser();
  40. $adminUser = $adminUserObj->getAdminUserByUsername($username);
  41. if (empty($adminUser) || $adminUser->status != config('status.mysql.table_normal')) {
  42. return show(config('status.error'), '不存在该用户');
  43. }
  44. $adminUser = $adminUser->toArray();
  45. if ($adminUser['password'] !== md5($password . '_singwa_abc')) {
  46. return show(config('status.error'), '密码错误');
  47. }
  48. return show(config('status.success'), '登陆成功');
  49. }
  50. }