Login.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Controller;
  4. use think\Exception;
  5. use think\Session;
  6. use think\Log;
  7. use think\cache\driver\Redis;
  8. class Login extends Controller
  9. {
  10. /**
  11. * 管理员登录
  12. *
  13. * @access public
  14. * @return string
  15. */
  16. public function login()
  17. {
  18. $msg = '';
  19. if (input('post.')) {
  20. $msg = lang('EC01002');
  21. try {
  22. // 获取管理员信息.
  23. $userInfo = model('Admin')->login();
  24. print_r($userInfo);
  25. // 成功则跳转.
  26. if ($userInfo['code'] === 1) {
  27. return $this->redirect('Admin/Index/index');
  28. // 失败则返回错误信息.
  29. } else {
  30. $msg = $userInfo['msg'];
  31. }
  32. } catch (Exception $e) {
  33. Log::write($e->getMessage(), 'error');
  34. }
  35. }
  36. $this->assign([
  37. 'errorMsg' => $msg,
  38. ]);
  39. return $this->fetch();
  40. }//end login()
  41. /**
  42. * 退出登陆
  43. *
  44. * @access public
  45. * @return string
  46. */
  47. public function logout()
  48. {
  49. try {
  50. // 退出登陆.
  51. $userInfo = model('Admin')->logout();
  52. // 成功.
  53. if ($userInfo['code'] === 1) {
  54. return $this->redirect('Admin/Login/login');
  55. }
  56. } catch (Exception $e) {
  57. Log::write($e->getMessage(), 'error');
  58. }
  59. }//end logout()
  60. }