Index.php
4.7 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
namespace app\teacher\controller;
use app\common\controller\TeacherBase;
use think\Config;
use think\Hook;
use think\Validate;
/**
* 后台首页
* @internal
*/
class Index extends TeacherBase
{
protected $noNeedLogin = ['login'];
protected $noNeedRight = ['index', 'logout'];
protected $layout = '';
public function _initialize()
{
parent::_initialize();
//移除HTML标签
$this->request->filter('trim,strip_tags,htmlspecialchars');
}
/**
* 后台首页
*/
public function index()
{
$menulist = [];
$navlist = [];
$action = $this->request->request('action');
if ($this->request->isPost()) {
if ($action == 'refreshmenu') {
$this->success('', null, ['menulist' => $menulist, 'navlist' => $navlist]);
}
}
$fixedmenu= [
"id" => 1,
"type" => "file",
"level_type" => "1",
"pid" => 0,
"name" => "dashboard",
"title" => "控制台",
"icon" => "fa fa-dashboard fa-fw",
"condition" => "",
"remark" => "Dashboard tips",
"ismenu" => 1,
"createtime" => 1602726835,
"updatetime" => 1602726835,
"weigh" => 0,
"status" => "normal",
"url" => "/teacher/dashboard",
"badge" => "",
"py" => "kzt",
"pinyin" => "kongzhitai"
];
$referermenu = [];
$this->view->assign('fixedmenu', $fixedmenu);
$this->view->assign('referermenu', $referermenu);
$this->view->assign('title', __('Home'));
return $this->view->fetch();
}
/**
* 管理员登录
*/
public function login()
{
$url = $this->request->get('url', 'index/index');
if ($this->isLogin()) {
$this->success(__("You've logged in, do not login again"), $url);
}
if ($this->request->isPost()) {
$username = $this->request->post('username');
$password = $this->request->post('password');
$keeplogin = $this->request->post('keeplogin');
$token = $this->request->post('__token__');
$rule = [
'username' => 'require|length:3,30',
'password' => 'require|length:3,30',
//'__token__' => 'require|token',
];
$data = [
'username' => $username,
'password' => $password,
// '__token__' => $token,
];
// if (Config::get('fastadmin.login_captcha')) {
// $rule['captcha'] = 'require|captcha';
// $data['captcha'] = $this->request->post('captcha');
// }
// $validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]);
// $result = $validate->check($data);
// if (!$result) {
// $this->error($validate->getError(), $url, ['token' => $this->request->token()]);
// }
$result = $this->login_base($username, $password, $keeplogin ? 86400 : 0);
if (is_array($result)) {
Hook::listen("admin_login_after", $this->request);
$this->success(__('Login successful'), $url, ['url' => $url, 'id' => $result['id'], 'username' => $username, 'avatar' => '/assets/img/avatar.png']);
} else {
// $msg = $this->auth->getError();
$msg = $result ? $result : __('Username or password is incorrect');
$this->error($msg);
}
}
// 根据客户端的cookie,判断是否可以自动登录
// if ($this->autologin()) {
// $this->redirect($url);
// }
$background = Config::get('fastadmin.login_background');
$background = stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background;
$this->view->assign('background', $background);
$this->view->assign('title', __('Login'));
Hook::listen("admin_login_init", $this->request);
return $this->view->fetch();
}
/**
* 注销登录
*/
public function logout()
{
$this->logout_base();
Hook::listen("teacher_logout_after", $this->request);
$this->success(__('Logout successful'), 'index/login');
}
/**
* 页面跳转
*/
public function transfer($url = NULL) {
$this->assignconfig('target_url', $url);
return $this->view->fetch();
}
public function checkUserLogin(){
$teacher = session("teacher");
if(empty($teacher)){
$this->error("请登录");
}else{
$this->success("success");
}
}
}