-
Notifications
You must be signed in to change notification settings - Fork 3
/
UserController.class.php
70 lines (61 loc) · 1.33 KB
/
UserController.class.php
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
<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller{
//管理员登录
public function login(){
if(IS_POST){
$administratorTabModel = M('administratortab');
$condition = array(
'username' => I("post.username");
'password' => I("post.password");
);
$result = $administratorTabModel->where($condition)->count();
if($result>0){
session("username",I("post.username"));
$this->success("登录成功",U("Index/index"));
}
else{
$this->error("用户名或密码不正确");
}
}
else{
$this->display();
}
}
//注册
public function reg(){
$this->display();
}
//注册为管理员
public function doReg(){
if(!IS_POST){
exit("bad request!");
}
$administratorTabModel=D("administratortab");
$condition = array(
'username' => I("post.username");
);
$result = $administratorTabModel->where($condition)->count();
if($result==0 && $administratorTabModel->add()){
$this->success("注册成功",U("lists"));
}
elseif ($result>0) {
$this->error("用户名已使用");
}
else{
$this->error("注册失败");
}
}
//退出管理员登录
public function logout(){
session('[destroy]');
redirect(U('User/login'),2,'正在退出');
}
public function doAdd(){
if(!IS_POST){
exit("bad request请求");
}
}
}
?>