finish token manager
This commit is contained in:
@@ -24,6 +24,31 @@ div.user-item-icon {
|
||||
|
||||
|
||||
|
||||
div.token-item {
|
||||
display: flex;
|
||||
flex-flow: row;
|
||||
align-items: flex-start;
|
||||
|
||||
padding: 1.25rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
div.token-item-words {
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
align-items: flex-start;
|
||||
flex-grow: 1;
|
||||
flex-basis: 0;
|
||||
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
div.token-item-icon {
|
||||
margin-left: 0.75rem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
div.control-list {
|
||||
display: flex;
|
||||
|
||||
@@ -134,4 +134,5 @@ ccn-i18n-userItem-isAdmin=Is Admin
|
||||
|
||||
ccn-i18n-tokenItem-ua=User Agent:
|
||||
ccn-i18n-tokenItem-ip=IP:
|
||||
ccn-i18n-tokenItem-expireOn=Expire On:
|
||||
ccn-i18n-tokenItem-isMe=This is the login credentials you are currently using.
|
||||
|
||||
@@ -134,4 +134,5 @@ ccn-i18n-userItem-isAdmin=是管理员
|
||||
|
||||
ccn-i18n-tokenItem-ua=UA:
|
||||
ccn-i18n-tokenItem-ip=IP:
|
||||
ccn-i18n-tokenItem-expireOn=过期时间:
|
||||
ccn-i18n-tokenItem-isMe=这是你当前使用的登录凭据
|
||||
|
||||
@@ -179,25 +179,6 @@ function ccn_api_common_tokenValid() {
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_api_common_isAdmin() {
|
||||
return ccn_api_boolTemplate(
|
||||
'/api/common/isAdmin',
|
||||
{
|
||||
token: ccn_localstorageAssist_GetApiToken()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function ccn_api_common_changePassword(_password) {
|
||||
return ccn_api_boolTemplate(
|
||||
'/api/common/changePassword',
|
||||
{
|
||||
token: ccn_localstorageAssist_GetApiToken(),
|
||||
password: _password
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// ====================================================== calendar
|
||||
|
||||
function ccn_api_calendar_getFull(_startDateTime, _endDateTime) {
|
||||
@@ -461,3 +442,42 @@ function ccn_api_admin_delete(_username) {
|
||||
);
|
||||
}
|
||||
|
||||
// ====================================================== profile
|
||||
|
||||
function ccn_api_profile_isAdmin() {
|
||||
return ccn_api_boolTemplate(
|
||||
'/api/profile/isAdmin',
|
||||
{
|
||||
token: ccn_localstorageAssist_GetApiToken()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function ccn_api_profile_changePassword(_password) {
|
||||
return ccn_api_boolTemplate(
|
||||
'/api/profile/changePassword',
|
||||
{
|
||||
token: ccn_localstorageAssist_GetApiToken(),
|
||||
password: _password
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function ccn_api_profile_getToken() {
|
||||
return ccn_api_boolTemplate(
|
||||
'/api/profile/getToken',
|
||||
{
|
||||
token: ccn_localstorageAssist_GetApiToken()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function ccn_api_profile_deleteToken(_deleteToken) {
|
||||
return ccn_api_boolTemplate(
|
||||
'/api/profile/deleteToken',
|
||||
{
|
||||
token: ccn_localstorageAssist_GetApiToken(),
|
||||
deleteToken: _deleteToken
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var ccn_admin_userListCache = [];
|
||||
var ccn_admin_tokenListCache = [];
|
||||
|
||||
$(document).ready(function() {
|
||||
ccn_pages_currentPage = ccn_pages_enumPages.admin;
|
||||
@@ -28,7 +29,7 @@ $(document).ready(function() {
|
||||
ccn_tabcontrol_SwitchTab(1, 1);
|
||||
|
||||
// load user tab according to admin status
|
||||
if(!ccn_api_common_isAdmin())
|
||||
if(!ccn_api_profile_isAdmin())
|
||||
$('#tabcontrol-tab-1-3').hide();
|
||||
|
||||
// apply i18n
|
||||
@@ -37,6 +38,7 @@ $(document).ready(function() {
|
||||
|
||||
// bind event
|
||||
$('#ccn-admin-profile-btnChangePassword').click(ccn_admin_profile_ChangePassword);
|
||||
$('#ccn-admin-tokenList-btnRefresh').click(ccn_admin_tokenList_Refresh);
|
||||
$('#ccn-admin-userList-btnAdd').click(ccn_admin_userList_Add);
|
||||
$('#ccn-admin-userList-btnRefresh').click(ccn_admin_userList_Refresh);
|
||||
});
|
||||
@@ -47,7 +49,7 @@ function ccn_admin_profile_ChangePassword() {
|
||||
var newpassword = $('#ccn-admin-profile-inputPassword').val();
|
||||
if (newpassword == "") return;
|
||||
|
||||
var result = ccn_api_common_changePassword(newpassword);
|
||||
var result = ccn_api_profile_changePassword(newpassword);
|
||||
if(result) {
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-success"));
|
||||
$('#ccn-admin-profile-inputPassword').val('');
|
||||
@@ -56,6 +58,61 @@ function ccn_admin_profile_ChangePassword() {
|
||||
|
||||
}
|
||||
|
||||
// ================== token
|
||||
|
||||
function ccn_admin_tokenList_Refresh() {
|
||||
ccn_admin_tokenListCache = new Array();
|
||||
var listDOM = $('#ccn-admin-tokenList');
|
||||
listDOM.empty();
|
||||
|
||||
var renderdata = {
|
||||
uuid: undefined,
|
||||
isMe: undefined,
|
||||
ua: undefined,
|
||||
ip: undefined,
|
||||
expireOn: undefined
|
||||
}
|
||||
var gottenDateTime = new Date();
|
||||
|
||||
var result = ccn_api_profile_getToken();
|
||||
if(typeof(result) != 'undefined') {
|
||||
for(var index in result) {
|
||||
var item = result[index];
|
||||
renderdata.uuid = item[1];
|
||||
renderdata.isMe = ccn_localstorageAssist_GetApiToken() == item[1];
|
||||
renderdata.ua = item[3];
|
||||
renderdata.ip = item[4];
|
||||
gottenDateTime.setTime(item[2] * 1000);
|
||||
renderdata.expireOn = gottenDateTime.toLocaleString();
|
||||
|
||||
listDOM.append(ccn_template_tokenItem.render(renderdata));
|
||||
|
||||
// bind event
|
||||
var uuid = renderdata.uuid;
|
||||
$("#ccn-tokenItem-btnLogout-" + uuid).click(ccn_admin_tokenList_ItemDelete);
|
||||
|
||||
// add into cache
|
||||
ccn_admin_tokenListCache[uuid] = item;
|
||||
}
|
||||
|
||||
ccn_i18n_ApplyLanguage2Content(listDOM);
|
||||
}
|
||||
}
|
||||
|
||||
function ccn_admin_tokenList_ItemDelete() {
|
||||
var uuid = $(this).attr("uuid");
|
||||
|
||||
var result = ccn_api_profile_deleteToken(uuid);
|
||||
|
||||
if(!result) {
|
||||
// fail
|
||||
ccn_messagebox_Show($.i18n.prop("ccn-i18n-js-fail-delete"));
|
||||
} else {
|
||||
// remove body
|
||||
$("#ccn-tokenItem-" + uuid).remove();
|
||||
}
|
||||
}
|
||||
|
||||
// ================== user list
|
||||
|
||||
function ccn_admin_userList_RefreshCacheList() {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
<div id="ccn-tokenItem-{{:uuid}}" class="token-item card">
|
||||
<div class="token-item-words">
|
||||
<b>{{>token}}</b>
|
||||
{{if isMe}}
|
||||
<p i18n-name="ccn-i18n-tokenItem-isMe"></p>
|
||||
{{/if}}
|
||||
<b>{{>uuid}}</b>
|
||||
<p>
|
||||
<span i18n-name="ccn-i18n-tokenItem-ua"></span>
|
||||
<span>{{>ua}}</span>
|
||||
@@ -12,6 +9,16 @@
|
||||
<span i18n-name="ccn-i18n-tokenItem-ip"></span>
|
||||
<span>{{>ip}}</span>
|
||||
</p>
|
||||
<p>
|
||||
<span i18n-name="ccn-i18n-tokenItem-expireOn"></span>
|
||||
<span>{{>expireOn}}</span>
|
||||
</p>
|
||||
{{if isMe}}
|
||||
<p>
|
||||
<span class="icon is-small"><i class="fas fa-exclamation-triangle"></i></span>
|
||||
<span i18n-name="ccn-i18n-tokenItem-isMe"></span>
|
||||
</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div id="ccn-tokenItem-btnLogout-{{:uuid}}" uuid="{{:uuid}}" class="token-item-icon control">
|
||||
|
||||
Reference in New Issue
Block a user