Adminlogin.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace addons\adminlogin;
  3. use addons\adminlogin\library\Service;
  4. use app\admin\library\Auth;
  5. use think\Addons;
  6. use think\Config;
  7. use think\Hook;
  8. use think\Loader;
  9. use think\Request;
  10. use think\Validate;
  11. use think\View;
  12. /**
  13. * 插件
  14. */
  15. class Adminlogin extends Addons
  16. {
  17. public function adminNologin()
  18. {
  19. $config = $this->getConfig();
  20. if ($config['is_origin']) return true;
  21. Service::error();
  22. }
  23. static $isViewFilter = false;
  24. public function moduleInit() {
  25. $config = $this->getConfig();
  26. // 如果使用原登录路径
  27. if ($config['is_origin']) {
  28. // 放到第一个执行,只执行一次
  29. Hook::add('view_filter', function (&$content) {
  30. if (self::$isViewFilter) return true;
  31. self::$isViewFilter = true;
  32. $auth = new Auth();
  33. if ($auth->isLogin()) return true;
  34. $config = $this->getConfig();
  35. $request = Request::instance();
  36. $module = strtolower($request->module());
  37. $controller = strtolower($request->controller());
  38. $action = strtolower($request->action());
  39. if ($module == 'admin' && $controller == 'index' && $action == 'login') {
  40. $templateTypeList = [];
  41. $type = $config['type'];
  42. if (true == $config['dev']) {
  43. $type = input('type') ? input('type') : $type;
  44. $templateTypeList = get_addon_fullconfig('adminlogin')[0]['content'];
  45. $i = 1;
  46. foreach ($templateTypeList as &$item) {
  47. $item = "{$i}、{$item}";
  48. $i++;
  49. }
  50. }
  51. $type = $type > 1 ? $type : '';
  52. $path = APP_PATH. 'admin/view/adminlogin/login'.$type.'.html';
  53. $temp = file_get_contents($path);
  54. $background = Config::get('fastadmin.login_background');
  55. $background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : '';
  56. $data = [
  57. 'templateTypeList' => $templateTypeList,
  58. 'hasCaptcha' => 1,
  59. 'background' => $background
  60. ];
  61. $content = (View::instance())->display($temp, $data);
  62. }
  63. return false;
  64. }, true);
  65. return true;
  66. }
  67. // 判断是否关闭fast自带登录
  68. $addonConfig = get_addon_config('adminlogin');
  69. $is = $addonConfig['close_fast'];
  70. if (!$is) {
  71. return true;
  72. }
  73. if (request()->module() != 'admin') {
  74. return true;
  75. }
  76. $controllername = Loader::parseName(request()->controller());
  77. $actionname = strtolower(request()->action());
  78. $path = str_replace('.', '/', $controllername) . '/' . $actionname;
  79. if ($path == 'index/login') {
  80. Service::error();
  81. }
  82. }
  83. /**
  84. * 插件安装方法
  85. * @return bool
  86. */
  87. public function install()
  88. {
  89. return true;
  90. }
  91. /**
  92. * 插件卸载方法
  93. * @return bool
  94. */
  95. public function uninstall()
  96. {
  97. return true;
  98. }
  99. /**
  100. * 插件启用方法
  101. * @return bool
  102. */
  103. public function enable()
  104. {
  105. return true;
  106. }
  107. /**
  108. * 插件禁用方法
  109. * @return bool
  110. */
  111. public function disable()
  112. {
  113. return true;
  114. }
  115. }