Passport.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\admin\controller;
  10. use app\admin\model\admin\User as UserModel;
  11. use think\Session;
  12. /**
  13. * 超管后台认证
  14. * Class Passport
  15. * @package app\store\controller
  16. */
  17. class Passport extends Controller
  18. {
  19. /**
  20. * 超管后台登录
  21. * @return array|mixed
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. */
  26. public function login()
  27. {
  28. if ($this->request->isAjax()) {
  29. $model = new UserModel;
  30. if ($model->login($this->postData('User'))) {
  31. return $this->renderSuccess('登录成功', url('index/index'));
  32. }
  33. return $this->renderError($model->getError() ?: '登录失败');
  34. }
  35. $this->view->engine->layout(false);
  36. return $this->fetch('login');
  37. }
  38. /**
  39. * 退出登录
  40. */
  41. public function logout()
  42. {
  43. Session::clear('dyu_admin');
  44. $this->redirect('passport/login');
  45. }
  46. }