分离后台和用户中心登录状态
This commit is contained in:
@@ -13,16 +13,29 @@ use think\facade\Session;
|
|||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @title 检查登录状态
|
||||||
*/
|
*/
|
||||||
function is_login() {
|
function is_login() {
|
||||||
$user = Session::get('userInfo');
|
if(strpos(Request::controller(), ".")){
|
||||||
return isset($user['uid']) ? $user['uid'] : false;
|
list($module, $controller) = explode(".", Request::controller());
|
||||||
|
}else{
|
||||||
|
$module = "";
|
||||||
|
}
|
||||||
|
$user = Session::get(strtolower($module) . 'Info');
|
||||||
|
return $user['uid'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title 检查是否为超级管理员
|
||||||
|
*/
|
||||||
function is_administrator() {
|
function is_administrator() {
|
||||||
$user = Session::get('userInfo');
|
if(strpos(Request::controller(), ".")){
|
||||||
return (isset($user['uid']) && (int) $user['uid'] === (int) env('rootuid')) ? true : false;
|
list($module, $controller) = explode(".", Request::controller());
|
||||||
|
}else{
|
||||||
|
$module = "";
|
||||||
|
}
|
||||||
|
$user = Session::get(strtolower($module) . 'Info');
|
||||||
|
return (int) $user['uid'] === (int) env('rootuid') ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function form($field = [], $data = []) {
|
function form($field = [], $data = []) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use app\model\AuthGroup;
|
|||||||
use app\model\Menu;
|
use app\model\Menu;
|
||||||
use app\model\Model;
|
use app\model\Model;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
|
use think\facade\Config;
|
||||||
|
|
||||||
class Base extends BaseC {
|
class Base extends BaseC {
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class Index extends Base {
|
|||||||
try {
|
try {
|
||||||
$userinfo = $user->login($this->request);
|
$userinfo = $user->login($this->request);
|
||||||
if ($userinfo) {
|
if ($userinfo) {
|
||||||
Session::set('userInfo', $userinfo);
|
Session::set('adminInfo', $userinfo);
|
||||||
return $this->success('登录成功!', url('/admin/index/index'));
|
return $this->success('登录成功!', url('/admin/index/index'));
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -64,7 +64,7 @@ class Index extends Base {
|
|||||||
* @return html
|
* @return html
|
||||||
*/
|
*/
|
||||||
public function logout(Member $user) {
|
public function logout(Member $user) {
|
||||||
Session::delete('userInfo');
|
Session::delete('adminInfo');
|
||||||
$this->redirect('/admin/login');
|
$this->redirect('/admin/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,12 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\controller\user;
|
namespace app\controller\user;
|
||||||
|
|
||||||
use think\facade\View;
|
|
||||||
use think\facade\Cache;
|
|
||||||
use app\controller\Base as BaseC;
|
use app\controller\Base as BaseC;
|
||||||
use app\model\Model;
|
|
||||||
use app\model\Form;
|
use app\model\Form;
|
||||||
|
use app\model\Model;
|
||||||
|
use think\facade\Cache;
|
||||||
|
use think\facade\Config;
|
||||||
|
use think\facade\View;
|
||||||
|
|
||||||
class Base extends BaseC {
|
class Base extends BaseC {
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ class Base extends BaseC {
|
|||||||
$this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $pc_themes;
|
$this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $pc_themes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!file_exists($this->app->getRootPath() . $this->tpl_config['view_dir_name'] . DIRECTORY_SEPARATOR . 'user')){
|
if (!file_exists($this->app->getRootPath() . $this->tpl_config['view_dir_name'] . DIRECTORY_SEPARATOR . 'user')) {
|
||||||
$this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'default';
|
$this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'default';
|
||||||
}
|
}
|
||||||
if ($template == '') {
|
if ($template == '') {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class Index extends Base {
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->error($e->getError(), '');
|
return $this->error($e->getError(), '');
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,10 +62,10 @@ class Index extends Base {
|
|||||||
$result = (new Member())->register($this->request);
|
$result = (new Member())->register($this->request);
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $this->success("注册成功!", url('/user/index/login'));
|
return $this->success("注册成功!", url('/user/index/login'));
|
||||||
}else{
|
} else {
|
||||||
return $this->error("注册失败!");
|
return $this->error("注册失败!");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,13 +90,13 @@ class Index extends Base {
|
|||||||
$result = Member::sendFindPaswd($user);
|
$result = Member::sendFindPaswd($user);
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $this->success("已发送找回密码邮件!", url('/user/index/login'));
|
return $this->success("已发送找回密码邮件!", url('/user/index/login'));
|
||||||
}else{
|
} else {
|
||||||
return $this->error("发送邮件失败!");
|
return $this->error("发送邮件失败!");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return $this->error('无此用户!');
|
return $this->error('无此用户!');
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,13 +124,13 @@ class Index extends Base {
|
|||||||
$result = Member::update($data, ['uid' => $user['uid']]);
|
$result = Member::update($data, ['uid' => $user['uid']]);
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $this->success("已重置!", url('/user/index/login'));
|
return $this->success("已重置!", url('/user/index/login'));
|
||||||
}else{
|
} else {
|
||||||
return $this->error("发送邮件失败!");
|
return $this->error("发送邮件失败!");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return $this->error('无此用户!');
|
return $this->error('无此用户!');
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$token = $this->request->param('token');
|
$token = $this->request->param('token');
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<li class="dropdown user user-menu">
|
<li class="dropdown user user-menu">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
<img src="__plugins__/adminlte/img/user2-160x160.jpg" class="user-image" alt="User Image">
|
<img src="__plugins__/adminlte/img/user2-160x160.jpg" class="user-image" alt="User Image">
|
||||||
<span class="hidden-xs">{:session('userInfo.nickname')}</span>
|
<span class="hidden-xs">{:session('adminInfo.nickname')}</span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<!-- User image -->
|
<!-- User image -->
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
<img src="__plugins__/adminlte/img/user2-160x160.jpg" class="img-circle" alt="User Image">
|
<img src="__plugins__/adminlte/img/user2-160x160.jpg" class="img-circle" alt="User Image">
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{:session('userInfo.nickname')}
|
{:session('adminInfo.nickname')}
|
||||||
<small>Member since Nov. 2012</small>
|
<small>Member since Nov. 2012</small>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
<img src="__plugins__/adminlte/img/user2-160x160.jpg" class="img-circle" alt="User Image">
|
<img src="__plugins__/adminlte/img/user2-160x160.jpg" class="img-circle" alt="User Image">
|
||||||
</div>
|
</div>
|
||||||
<div class="pull-left info">
|
<div class="pull-left info">
|
||||||
<p>{:session('userInfo.nickname')}</p>
|
<p>{:session('adminInfo.nickname')}</p>
|
||||||
<a href="#"><i class="fa fa-circle text-success"></i> 在线</a>
|
<a href="#"><i class="fa fa-circle text-success"></i> 在线</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user