LoginController.class.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Home\Controller;
  3. use Base\Controller\BaseController;
  4. use User\Model\AdminModel;
  5. use Think\Verify;
  6. /*
  7. * To change this license header, choose License Headers in Project Properties.
  8. * To change this template file, choose Tools | Templates
  9. * and open the template in the editor.
  10. */
  11. /**
  12. * 登录控制器
  13. */
  14. class LoginController extends BaseController {
  15. private $adminModel;
  16. public function _initialize(){
  17. $this->adminModel = new AdminModel();
  18. }
  19. public function login() {
  20. layout(false);
  21. if (IS_POST) {
  22. $res = checkVerify(I('verify'));
  23. if(empty($res)){
  24. $this->error('验证码错误', __APP__.'/Home/Login/login', 2);
  25. exit;
  26. }
  27. if(empty(I('username')) || empty(I('password'))){
  28. $this->error('用户名或者密码不能为空', __APP__.'/Home/Login/login', 2);
  29. exit;
  30. }
  31. $admin = $this->adminModel->onLogin();
  32. if(empty($admin)) {
  33. $this->error('用户名或者密码错误', __APP__.'/Home/Login/login', 2);
  34. exit;
  35. }
  36. session('admin', $admin);
  37. header("location: " . __APP__ . "/User/User/index");
  38. exit;
  39. }
  40. $this->display();
  41. }
  42. public function createVerify(){
  43. $Verify = new Verify();
  44. $Verify->fontSize = 20;
  45. $Verify->length = 4;
  46. $Verify->useNoise = false;
  47. $Verify->imageW = 150;
  48. $Verify->imageH = 50;
  49. $Verify->entry();
  50. }
  51. public function outLogin(){
  52. session(null);
  53. layout(false);
  54. $this->display("login");
  55. }
  56. }