-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_controller.php
65 lines (54 loc) · 2.04 KB
/
account_controller.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
<?php
function account_controller() {
global $route, $session, $mysqli, $redis, $user;
require_once("Modules/account/account_model.php");
$account_class = new Accounts($mysqli, $redis, $user);
// Redirect to switch
if ($route->action == "list" && isset($_SESSION['adminuser'])) {
$route->action = "switch";
}
// List linked accounts
// GET /account/list
// GET /account/list.json
if ($route->action == "list" && $session["write"]) {
if ($route->format == 'html') {
return view("Modules/account/account_view.php",array());
} else {
$route->format = 'json';
return $account_class->list($session["userid"]);
}
}
// Add account
// POST /account/add.json (post body: username, password)
if ($route->action == "add" && $session["write"]) {
$username = post("username",true);
$password = post("password",true);
$email = post("email",true);
$timezone = post("timezone",true);
$result = $account_class->add($session["userid"],$username,$password,$email,$timezone);
$route->format = 'json';
return $result;
}
// Unlink account
// GET /account/unlink.json (get body: userid)
if ($route->action == "unlink" && $session["write"]) {
$route->format = 'json';
$userid = post("userid",true);
return $account_class->unlink($session["userid"],$userid);
}
// Switch user
// GET /account/switch.json?userid=123
if ($route->action == "switch" && $session["write"]) {
$route->format = 'json';
$userid = get("userid",false);
return $account_class->switch($session["userid"],$userid);
}
// Set access
// POST /account/access.json (post body: userid, access)
if ($route->action == "setaccess" && $session["write"]) {
$route->format = 'json';
$userid = post("userid",true);
$access = post("access",true);
return $account_class->set_access($session["userid"],$userid,$access);
}
}