Login.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @author huwhois<huwhois@163.com>
  4. */
  5. namespace app\admin\controller;
  6. use daswork\Controller;
  7. use app\admin\model\User;
  8. class Login extends Controller
  9. {
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. $this->model = new User();
  14. session_start();
  15. }
  16. public function index()
  17. {
  18. if ($_SERVER['REQUEST_METHOD']=='POST') {
  19. $param = escapeString($_POST);
  20. // var_dump($param);
  21. // exit;
  22. $username = trim($param['username']);
  23. $password = trim($param['passwd']);
  24. if (!$username || !$password) {
  25. echo "<script>alert('用户名/密码/不能为空');location.href='http://meeting.ecorr.org/admin/login/index';</script>";
  26. return false;
  27. }
  28. $info = $this->model->getOneByUsername($username);
  29. if (!$info || md5($password) != $info['password']) {
  30. $this->assign('code', 0);
  31. $this->assign('msg', '用户名/密码不正确');
  32. $this->assign('url', '/admin/login/index');
  33. $this->assign('wait', 2);
  34. $this->fetch('jump.html');
  35. // die("<script>alert('用户名/密码不正确');location.href='http://meeting.ecorr.org/admin/login/index';</script>");
  36. return false;
  37. }
  38. // 记录登录时间
  39. $info['last_time'] = time();
  40. $this->model->updateById($info);
  41. $_SESSION['admin'] = true;
  42. $_SESSION['username'] = $username;
  43. $_SESSION['userid'] = $info['id'];
  44. $this->assign('code', 1);
  45. $this->assign('msg', '登录成功');
  46. $this->assign('url', '/admin/index/index');
  47. $this->assign('wait', 3);
  48. $this->fetch('jump.html');
  49. } else {
  50. if (isset($_SESSION["admin"]) && $_SESSION["admin"] === true) {
  51. echo "alert('您已登录');<script>location.href='http://meeting.ecorr.org/admin/index/index';</script>";
  52. // return false;
  53. } else {
  54. $this->fetch();
  55. }
  56. }
  57. }
  58. public function logout()
  59. {
  60. session_destroy();
  61. return $this->fetch('index.html');
  62. }
  63. }