赛亿官网

Login.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Controller;
  4. use think\Request;
  5. use app\admin\model\SysUser as UserModel;
  6. class Login extends Controller
  7. {
  8. protected $user_model;
  9. public function __construct(Request $request = null)
  10. {
  11. parent::__construct($request);
  12. $this->user_model = new UserModel();
  13. }
  14. public function index()
  15. {
  16. if (session('?username')) {
  17. $this->success('您已登入', 'admin/index/index');
  18. } else {
  19. return $this->fetch();
  20. }
  21. }
  22. public function dologin(Request $request = null)
  23. {
  24. if ($request->isPOST()) {
  25. // var_dump(input('post.'));
  26. // exit;
  27. $username = trim(input('post.username'));
  28. $password = trim(input('post.password'));
  29. $verify = trim(input('post.verify'));
  30. if (!$username || !$password || !$verify) {
  31. $this->error('用户名/密码/验证码不能为空');
  32. }
  33. if (!captcha_check($verify)) {
  34. $this->error('验证码不正确', '/admin/login');
  35. }
  36. $info = $this->user_model->getLogInfo($username);
  37. if (!$info || md5($password) != $info->password) {
  38. $this->error('用户名/密码不正确', '/admin/login');
  39. }
  40. $time = time();
  41. $ip = $request->ip();
  42. $result = $this->user_model->save(['login_time' => $time, 'login_ip' => $ip], ['id' => $info->id]);
  43. if ($result === false) {
  44. $this->error('登陆失败,请稍后重试', '/admin/login');
  45. }
  46. //记录登陆信息
  47. $browser = browser_info();
  48. @$result = model('login_note')->save([
  49. 'userid'=>$info['id'],
  50. 'time'=>$time,
  51. 'ip'=>$ip,
  52. 'browser'=>$browser
  53. ]);
  54. session('uid', $info->id);
  55. session('username', $info->username);
  56. session('role_id', $info->role_id);
  57. session('last_time', $info->login_time);
  58. session('last_ip', $info->login_ip);
  59. $this->success('登入成功', 'admin/index/index');
  60. } else {
  61. if (session('?user_name')) {
  62. $this->success('您已登入', 'admin/index/index');
  63. } else {
  64. return $this->fetch();
  65. }
  66. }
  67. }
  68. /**
  69. * 登出
  70. */
  71. public function logout()
  72. {
  73. session(null);
  74. return $this->fetch('index');
  75. }
  76. /**
  77. * admin/login/makecaptcha
  78. */
  79. }