Add mobile API, change date format on task editor to work with HTML5 date pickers
This commit is contained in:
parent
01cbdb3a60
commit
3e0b18e14e
@ -213,7 +213,7 @@ function doLoginUser($username) {
|
||||
}
|
||||
|
||||
$resp = json_decode($response->getBody(), TRUE);
|
||||
var_dump($resp);
|
||||
|
||||
if ($resp['status'] == "OK") {
|
||||
$userinfo = $resp['data'];
|
||||
$_SESSION['username'] = $username;
|
||||
|
103
mobile/index.php
Normal file
103
mobile/index.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Mobile app API
|
||||
*/
|
||||
|
||||
require __DIR__ . "/../required.php";
|
||||
|
||||
require __DIR__ . "/../lib/login.php";
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Allow ping check without authentication
|
||||
if ($VARS['action'] == "ping") {
|
||||
exit(json_encode(["status" => "OK"]));
|
||||
}
|
||||
|
||||
function mobile_enabled() {
|
||||
$client = new GuzzleHttp\Client();
|
||||
|
||||
$response = $client
|
||||
->request('POST', PORTAL_API, [
|
||||
'form_params' => [
|
||||
'key' => PORTAL_KEY,
|
||||
'action' => "mobileenabled"
|
||||
]
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() > 299) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$resp = json_decode($response->getBody(), TRUE);
|
||||
if ($resp['status'] == "OK" && $resp['mobile'] === TRUE) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function mobile_valid($username, $code) {
|
||||
$client = new GuzzleHttp\Client();
|
||||
|
||||
$response = $client
|
||||
->request('POST', PORTAL_API, [
|
||||
'form_params' => [
|
||||
'key' => PORTAL_KEY,
|
||||
"code" => $code,
|
||||
"username" => $username,
|
||||
'action' => "mobilevalid"
|
||||
]
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() > 299) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$resp = json_decode($response->getBody(), TRUE);
|
||||
if ($resp['status'] == "OK" && $resp['valid'] === TRUE) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mobile_enabled() !== TRUE) {
|
||||
exit(json_encode(["status" => "ERROR", "msg" => lang("mobile login disabled", false)]));
|
||||
}
|
||||
|
||||
// Make sure we have a username and access key
|
||||
if (is_empty($VARS['username']) || is_empty($VARS['key'])) {
|
||||
http_response_code(401);
|
||||
die(json_encode(["status" => "ERROR", "msg" => "Missing username and/or access key."]));
|
||||
}
|
||||
|
||||
// Make sure the username and key are actually legit
|
||||
if (!mobile_valid($VARS['username'], $VARS['key'])) {
|
||||
engageRateLimit();
|
||||
http_response_code(401);
|
||||
die(json_encode(["status" => "ERROR", "msg" => "Invalid username and/or access key."]));
|
||||
}
|
||||
|
||||
// Process the action
|
||||
switch ($VARS['action']) {
|
||||
case "start_session":
|
||||
// Do a web login.
|
||||
if (user_exists($VARS['username'])) {
|
||||
if (get_account_status($VARS['username']) == "NORMAL") {
|
||||
if (authenticate_user($VARS['username'], $VARS['password'], $autherror)) {
|
||||
if (account_has_permission($VARS['username'], "TASKFLOOR")) {
|
||||
doLoginUser($VARS['username'], $VARS['password']);
|
||||
exit(json_encode(["status" => "OK"]));
|
||||
} else {
|
||||
exit(json_encode(["status" => "ERROR", "msg" => lang("no permission", false)]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)]));
|
||||
default:
|
||||
http_response_code(404);
|
||||
die(json_encode(["status" => "ERROR", "msg" => "The requested action is not available."]));
|
||||
}
|
@ -57,10 +57,10 @@ if (!is_empty($taskid) && $database->has('assigned_tasks', ['taskid' => $taskid]
|
||||
<?php lang("assigned to") ?>:
|
||||
<input type="text" id="assigned-to-box" name="assignedto" class="form-control" autocomplete="off" value="<?php echo (is_null($tass['userid']) ? "" : getUserByID($tass['userid'])['username'] ); ?>" placeholder="<?php lang("nobody") ?>" />
|
||||
<br />
|
||||
<?php lang("assigned on 2") ?>: <input type="date" class="form-control" id="assigned-on-box" name="taskassignedon" value="<?php echo $task['taskassignedon']; ?>" />
|
||||
<?php lang("assigned on 2") ?>: <input type="datetime-local" class="form-control" id="assigned-on-box" name="taskassignedon" value="<?php echo date('o-m-d\TH:i:s', strtotime($task['taskassignedon'])); ?>" />
|
||||
<p><i class="fa fa-info-circle"></i> <?php lang("use now tip") ?></p>
|
||||
<br />
|
||||
<?php lang("due by 2") ?>: <input type="date" class="form-control" id="due-by-box" name="taskdueby" value="<?php echo $task['taskdueby']; ?>"/>
|
||||
<?php lang("due by 2") ?>: <input type="datetime-local" class="form-control" id="due-by-box" name="taskdueby" value="<?php echo date('o-m-d\TH:i:s', strtotime($task['taskdueby'])); ?>"/>
|
||||
<br />
|
||||
<button id="savebtn" type="submit" class="btn btn-success"><i class="fa fa-floppy-o"></i> <?php lang("save task") ?></button>
|
||||
<a class="btn btn-warning" href="app.php?page=taskman"><i class="fa fa-times"></i> <?php lang("exit") ?></a>
|
||||
|
Loading…
x
Reference in New Issue
Block a user