PublicController.class.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Admin\Controller;
  3. use Common\Controller\ControllerController;
  4. use Think\Verify;
  5. /**
  6. * 后台唯一不需要权限验证的控制器
  7. *
  8. */
  9. class PublicController extends ControllerController
  10. {
  11. /**
  12. * 后台登陆
  13. *
  14. */
  15. public function login()
  16. {
  17. // $this->display('error');die;
  18. if (IS_POST) {
  19. $username = I('username');
  20. $password = I('password');
  21. // 图片验证码校验
  22. if (!$this->check_verify(I('post.verify')) && 'localhost' !== $_SERVER['HTTP_HOST'] && '127.0.0.1' !== $_SERVER['HTTP_HOST']) {
  23. //$this->error('验证码输入错误!');
  24. }
  25. // 验证用户名密码是否正确
  26. $user_object = D('Admin/User');
  27. $user_info = $user_object->login($username, $password);
  28. if (!$user_info) {
  29. $this->error($user_object->getError());
  30. }
  31. // 验证管理员表里是否有该用户
  32. $account_object = D('Admin/Access');
  33. $where['uid'] = $user_info['id'];
  34. $account_info = $account_object->where($where)->find();
  35. if (!$account_info) {
  36. $this->error('该用户没有管理员权限' . $account_object->getError());
  37. }
  38. // 设置登录状态
  39. $uid = $user_object->auto_login($user_info);
  40. // 跳转
  41. if (0 < $account_info['uid'] && $account_info['uid'] === $uid) {
  42. $this->success('登录成功!','index.php');
  43. } else {
  44. $this->logout();
  45. }
  46. } else {
  47. $this->assign('meta_title', '管理员登录');
  48. $this->display();
  49. }
  50. }
  51. /**
  52. * 注销
  53. *
  54. */
  55. public function logout()
  56. {
  57. session('user_auth', null);
  58. session('user_auth_sign', null);
  59. session('user_group', null);
  60. $this->success('退出成功!', U('login'));
  61. }
  62. /**
  63. * 图片验证码生成,用于登录和注册
  64. *
  65. */
  66. public function verify($vid = 1)
  67. {
  68. $verify = new Verify();
  69. $verify->length = 4;
  70. $verify->entry($vid);
  71. }
  72. /**
  73. * 检测验证码
  74. * @param integer $id 验证码ID
  75. * @return boolean 检测结果
  76. */
  77. public function check_verify($code, $vid = 1)
  78. {
  79. $verify = new Verify();
  80. return $verify->check($code, $vid);
  81. }
  82. }