123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace addons\adminlogin;
- use addons\adminlogin\library\Service;
- use app\admin\library\Auth;
- use think\Addons;
- use think\Config;
- use think\Hook;
- use think\Loader;
- use think\Request;
- use think\Validate;
- use think\View;
- /**
- * 插件
- */
- class Adminlogin extends Addons
- {
- public function adminNologin()
- {
- $config = $this->getConfig();
- if ($config['is_origin']) return true;
- Service::error();
- }
- static $isViewFilter = false;
- public function moduleInit() {
- $config = $this->getConfig();
- // 如果使用原登录路径
- if ($config['is_origin']) {
- // 放到第一个执行,只执行一次
- Hook::add('view_filter', function (&$content) {
- if (self::$isViewFilter) return true;
- self::$isViewFilter = true;
- $auth = new Auth();
- if ($auth->isLogin()) return true;
- $config = $this->getConfig();
- $request = Request::instance();
- $module = strtolower($request->module());
- $controller = strtolower($request->controller());
- $action = strtolower($request->action());
- if ($module == 'admin' && $controller == 'index' && $action == 'login') {
- $templateTypeList = [];
- $type = $config['type'];
- if (true == $config['dev']) {
- $type = input('type') ? input('type') : $type;
- $templateTypeList = get_addon_fullconfig('adminlogin')[0]['content'];
- $i = 1;
- foreach ($templateTypeList as &$item) {
- $item = "{$i}、{$item}";
- $i++;
- }
- }
- $type = $type > 1 ? $type : '';
- $path = APP_PATH. 'admin/view/adminlogin/login'.$type.'.html';
- $temp = file_get_contents($path);
- $background = Config::get('fastadmin.login_background');
- $background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : '';
- $data = [
- 'templateTypeList' => $templateTypeList,
- 'hasCaptcha' => 1,
- 'background' => $background
- ];
- $content = (View::instance())->display($temp, $data);
- }
- return false;
- }, true);
- return true;
- }
- // 判断是否关闭fast自带登录
- $addonConfig = get_addon_config('adminlogin');
- $is = $addonConfig['close_fast'];
- if (!$is) {
- return true;
- }
- if (request()->module() != 'admin') {
- return true;
- }
- $controllername = Loader::parseName(request()->controller());
- $actionname = strtolower(request()->action());
- $path = str_replace('.', '/', $controllername) . '/' . $actionname;
- if ($path == 'index/login') {
- Service::error();
- }
- }
- /**
- * 插件安装方法
- * @return bool
- */
- public function install()
- {
-
- return true;
- }
- /**
- * 插件卸载方法
- * @return bool
- */
- public function uninstall()
- {
-
- return true;
- }
- /**
- * 插件启用方法
- * @return bool
- */
- public function enable()
- {
-
- return true;
- }
- /**
- * 插件禁用方法
- * @return bool
- */
- public function disable()
- {
-
- return true;
- }
- }
|