Index.php
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace app\web\controller;
use think\Cache;
use think\Db;
use think\Request;
use think\Cookie;
use think\Session;
/**
* 首页
* Class Index
* @package app\admin\controller
*/
class Index extends Controller
{
//登录页面
public function login()
{
$this->view->engine->layout(false);
return $this->fetch();
}
public function tologin(Request $request)
{
$data = $request->param();
$where['username']=$data['name'];
$list= Db::table('sos_user_admin')->where($where)->find();
if(empty($list)){
$list= Db::table('sos_user_mechanism')->where($where)->find();
}
if(empty($list)){
$data=[
'code'=>100,
'msg'=>'用户名错误'
];
return json_encode($data);
}elseif($list['password'] != md5(md5($data['pwd']))){
$data=[
'code'=>100,
'msg'=>'密码错误'
];
return json_encode($data);
}else{
//Cookie::set('name',$name);
// 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,
'msg'=>'验证成功'
];
return json_encode($data);
}
}
/**
* 框架页面
* @return array|mixed
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index()
{
//$user=Cookie::get('name');
//$user = Session::get('name');
$user=Cache::get('name');
if(!$user){
//重定向到指定的URL地址
$this->error('您未进行登录', 'web/index/login'); exit;
}
$this->view->engine->layout(false);
return $this->fetch('index');
}
public function loginout()
{
//Cookie::delete('name');
//Session::clear();
Cache::clear();
$this->view->engine->layout(false);
return $this->fetch('login');
}
public function quick_menu()
{
$this->view->engine->layout(false);
return $this->fetch('quick_menu');
}
}