Add basic group info APIs
This commit is contained in:
parent
29f4f9e9d3
commit
4ac39bd0d3
49
api.php
49
api.php
@ -305,6 +305,55 @@ switch ($VARS['action']) {
|
||||
}
|
||||
}
|
||||
exit(json_encode(["status" => "OK", "apps" => $apps]));
|
||||
case "getusersbygroup":
|
||||
if ($VARS['gid']) {
|
||||
if ($database->has("groups", ['groupid' => $VARS['gid']])) {
|
||||
$groupid = $VARS['gid'];
|
||||
} else {
|
||||
exit(json_encode(["status" => "ERROR", "msg" => lang("group does not exist", false)]));
|
||||
}
|
||||
} else {
|
||||
http_response_code(400);
|
||||
die("\"400 Bad Request\"");
|
||||
}
|
||||
if ($VARS['get'] == "username") {
|
||||
$users = $database->select('assigned_groups', ['[>]accounts' => ['uid' => 'uid']], 'username', ['groupid' => $groupid]);
|
||||
} else {
|
||||
$users = $database->select('assigned_groups', 'uid', ['groupid' => $groupid]);
|
||||
}
|
||||
exit(json_encode(["status" => "OK", "users" => $users]));
|
||||
break;
|
||||
case "getgroupsbyuser":
|
||||
if ($VARS['uid']) {
|
||||
if ($database->has("accounts", ['uid' => $VARS['uid']])) {
|
||||
$empid = $VARS['uid'];
|
||||
} else {
|
||||
exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false)]));
|
||||
}
|
||||
} else if ($VARS['username']) {
|
||||
if ($database->has("accounts", ['username' => strtolower($VARS['username'])])) {
|
||||
$empid = $database->select('accounts', 'uid', ['username' => strtolower($VARS['username'])]);
|
||||
} else {
|
||||
exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false)]));
|
||||
}
|
||||
} else {
|
||||
http_response_code(400);
|
||||
die("\"400 Bad Request\"");
|
||||
}
|
||||
$groups = $database->select('assigned_groups', ["[>]groups" => ["groupid" => "groupid"]], ['groups.groupid (id)', 'groups.groupname (name)'], ['uid' => $empid]);
|
||||
exit(json_encode(["status" => "OK", "groups" => $groups]));
|
||||
break;
|
||||
case "getgroups":
|
||||
$groups = $database->select('groups', ['groupid (id)', 'groupname (name)']);
|
||||
exit(json_encode(["status" => "OK", "groups" => $groups]));
|
||||
break;
|
||||
case "groupsearch":
|
||||
if (is_empty($VARS['search']) || strlen($VARS['search']) < 2) {
|
||||
exit(json_encode(["status" => "OK", "result" => []]));
|
||||
}
|
||||
$data = $database->select('groups', ['groupid (id)', 'groupname (name)'], ['groupname[~]' => $VARS['search'], "LIMIT" => 10]);
|
||||
exit(json_encode(["status" => "OK", "result" => $data]));
|
||||
break;
|
||||
default:
|
||||
http_response_code(404);
|
||||
die(json_encode("404 Not Found: the requested action is not available."));
|
||||
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
-- MySQL Script generated by MySQL Workbench
|
||||
-- Mon 18 Dec 2017 12:56:23 AM MST
|
||||
-- Thu 21 Dec 2017 01:19:57 AM MST
|
||||
-- Model: New Model Version: 1.0
|
||||
-- MySQL Workbench Forward Engineering
|
||||
|
||||
@ -123,7 +123,7 @@ ENGINE = InnoDB;
|
||||
-- Table `accounthub`.`groups`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `accounthub`.`groups` (
|
||||
`groupid` INT NOT NULL,
|
||||
`groupid` INT NOT NULL AUTO_INCREMENT,
|
||||
`groupname` VARCHAR(45) NOT NULL,
|
||||
PRIMARY KEY (`groupid`),
|
||||
UNIQUE INDEX `groupid_UNIQUE` (`groupid` ASC),
|
||||
|
@ -12,3 +12,6 @@ CREATE TABLE IF NOT EXISTS `onetimekeys` (
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8
|
||||
|
||||
ALTER TABLE `groups`
|
||||
CHANGE COLUMN `groupid` `groupid` INT(11) NOT NULL AUTO_INCREMENT
|
Loading…
x
Reference in New Issue
Block a user