Login.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare (strict_types = 1);
  3. /**
  4. * +----------------------------------------------------------------------
  5. * | 后台登录控制制器
  6. * +----------------------------------------------------------------------
  7. */
  8. namespace app\sys\controller;
  9. // 引入框架内置类
  10. use think\facade\Session;
  11. use think\facade\View;
  12. use app\common\model\SysUser;
  13. use think\facade\Cache;
  14. class Login
  15. {
  16. // 登录页面
  17. public function index()
  18. {
  19. // 已登录自动跳转
  20. if (Session::has('adminuser')) {
  21. return redirect((string)url('index/index'));
  22. }
  23. $restore_url = Session::has('restore') ? Session::get('restore'): (string)url('index/index');
  24. View::assign('restore_url', $restore_url);
  25. return View::fetch();
  26. }
  27. // 校验登录
  28. public function checkLogin(){
  29. return SysUser::checkLogin();
  30. }
  31. // 退出登录
  32. public function logout(){
  33. Cache::clear();
  34. Session::delete('adminuser');
  35. return redirect((string) url('login/index'));
  36. }
  37. }