-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathadmin.php
163 lines (154 loc) · 4.69 KB
/
admin.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
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
156
157
158
159
160
161
162
163
<?php
require('common.php');
if(empty($_GET['a'])){
if(check_login()){
header('location:./admin.php?a=invitation_code');
exit();
}else{
require('login.html');
exit();
}
}
if($_GET['a'] == 'login'){
$username = !empty($_POST['username']) ? $_POST['username'] : '';
$password = !empty($_POST['password']) ? $_POST['password'] : '';
if($username == $admin['username'] && md5($password) == $admin['password']){
$_SESSION['token'] = md5($admin['username'] . $admin['password']);
header('location:./admin.php?a=invitation_code');
exit();
}else{
exit("登录失败");
}
}
if($_GET['a'] == 'invitation_code'){
if(!check_login()){
require('login.html');
exit();
}
require('invitation_code.html');
exit();
}
if($_GET['a'] == 'invitation_code_list'){
if(!check_login()){
response(1,"登录已失效");
}
$page = !empty($_GET['page']) ? intval($_GET['page']) : 0;
$limit = !empty($_GET['limit']) ? intval($_GET['limit']) : 0;
$status = !empty($_GET['status']) ? intval($_GET['status']) : 0;//0全部 1已使用 2未使用
$keyword = !empty($_GET['keyword']) ? intval($_GET['keyword']) : '';
if($page <= 0){
response(1,"页码必须大于0");
}
if($limit <= 0){
response(1,"每页条数必须大于0");
}
$where = '1';
if(!empty($status)){
if($status == 1){
$where .= ' and status=1';
}
if($status == 2){
$where .= ' and status=0';
}
}
if(!empty($keyword)){
$where .= " and (`code` like '%$keyword%' or `email` like '%$keyword%')";
}
$conn = mysql_conn();
$result = mysqli_query($conn,"select * from invitation_code where $where limit ". ($page-1)*$limit . ',' . $limit);
$data = array();
while($row = mysqli_fetch_assoc($result)){
$data[] = $row;
}
if(!empty(implode(',',array_column($data,'email')))){
$token = get_ms_token($tenant_id,$client_id,$client_secret);
}
foreach($data as $k =>$v){
$data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
$data[$k]['update_time'] = date('Y-m-d H:i:s',$v['update_time']);
if(!empty($v['email'])){
!empty(account_status($v['email'],$token)) ? $data[$k]['account_status'] = 0 : $data[$k]['account_status'] = -1;
}
}
$count = mysqli_fetch_assoc(mysqli_query($conn,"select count(*) as `count` from invitation_code where $where"));
response(0,"获取邀请码列表成功",$data,$count['count']);
}
if($_GET['a'] == 'invitation_code_create'){
if(!check_login()){
response(1,"登录已失效");
}
$num = !empty($_POST['num']) ? intval($_POST['num']) : 0;
if($num <= 0){
response(1,"数量必须大于0");
}
$conn = mysql_conn();
$i = 0;
$total = $num;
$success = 0;
$error = 0;
while($i < $num){
$code = get_rand_number($admin['invitation_code_num']);
$time = time();
$result = mysqli_query($conn,"INSERT INTO `invitation_code`(`code`, `create_time`, `update_time`, `status`) VALUES ('$code',$time,$time, 0)");
if(!empty($result)){
$success++;
}else{
$error++;
}
$i++;
}
$data = [
'total'=>$total,
'success'=>$success,
'error'=>$error,
];
response(0,'生成成功',$data);
}
if($_GET['a'] == 'invitation_code_delete'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($tenant_id,$client_id,$client_secret);
$user_email = !empty($_POST['email']) ? $_POST['email'] : 0;
if($user_email){
$resultaccount = account_delete($user_email,$token);
}else{
$resultaccount = false;
}
$id = !empty($_POST['id']) ? intval($_POST['id']) : 0;
$conn = mysql_conn();
$resultsql = mysqli_query($conn,"DELETE FROM `invitation_code` WHERE `id` = $id");
if(!empty($resultsql) && $resultaccount){
response(0,"邀请码删除成功,用户账户删除成功");
}else if(!empty($resultsql)){
response(0,"邀请码删除成功,无用户或无权限删除账户");
}else{
response(1,"删除失败");
}
}
if($_GET['a'] == 'invitation_code_account_enable'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($tenant_id,$client_id,$client_secret);
$user_email = !empty($_POST['email']) ? $_POST['email'] : 0;
$result=account_enable($user_email,$token);
if(!empty($result)){
response(0,$user_email."允许失败");
}else{
response(1,$user_email."允许成功");
}
}
if($_GET['a'] == 'invitation_code_account_disable'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($tenant_id,$client_id,$client_secret);
$user_email = !empty($_POST['email']) ? $_POST['email'] : 0;
$result=accountin_disable($user_email,$token);
if(!empty($result)){
response(0,$user_email."禁用失败");
}else{
response(1,$user_email."成功禁用");
}
}