Tokens can now be reset
This commit is contained in:
parent
9bb2a3fd3d
commit
5b098c8fca
@ -188,12 +188,17 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
|
|||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr id="token-<?php echo $row['id']; ?>-created" class="success hide">
|
||||||
<td colspan="4" id="token-<?php echo $row['id']; ?>-created" class="success hide">
|
<td colspan="4">
|
||||||
Generated Token: <code class="token"></code>
|
Generated Token: <code class="token"></code>
|
||||||
<p><b>NOTE:</b> Please record this token, as this is the only time you will be able to view it!</p>
|
<p><b>NOTE:</b> Please record this token, as this is the only time you will be able to view it!</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr id="token-<?php echo $row['id']; ?>-reset" class="success hide">
|
||||||
|
<td colspan="4">
|
||||||
|
<p>All tokens for this user have been removed!</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
endforeach;
|
endforeach;
|
||||||
?>
|
?>
|
||||||
|
@ -34,7 +34,8 @@ if ($request_method == 'POST') {
|
|||||||
output($token);
|
output($token);
|
||||||
return http_response_code(200);
|
return http_response_code(200);
|
||||||
} elseif ($action == 'reset') {
|
} elseif ($action == 'reset') {
|
||||||
//TODO
|
reset_tokens($user_id, $hesk_settings);
|
||||||
|
return http_response_code(204);
|
||||||
} else {
|
} else {
|
||||||
return http_response_code(400);
|
return http_response_code(400);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
function store_token($user_id, $token_hash, $hesk_settings) {
|
function store_token($user_id, $token_hash, $hesk_settings) {
|
||||||
$sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "user_api_tokens` (`user_id`, `token`)
|
$sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "user_api_tokens` (`user_id`, `token`)
|
||||||
VALUES ('" . hesk_dbEscape($user_id) . "', '" . hesk_dbEscape($token_hash) . "')";
|
VALUES (" . intval($user_id) . ", '" . hesk_dbEscape($token_hash) . "')";
|
||||||
|
hesk_dbQuery($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset_tokens($user_id, $hesk_settings) {
|
||||||
|
$sql = "DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "user_api_tokens` WHERE `user_id` = ".intval($user_id);
|
||||||
hesk_dbQuery($sql);
|
hesk_dbQuery($sql);
|
||||||
}
|
}
|
@ -69,6 +69,8 @@ function generateToken(userId) {
|
|||||||
var endpoint = getHelpdeskUrl();
|
var endpoint = getHelpdeskUrl();
|
||||||
endpoint += '/internal-api/admin/api-authentication/';
|
endpoint += '/internal-api/admin/api-authentication/';
|
||||||
markSaving('token-' + userId);
|
markSaving('token-' + userId);
|
||||||
|
$('#token-' + userId + '-reset').addClass('hide');
|
||||||
|
$('#token-' + userId + '-created').addClass('hide');
|
||||||
var data = {
|
var data = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
action: 'generate'
|
action: 'generate'
|
||||||
@ -78,7 +80,7 @@ function generateToken(userId) {
|
|||||||
data: data,
|
data: data,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
$('#token-' + userId + '-created > .token').text(data);
|
$('#token-' + userId + '-created > td > .token').text(data);
|
||||||
$('#token-' + userId + '-created').removeClass('hide');
|
$('#token-' + userId + '-created').removeClass('hide');
|
||||||
markSuccess('token-' + userId);
|
markSuccess('token-' + userId);
|
||||||
var oldNumberOfTokens = parseInt($('#token-' + userId + '-count').text());
|
var oldNumberOfTokens = parseInt($('#token-' + userId + '-count').text());
|
||||||
@ -92,5 +94,27 @@ function generateToken(userId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearTokens(userId) {
|
function clearTokens(userId) {
|
||||||
alert(userId);
|
var endpoint = getHelpdeskUrl();
|
||||||
|
endpoint += '/internal-api/admin/api-authentication/';
|
||||||
|
markSaving('token-' + userId);
|
||||||
|
$('#token-' + userId + '-reset').addClass('hide');
|
||||||
|
$('#token-' + userId + '-created').addClass('hide');
|
||||||
|
var data = {
|
||||||
|
userId: userId,
|
||||||
|
action: 'reset'
|
||||||
|
};
|
||||||
|
$.ajax({
|
||||||
|
url: endpoint,
|
||||||
|
data: data,
|
||||||
|
method: 'POST',
|
||||||
|
success: function() {
|
||||||
|
$('#token-' + userId + '-reset').removeClass('hide');
|
||||||
|
$('#token-' + userId + '-count').text('0');
|
||||||
|
markSuccess('token-' + userId);
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
console.error(data);
|
||||||
|
markFailure('token-' + userId);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user