修改localstore模块登录
This commit is contained in:
parent
a1bc48208f
commit
4593540bf7
307
app/common/basics/LocalStoreBase.php
Executable file
307
app/common/basics/LocalStoreBase.php
Executable file
@ -0,0 +1,307 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\basics;
|
||||
|
||||
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\utils\Time;
|
||||
use app\shop\server\AuthServer;
|
||||
use think\App;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\facade\Config;
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* 后台基类
|
||||
* Class ShopBase
|
||||
* @Author FZR
|
||||
* @package app\common\basics
|
||||
*/
|
||||
abstract class LocalStoreBase
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 商家信息
|
||||
* @var
|
||||
*/
|
||||
protected $local_store;
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
* @var
|
||||
*/
|
||||
protected $lstore_id;
|
||||
|
||||
/**
|
||||
* 商家名称
|
||||
* @var
|
||||
*/
|
||||
protected $local_store_name;
|
||||
|
||||
/**
|
||||
* 管理员id
|
||||
* @var
|
||||
*/
|
||||
protected $local_store_admin_id;
|
||||
|
||||
/**
|
||||
* 管理员名称
|
||||
* @var
|
||||
*/
|
||||
protected $local_store_admin_name;
|
||||
|
||||
/**
|
||||
* 逻辑
|
||||
* @var
|
||||
*/
|
||||
protected $logic;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
* @var
|
||||
*/
|
||||
protected $validate;
|
||||
|
||||
/**
|
||||
* 不需要登录的方法
|
||||
* @var array
|
||||
*/
|
||||
public $like_not_need_login = [];
|
||||
|
||||
/**
|
||||
* js数据
|
||||
* @var array
|
||||
*/
|
||||
protected $js_data = [];
|
||||
|
||||
/**
|
||||
* 分页
|
||||
* @var int
|
||||
*/
|
||||
public $page_no = 1;
|
||||
public $page_size = 15;
|
||||
|
||||
/**
|
||||
* 模板颜色
|
||||
* @var string
|
||||
*/
|
||||
public $view_theme_color = '';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
//默认设置参数
|
||||
$this->initConfig();
|
||||
|
||||
//验证登录
|
||||
$this->checkLogin();
|
||||
|
||||
//验证权限
|
||||
$this->checkAuth();
|
||||
|
||||
//默认页面参数
|
||||
$this->setViewValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 基础配置参数
|
||||
* @author 段誉(2021/4/9 14:18)
|
||||
*/
|
||||
protected function initConfig()
|
||||
{
|
||||
$this->local_store = session('shop_info');
|
||||
$this->lstore_id = session('shop_info.lstore_id');
|
||||
$this->local_store_name = session('shop_info.shop_name');
|
||||
$this->local_store_admin_id = session('shop_info.id');
|
||||
$this->local_store_admin_name = session('shop_info.name');
|
||||
//分页参数
|
||||
$page_no = (int)$this->request->get('page_no');
|
||||
$this->page_no = $page_no && is_numeric($page_no) ? $page_no : $this->page_no;
|
||||
$page_size = (int)$this->request->get('page_size');
|
||||
$this->page_size = $page_size && is_numeric($page_size) ? $page_size : $this->page_size;
|
||||
$this->page_size = min($this->page_size, 100);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置视图全局变量
|
||||
*/
|
||||
private function setViewValue()
|
||||
{
|
||||
$app = Config::get('project');
|
||||
View::assign([
|
||||
'view_env_name' => $app['env_name'],
|
||||
'view_admin_name' => $app['admin_name'],
|
||||
'view_theme_color' => $app['theme_color'],
|
||||
'view_theme_button' => $app['theme_button'],
|
||||
'front_version' => $app['front_version'],
|
||||
'version' => $app['version'],
|
||||
'dateTime' => Time::getTime(),
|
||||
'storageUrl' => UrlServer::getFileUrl('/'),
|
||||
'company_name' => ConfigServer::get('copyright', 'company_name')
|
||||
]);
|
||||
$this->assignJs('image_upload_url', '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 检查登录
|
||||
* @author 段誉(2021/4/9 14:05)
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkLogin()
|
||||
{
|
||||
//已登录的访问登录页
|
||||
if ($this->local_store && !$this->isNotNeedLogin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//已登录的访问非登录页
|
||||
if ($this->local_store && $this->isNotNeedLogin()) {
|
||||
$this->redirect(url('index/index'));
|
||||
}
|
||||
|
||||
//未登录的访问非登录页
|
||||
if (!$this->local_store && $this->isNotNeedLogin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//未登录访问登录页
|
||||
$this->redirect(url('login/login'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 验证登录角色权限
|
||||
* @author 段誉(2021/4/13 11:34)
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkAuth()
|
||||
{
|
||||
//未登录的无需权限控制
|
||||
if (empty(session('shop_info'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//如果id为1,视为系统超级管理,无需权限控制
|
||||
if (session('shop_info.id') == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//权限控制判断
|
||||
$controller_action = request()->controller() . '/' . request()->action();// 当前访问
|
||||
$controller_action = strtolower($controller_action);
|
||||
|
||||
//没有的权限
|
||||
$none_auth = AuthServer::getRoleNoneAuthUris(session('shop_info.role_id'));
|
||||
if (empty($none_auth) || !in_array($controller_action, $none_auth)) {
|
||||
//通过权限控制
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->redirect(url('dispatch/dispatch_error',['msg' => '权限不足,无法访问']));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: js
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @author 段誉(2021/4/9 14:23)
|
||||
*/
|
||||
protected function assignJs($name, $value)
|
||||
{
|
||||
$this->js_data[$name] = $value;
|
||||
$js_code = "<script>";
|
||||
foreach ($this->js_data as $name => $value) {
|
||||
if (is_array($value)) {
|
||||
$value = json_encode($value);
|
||||
} elseif (!is_integer($value)) {
|
||||
$value = '"' . $value . '"';
|
||||
}
|
||||
$js_code .= $name . '=' . $value . ';';
|
||||
}
|
||||
$js_code .= "</script>";
|
||||
View::assign('js_code', $js_code);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 是否无需登录
|
||||
* @author 段誉(2021/4/9 14:03)
|
||||
* @return bool
|
||||
*/
|
||||
private function isNotNeedLogin()
|
||||
{
|
||||
if (empty($this->like_not_need_login)) {
|
||||
return false;
|
||||
}
|
||||
$action = strtolower(request()->action());
|
||||
$data = array_map('strtolower', $this->like_not_need_login);
|
||||
if (!in_array($action, $data)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 自定义重定向
|
||||
* @param mixed ...$args
|
||||
* @author 段誉(2021/4/9 14:04)
|
||||
*/
|
||||
public function redirect(...$args)
|
||||
{
|
||||
throw new HttpResponseException(redirect(...$args));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
13
app/common/model/localstore/LocalStoreAdmin.php
Normal file
13
app/common/model/localstore/LocalStoreAdmin.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\localstore;
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
class LocalStoreAdmin extends Models
|
||||
{
|
||||
public function getLoginTimeAttr($value)
|
||||
{
|
||||
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@
|
||||
namespace app\localstore\controller;
|
||||
|
||||
|
||||
use app\common\basics\ShopBase;
|
||||
use app\common\basics\LocalStoreBase;
|
||||
use app\common\model\shop\ShopRole;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\JsonServer;
|
||||
@ -29,7 +29,7 @@ use app\localstore\logic\index\StatLogic;
|
||||
use app\localstore\server\MenuServer;
|
||||
use think\facade\Config;
|
||||
|
||||
class Index extends ShopBase
|
||||
class Index extends LocalStoreBase
|
||||
{
|
||||
/**
|
||||
* 后台前端全局界面
|
||||
|
||||
@ -23,6 +23,7 @@ namespace app\localstore\logic;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\shop\ShopAdmin;
|
||||
use app\common\model\localstore\LocalStoreAdmin;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\facade\Cookie;
|
||||
|
||||
@ -42,7 +43,7 @@ class LoginLogic extends Logic
|
||||
*/
|
||||
public static function login($post)
|
||||
{
|
||||
$adminModel = new ShopAdmin();
|
||||
$adminModel = new LocalStoreAdmin();
|
||||
$admin_info = $adminModel->alias('a')
|
||||
->join('shop s', 's.id = a.shop_id')
|
||||
->field(['a.id', 'a.account', 'a.name', 'role_id', 'shop_id', 's.name' => 'shop_name', 's.type'])
|
||||
@ -74,11 +75,9 @@ class LoginLogic extends Logic
|
||||
*/
|
||||
public static function logout()
|
||||
{
|
||||
session('shop_info', null);
|
||||
session('local_store_info', null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function config()
|
||||
{
|
||||
$config = [
|
||||
@ -95,6 +94,4 @@ class LoginLogic extends Logic
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -22,7 +22,7 @@ namespace app\localstore\validate;
|
||||
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\model\shop\ShopAdmin;
|
||||
use app\common\model\localstore\LocalStoreAdmin;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
@ -61,13 +61,12 @@ class LoginValidate extends Validate
|
||||
return false;
|
||||
}
|
||||
|
||||
$adminModel = new ShopAdmin();
|
||||
$adminModel = new LocalStoreAdmin();
|
||||
$admin_info = $adminModel->alias('a')
|
||||
->field('a.*')
|
||||
->join('shop s', 's.id = a.shop_id')
|
||||
->join('local_store ls', 'ls.lstore_id = a.lstore_id')
|
||||
->where(['a.account' => $data['account'], 'a.del' => 0])
|
||||
->find();
|
||||
|
||||
if (empty($admin_info)) {
|
||||
$this->safe(true);
|
||||
return '账号不存在';
|
||||
@ -93,11 +92,11 @@ class LoginValidate extends Validate
|
||||
*/
|
||||
protected function safe($add = false)
|
||||
{
|
||||
$cache_name = 'shop_admin_login_error_count' . request()->ip();
|
||||
$cache_name = 'local_store_admin_login_error_count' . request()->ip();
|
||||
if ($add) {
|
||||
$admin_login_error_count = Cache::get($cache_name);
|
||||
$admin_login_error_count++;
|
||||
Cache::tag('shop_admin_login_error_count')->set($cache_name, $admin_login_error_count, 1800);
|
||||
Cache::tag('local_store_admin_login_error_count')->set($cache_name, $admin_login_error_count, 1800);
|
||||
}
|
||||
$count = Cache::get($cache_name);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user