作者 niuyongqing

人事系统

... ... @@ -2,6 +2,7 @@
namespace app\web\controller;
use think\Cache;
use think\Request;
use think\Session;
use think\Validate;
... ... @@ -19,8 +20,9 @@ class BaseController extends thinkController
*/
public function _initialize()
{
$user = Session::get('name');
if($user === ''){
//$user = Session::get('name');
$user=Cache::get('name');
if($user == ''){
// if (Session::get('name')) {
return Request::instance()->isAjax() ? json($this->renderError('您尚未登录系统')) : $this->redirect(url('web/index/login'));
}
... ...
... ... @@ -3,6 +3,7 @@
namespace app\web\controller;
use think\Cache;
use think\Db;
use think\Request;
... ... @@ -46,8 +47,10 @@ class Index extends Controller
return json_encode($data);
}else{
//Cookie::set('name',$name);
session('name', $list['username']);
// session('name', $list['username']);
// session('id', $list['id']);
Cache::set('name',$list['username'],3600);
Cache::set('id',$list['id'],3600);
$data=[
'data'=>$list['username'],
'code'=>200,
... ... @@ -69,7 +72,8 @@ class Index extends Controller
public function index()
{
//$user=Cookie::get('name');
$user = Session::get('name');
//$user = Session::get('name');
$user=Cache::get('name');
if(!$user){
//重定向到指定的URL地址
$this->error('您未进行登录', 'web/index/login'); exit;
... ... @@ -82,7 +86,8 @@ class Index extends Controller
public function loginout()
{
//Cookie::delete('name');
Session::clear();
//Session::clear();
Cache::clear();
$this->view->engine->layout(false);
return $this->fetch('login');
}
... ...