Commit 80fb28a3 authored by nickchen's avatar nickchen 🎨

up: 下載備份檔名為vault的name

up: 金鑰啟用方式
parent 762a9e69
......@@ -19,6 +19,7 @@ using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using System.IO;
using DocumentFormat.OpenXml.Wordprocessing;
namespace backstage.Controllers
{
......@@ -527,5 +528,71 @@ namespace backstage.Controllers
return result;
}
/// <summary>
/// 啟用KEY ajax
/// </summary>
/// <returns></returns>
[Authorize(Policy = "AdminOnly")]
[HttpPost]
public async Task<ResultModel> EnableKey(string keyId)
{
var result = new ResultModel();
string msg;
var url = _config["IP"] + "/security/key";
var httpMethod = HttpMethod.Put;
var parameters = new Dictionary<string, string>
{
{ "id", keyId.ToString()},
{ "active", "1"},
};
var apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
if (apiResult.IsSuccess)
{
try
{
var Response = JsonConvert.DeserializeObject<Response>(apiResult.Data.ToString());
if (Response.r == 0)
{
switch (_currentLanguage)
{
case "en":
msg = "Enable key success.";
break;
case "zh":
msg = "啟用成功";
break;
default:
msg = "啟用成功";
break;
}
result.IsSuccess = true;
result.Message = msg;
return result;
}
else
{
result.IsSuccess = false;
result.Message = Response.m.ToString();
return result;
}
}
catch (Exception e)
{
result.IsSuccess = false;
result.Message = e.Message + e.InnerException?.Message;
return result;
}
}
result.IsSuccess = false;
result.Message = apiResult.Message;
return result;
}
}
}
\ No newline at end of file
......@@ -26,6 +26,7 @@ using TokenVault_management.Models;
using Microsoft.Extensions.Localization;
using Microsoft.AspNetCore.Localization;
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.EntityFrameworkCore.Internal;
namespace backstage.Controllers
{
......@@ -2348,16 +2349,57 @@ namespace backstage.Controllers
// 取得使用者的 "token" Claim 值
string token = User.FindFirstValue("token");
string msg;
string fileName;
var url = _config["IP"] + "/v2/vault/entry/backup";
var url = _config["IP"] + "/v2/vault/get";
var httpMethod = HttpMethod.Post;
var parameters = new Dictionary<string, string>
{
{ "vault_id",vault_id.ToString()},
{ "merchant_id",merchant_id.ToString()}
};
var apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
{ "id", vault_id.ToString()},
{ "Merchant_id", merchant_id.ToString()},
{ "info", "INFO"}
};
var apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
if (apiResult.IsSuccess)
{
try
{
var response = JsonConvert.DeserializeObject<Response>(apiResult.Data.ToString());
if (response.r == 0)
{
var vaultInfoList = JsonConvert.DeserializeObject<List<TokenVault>>(response.info.ToString());
fileName = vaultInfoList[0].name;
}
else
{
result.IsSuccess = false;
result.Message = response.m.ToString();
return result;
}
}
catch (Exception e)
{
result.IsSuccess = false;
result.Message = e.Message;
return result;
}
}
else
{
result.IsSuccess = false;
result.Message = apiResult.Message;
return result;
}
url = _config["IP"] + "/v2/vault/entry/backup";
parameters = new Dictionary<string, string>
{
{ "vault_id", vault_id.ToString()},
{ "merchant_id", merchant_id.ToString()}
};
apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
if (apiResult.IsSuccess)
{
try
......@@ -2369,7 +2411,7 @@ namespace backstage.Controllers
var resultData = new
{
fileName = "vault.json",
fileName = fileName,
json = jsonRe
};
......@@ -2381,21 +2423,21 @@ namespace backstage.Controllers
else
{
result.IsSuccess = false;
result.Message = "error.";
return result;
result.Message = response.m.ToString();
return result;
}
}
catch (Exception e)
{
result.IsSuccess = false;
result.Message = "error.";
result.Message = e.Message;
return result;
}
}
else
{
result.IsSuccess = false;
result.Message = "error.";
result.Message = apiResult.Message;
return result;
}
}
......
......@@ -16,6 +16,7 @@ namespace TokenVault_management.Models
public string[] QRData { get; set; }
public string[] error { get; set; }
public string flags { get; set; }
public Object info { get; set; }
public List<string> failInfo { get; set; }
}
......
......@@ -60,14 +60,14 @@
<div class="table-responsive">
<!--交易紀錄列表 table-->
<table class="table table-striped TBL_keysList">
<table class="table table-striped TBL_keysList" style="display: none;">
<thead>
<tr>
<th style=" border-left: solid 0.1px #d9d9d9;">@Localizer["ID"]</th>
<th>@Localizer["Name"]</th>
<th>@Localizer["Encryption"]</th>
<th>@Localizer["Last Update"]</th>
<th>@Localizer["Status"]</th>
<th>@Localizer["Enable"]</th>
<th>@Localizer["Expiration"]</th>
<th>@Localizer["Revise"]</th>
<th style=" border-right: solid 0.1px #d9d9d9;">@Localizer["Delete"]</th>
......@@ -86,7 +86,10 @@
<td>@k.name</td>
<td>@k.encryption</td>
<td>@k.lastUpdate</td>
<td>@(k.active==1?"In use":"")</td>
<td><!--@(k.active==1?"In use":"")-->
<input type="checkbox" class="isEnable" data-k_id="@k.id" @(k.active == 1 ? "disabled checked" : "")>
</td>
<td>@k.expiration</td>
<td>
<a class="reviseKeyBtn" data-keyid="@k.id" data-keyname="@k.name" data-active="@k.active" data-deletable="@k.deleteable" data- data-toggle="modal" data-target="#editApp" title="Revise">
......@@ -95,7 +98,12 @@
</a>
</td>
<td>
<a @(k.deleteable == 1 ? "" : "hidden") class="deleteKeyBtn" data-keyid="@k.id" data-toggle="modal" data-target="#deleteProject" title="Delete" disable>
@*<a @(k.deleteable == 1 && k.active != 1 ? "" : "hidden") class="deleteKeyBtn @(k.deleteable == 1 ? "deletable" : "")" data-keyid="@k.id" data-toggle="modal" data-target="#deleteProject" title="Delete" disable>
<i class="fa-solid fa-trash-can"></i>
</a>*@
<a class="deleteKeyBtn" data-keyid="@k.id" data-toggle="modal" data-target="#deleteProject" title="Delete" @(k.deleteable == 1 ? "" : "hidden")>
<i class="fa-solid fa-trash-can"></i>
</a>
......@@ -256,8 +264,8 @@
<div class="form-group">
@*<label class="control-label" for=""></label>*@
@*<div class="form-check form-check-inline">*@
<label class="form-check-label label-space" for="uniqueY">@Localizer["Active"]</label>
<input class="form-check-input" type="checkbox" id="is_enable" name="active" value="1">
@*<label class="form-check-label label-space" for="uniqueY">@Localizer["Active"]</label>
<input class="form-check-input" type="checkbox" id="is_enable" name="active" value="1">*@
@*</div>*@
......@@ -514,7 +522,7 @@
$('#edit_key_name').val($(this).data('keyname'));
var active = $(this).data('active');
var deletable = $(this).data('deletable');
console.log('active=' + active);
//console.log('active=' + active);
$('#is_enable').prop('checked', active == "1"); // 根據active的值設置#is_enable的選擇狀態
$('#deletableKey').prop('checked', deletable == "1");
});
......@@ -551,7 +559,55 @@
});
$('.isEnable').bootstrapSwitch({
onText: 'ON',
offText: 'OFF',
onColor: 'success',
offColor: 'danger',
size: 'mini',
onInit: function () {
// 初始化完成時的操作
// 例如顯示表格等
$('.table').show();
},
onSwitchChange: function (event, state) {
if (state == true){
let kId = $(this).data('k_id');
let thisEnable = $(this);
console.log(thisEnable.parents('tr'));
// 使用 AJAX 發送請求,處理狀態變更事件
$.ajax({
url: '/Key/EnableKey',
type: 'POST',
data: {
keyId: kId
},
success: function (response) {
// 在成功回調中處理回應
showAlert(response.isSuccess, response.message)
//ui控制
if (response.isSuccess){
$('.isEnable').bootstrapSwitch('disabled', false);
$('.isEnable').not(thisEnable).bootstrapSwitch('state', false);
thisEnable.bootstrapSwitch('disabled', true);
//$('.deletable').removeAttr("hidden");
//thisEnable.parents('tr').find('.deletable').attr("hidden", true);
}else{
thisEnable.bootstrapSwitch('state', false);
}
},
error: function (xhr) {
thisEnable.bootstrapSwitch('state', false);
showAlert(false, xhr.responseText)
console.log(xhr);
}
});
}
}
});
})
......
......@@ -81,28 +81,11 @@
@*<td>@i.locked</td>*@
<td>@i.creation_date</td>
<td>
@if (i.uid == 1)
{
<input type="checkbox" data-uid="@i.uid" class="toggleButton isEnable" @(i.enabled == 1 ? "checked" : "") disabled>
}
else
{
<input type="checkbox" data-uid="@i.uid" class="toggleButton isEnable" @(i.enabled == 1 ? "checked" : "")>
}
<input type="checkbox" data-uid="@i.uid" class="toggleButton isEnable" @(i.enabled == 1 ? "checked" : "") @(i.uid == 1 ? "disabled" : "") >
</td>
<td>
@if (i.uid == 1)
{
<input type="checkbox" data-uid="@i.uid" class="toggleButton isAdmin" @(i.isAdmin ? "checked" : "") disabled>
}
else
{
<input type="checkbox" data-uid="@i.uid" class="toggleButton isAdmin" @(i.isAdmin ? "checked" : "")>
}
<input type="checkbox" data-uid="@i.uid" class="toggleButton isAdmin" @(i.isAdmin ? "checked" : "") @(i.uid == 1 ? "disabled" : "") >
</td>
@*@if (i.isAdmin)
{ <td>是</td>}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment