PublicController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use cmf\controller\AdminBaseController;
  13. use think\Db;
  14. class PublicController extends AdminBaseController
  15. {
  16. public function initialize()
  17. {
  18. }
  19. /**
  20. * 后台登陆界面
  21. */
  22. public function login()
  23. {
  24. $loginAllowed = session("__LOGIN_BY_CMF_ADMIN_PW__");
  25. if (empty($loginAllowed)) {
  26. //$this->error('非法登录!', cmf_get_root() . '/');
  27. return redirect(cmf_get_root() . "/");
  28. }
  29. $admin_id = session('ADMIN_ID');
  30. if (!empty($admin_id)) {//已经登录
  31. return redirect(url("admin/Index/index"));
  32. } else {
  33. session("__SP_ADMIN_LOGIN_PAGE_SHOWED_SUCCESS__", true);
  34. $result = hook_one('admin_login');
  35. if (!empty($result)) {
  36. return $result;
  37. }
  38. return $this->fetch(":login");
  39. }
  40. }
  41. /**
  42. * 登录验证
  43. */
  44. public function doLogin()
  45. {
  46. if (hook_one('admin_custom_login_open')) {
  47. $this->error('您已经通过插件自定义后台登录!');
  48. }
  49. $loginAllowed = session("__LOGIN_BY_CMF_ADMIN_PW__");
  50. if (empty($loginAllowed)) {
  51. $this->error('非法登录!', cmf_get_root() . '/');
  52. }
  53. $captcha = $this->request->param('captcha');
  54. if (empty($captcha)) {
  55. $this->error(lang('CAPTCHA_REQUIRED'));
  56. }
  57. //验证码
  58. if (!cmf_captcha_check($captcha)) {
  59. $this->error(lang('CAPTCHA_NOT_RIGHT'));
  60. }
  61. $name = $this->request->param("username");
  62. if (empty($name)) {
  63. $this->error(lang('USERNAME_OR_EMAIL_EMPTY'));
  64. }
  65. $pass = $this->request->param("password");
  66. if (empty($pass)) {
  67. $this->error(lang('PASSWORD_REQUIRED'));
  68. }
  69. if (strpos($name, "@") > 0) {//邮箱登陆
  70. $where['user_email'] = $name;
  71. } else {
  72. $where['user_login'] = $name;
  73. }
  74. $result = Db::name('user')->where($where)->find();
  75. if (!empty($result)) {
  76. ///pppp
  77. ///主
  78. if($result['user_type']=='3')
  79. {
  80. $this->error('您登录的信息不存在');
  81. }
  82. /// pppp
  83. //pppp
  84. //次
  85. // if($result['user_type']!='3')
  86. // {
  87. // $this->error('您登录的信息不存在');
  88. // }
  89. if($result['user_type']=='3') {
  90. $res_fp = Db::name('user_fp')->where('userid', $result['id'])->find();
  91. if ($res_fp['end_time'] < time()) {
  92. $this->error('您暂时无法登录');
  93. }
  94. }
  95. ///pppp
  96. if ($pp=cmf_compare_password($pass, $result['user_pass'])) {
  97. $groups = Db::name('RoleUser')
  98. ->alias("a")
  99. ->join('__ROLE__ b', 'a.role_id =b.id')
  100. ->where(["user_id" => $result["id"], "status" => 1])
  101. ->value("role_id");
  102. if ($result["id"] != 1 && (empty($groups) || empty($result['user_status']))) {
  103. $this->error(lang('USE_DISABLED'));
  104. }
  105. //登入成功页面跳转
  106. session('ADMIN_ID', $result["id"]);
  107. session('name', $result["user_login"]);
  108. $result['last_login_ip'] = get_client_ip(0, true);
  109. $result['last_login_time'] = time();
  110. $token = cmf_generate_user_token($result["id"], 'web');
  111. if (!empty($token)) {
  112. session('token', $token);
  113. }
  114. Db::name('user')->update($result);
  115. cookie("admin_username", $name, 3600 * 24 * 30);
  116. session("__LOGIN_BY_CMF_ADMIN_PW__", null);
  117. $this->success(lang('LOGIN_SUCCESS'), url("admin/Index/index"));
  118. } else {
  119. $this->error(lang('PASSWORD_NOT_RIGHT'));
  120. }
  121. } else {
  122. $this->error(lang('USERNAME_NOT_EXIST'));
  123. }
  124. }
  125. /**
  126. * 后台管理员退出
  127. */
  128. public function logout()
  129. {
  130. session('ADMIN_ID', null);
  131. return redirect(url('/', [], false, true));
  132. }
  133. }