Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
TokenVaultManagement
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jasonwai
TokenVaultManagement
Commits
bb57d8fc
Commit
bb57d8fc
authored
Jul 06, 2023
by
nickchen
🎨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: vault 備份還原
parent
574bb94e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
221 additions
and
73 deletions
+221
-73
TokenVaultController .cs
...Management/backstage/Controllers/TokenVaultController .cs
+88
-26
Response.cs
Merchant Token Vault Management/backstage/Models/Response.cs
+2
-1
List.zh.resx
...agement/backstage/Resources/Views/TokenVault/List.zh.resx
+9
-0
ListKeys.cshtml
...oken Vault Management/backstage/Views/Key/ListKeys.cshtml
+3
-3
List.cshtml
...n Vault Management/backstage/Views/TokenVault/List.cshtml
+119
-43
No files found.
Merchant Token Vault Management/backstage/Controllers/TokenVaultController .cs
View file @
bb57d8fc
...
...
@@ -1883,15 +1883,15 @@ namespace backstage.Controllers
<
td
>
<
button
class
=""
btn
btnPermission
btn
-
sm
permissionBtn
""
data
-
merchant_id
=
""
{
merchantId
}
""
data
-
vault_id
=
""
{
vault
.
vault_id
}
""
>{
permission
}</
button
>
<
button
class
=""
btn
btnPermission
btn
-
sm
fieldsBtn
""
data
-
merchant_id
=
""
{
merchantId
}
""
data
-
vault_id
=
""
{
vault
.
vault_id
}
""
>{
Fields
}</
button
>
<
button
class
=""
btn
btnPermission
btn
-
sm
backupBtn
""
data
-
toggle
=
""
modal
""
data
-
target
=
""
#
backup
-
modal
""
data
-
merchant_id
=
""
{
merchantId
}
""
data
-
vault_id
=
""
{
vault
.
vault_id
}
""
data
-
vault_name
=
""
{
vault
.
name
}
""
>{
backup
}</
button
>
<
button
class
=""
btn
btnPermission
btn
-
sm
restituteBtn
""
data
-
toggle
=
""
modal
""
data
-
target
=
""
#
restitute
-
modal
""
data
-
merchant_id
=
""
{
merchantId
}
""
data
-
vault_id
=
""
{
vault
.
vault_id
}
""
>{
restitute
}</
button
>
</
td
>
<
td
>{
vault
.
tokenCount
}</
td
>
<
td
>{
vault
.
userCount
}</
td
>
</
tr
>
";
outputHtml
+=
htmlCode
;
//<button class=""btn btnPermission btn-sm backupBtn"" data-toggle=""modal"" data-target=""#backup-modal"" data-merchant_id=""{merchantId}"" data-vault_id=""{vault.vault_id}"" data-vault_name=""{vault.name}"">{backup}</button>
//<button class=""btn btnPermission btn-sm restituteBtn"" data-merchant_id=""{merchantId}"" data-vault_id=""{vault.vault_id}"" >{restitute}</button>
}
return
Content
(
outputHtml
);
}
...
...
@@ -2362,42 +2362,104 @@ namespace backstage.Controllers
try
{
var
response
=
JsonConvert
.
DeserializeObject
<
Response
>(
apiResult
.
Data
.
ToString
());
var
jsonRe
=
JsonConvert
.
SerializeObject
(
response
.
d
);
var
resultData
=
new
if
(
response
.
r
==
0
)
{
fileName
=
"vault.json"
,
json
=
jsonRe
};
var
jsonRe
=
JsonConvert
.
SerializeObject
(
response
.
d
);
result
.
IsSuccess
=
true
;
result
.
Message
=
"Success."
;
result
.
Data
=
resultData
;
return
result
;
var
resultData
=
new
{
fileName
=
"vault.json"
,
json
=
jsonRe
};
result
.
IsSuccess
=
true
;
result
.
Message
=
"Success."
;
result
.
Data
=
resultData
;
return
result
;
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
"error."
;
return
result
;
}
}
catch
(
Exception
e
)
{
result
.
IsSuccess
=
false
;
result
.
Message
=
"error."
;
return
result
;
}
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
"error."
;
return
result
;
}
}
var
data
=
new
[]
{
new
{
Id
=
1
,
Name
=
"John"
},
new
{
Id
=
2
,
Name
=
"Jane"
}
};
// 取得要匯出的資料
var
json
=
JsonConvert
.
SerializeObject
(
data
);
// 將資料序列化為JSON字串
var
bytes
=
Encoding
.
UTF8
.
GetBytes
(
json
);
// 將JSON字串轉換為位元組陣列
/// <summary>
/// 備份vault ajax
/// </summary>
/// <param name="vault_id"></param>
/// <param name="merchant_id"></param>
/// <returns></returns>
[
Authorize
(
Policy
=
"AdminOnly"
)]
[
HttpPost
]
public
async
Task
<
ResultModel
>
Restitute
(
int
vault_id
,
int
merchant_id
,
string
json
)
{
var
result
=
new
ResultModel
();
// 取得使用者的 "token" Claim 值
string
token
=
User
.
FindFirstValue
(
"token"
);
string
msg
;
var
fileName
=
"data.json"
;
var
url
=
_config
[
"IP"
]
+
"/v2/vault/entry/restitute"
;
var
httpMethod
=
HttpMethod
.
Post
;
//return File(bytes, "application/json", fileName); // 回傳檔案結果
return
new
ResultModel
();
}
var
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"vault_id"
,
vault_id
.
ToString
()},
{
"merchant_id"
,
merchant_id
.
ToString
()},
{
"data"
,
json
}
};
var
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
try
{
var
response
=
JsonConvert
.
DeserializeObject
<
Response
>(
apiResult
.
Data
.
ToString
());
if
(
response
.
r
==
0
)
{
result
.
IsSuccess
=
true
;
result
.
Message
=
"Success."
;
result
.
Data
=
response
.
error
;
return
result
;
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
"error."
;
return
result
;
}
}
catch
(
Exception
ex
)
{
result
.
IsSuccess
=
false
;
result
.
Message
=
"error."
;
return
result
;
}
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
"error."
;
return
result
;
}
}
}
...
...
Merchant Token Vault Management/backstage/Models/Response.cs
View file @
bb57d8fc
...
...
@@ -14,7 +14,8 @@ namespace TokenVault_management.Models
public
Object
data
{
get
;
set
;
}
public
Object
d
{
get
;
set
;
}
public
string
[]
QRData
{
get
;
set
;
}
public
string
flags
{
get
;
set
;
}
public
string
[]
error
{
get
;
set
;
}
public
string
flags
{
get
;
set
;
}
public
List
<
string
>
failInfo
{
get
;
set
;
}
}
...
...
Merchant Token Vault Management/backstage/Resources/Views/TokenVault/List.zh.resx
View file @
bb57d8fc
...
...
@@ -120,6 +120,12 @@
<data
name=
"Choose department"
xml:space=
"preserve"
>
<value>
選擇部門
</value>
</data>
<data
name=
"Choose file"
xml:space=
"preserve"
>
<value>
選擇檔案
</value>
</data>
<data
name=
"Close"
xml:space=
"preserve"
>
<value>
關閉
</value>
</data>
<data
name=
"Create Token Vault"
xml:space=
"preserve"
>
<value>
新增代碼庫
</value>
</data>
...
...
@@ -135,6 +141,9 @@
<data
name=
"ID"
xml:space=
"preserve"
>
<value>
編號
</value>
</data>
<data
name=
"Log"
xml:space=
"preserve"
>
<value>
日誌
</value>
</data>
<data
name=
"Manage"
xml:space=
"preserve"
>
<value>
管理
</value>
</data>
...
...
Merchant Token Vault Management/backstage/Views/Key/ListKeys.cshtml
View file @
bb57d8fc
...
...
@@ -453,7 +453,7 @@
//新增鑰匙
$("#CreateKey").on("click", function (e) {
$('#newApp').modal('hide');
var keyName = $('#key_name').val();
$.ajax({
url: "/Key/CreateKey",
...
...
@@ -461,11 +461,11 @@
data: { key_name: keyName},
success: function (response) {
// API 呼叫成功的處理程式碼
console.log('response=' + JSON.stringify( response));
//
console.log('response=' + JSON.stringify( response));
showAlert(response.isSuccess, response.message)
if (response.isSuccess) {
$('#newApp').modal('hide');
let key1 = response.data[0];
let key2 = response.data[1];
console.log(key1);
...
...
Merchant Token Vault Management/backstage/Views/TokenVault/List.cshtml
View file @
bb57d8fc
...
...
@@ -103,41 +103,63 @@
</div>
</div>
<!-- START MODAL -->
<!-- START Backup Modal -->
<div class="modal fade modal-full" id="backup-modal" role="dialog" tabindex="-1" style="padding-right: 17px;" aria-modal="true">
<div class="modal-dialog modalforMemberGo">
<!-- Modal content-->
<div class="modal-content">
<!--START of div "modal-header"-->
<div class="modal-header">
<h3 class="modal-title">
Backup
</h3>
<h3 class="modal-title">Backup</h3>
</div>
<!--END of div "modal-header"-->
<!--START of div "modal-body"-->
<div class="modal-body" style="padding-top:35px; padding-bottom: 35px">
<form>
<p class="modal-body-title">下載備份檔到本機</p>
<p>下載備份檔到本機</p>
<div class="SubmitBlock SubmitBlock_sm">
<button type="button" id="backupConfirm" class="btn btn-mainblue-solid" data-dismiss="modal" style=""> @Localizer["Confirm"]</button>
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal" style=""> @Localizer["Cancel"]</button>
<p class="modal-body-title">下載備份檔到本機</p>
<p>下載備份檔到本機</p>
<div class="SubmitBlock SubmitBlock_sm">
<button type="button" id="backupConfirm" class="btn btn-mainblue-solid" data-dismiss="modal" style="">@Localizer["Confirm"]</button>
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal" style="">@Localizer["Cancel"]</button>
</div>
</div>
<div class="modal-footer modalforMemberGo">
</div>
</div>
</div>
</div>
<!-- END Backup Modal -->
<!-- START Restitute Modal -->
<div class="modal fade modal-full" id="restitute-modal" role="dialog" tabindex="-1" style="padding-right: 17px;" aria-modal="true">
<div class="modal-dialog modalforMemberGo">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Restitute</h3>
</div>
<div class="modal-body" style="padding-top:35px; padding-bottom: 35px">
<div class="input-group mb-3">
<div class="custom-file">
<input type="file" class="custom-file-input" id="restituteJson" accept="application/json">
<label class="custom-file-label" id="restituteLabel" for="restituteJson">@Localizer["Choose file"]</label>
</div>
</form>
</div>
<div class="SubmitBlock SubmitBlock_sm">
<button type="button" id="restituteConfirm" class="btn btn-mainblue-solid" style="">@Localizer["Confirm"]</button>
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal" style="">@Localizer["Close"]</button>
</div>
</div>
<!--END of div "modal-body"-->
<!--START of div "modal-footer"-->
<div class="modal-footer modalforMemberGo"></div>
<!--END of div "modal-footer"-->
<div class="modal-footer modalforMemberGo" style="justify-content:flex-start;">
<label>@Localizer["Log"]:</label>
<textarea id="restituteLog" class="form-control" style="height:180px;" disabled></textarea>
</div>
</div>
</div>
</div>
<!-- END
of Modal
-->
<!-- END
Restitute Modal
-->
@section Scripts{
...
...
@@ -201,7 +223,7 @@
$('#tbody').empty();
$('#tbody').append(response);
// 在成功取得回應後的處理邏輯
console.log(response);
//
console.log(response);
},
error: function (xhr, status, error) {
// 在發生錯誤時的處理邏輯
...
...
@@ -235,13 +257,6 @@
});
//備份按鈕
/*$(document).on('click', '.backupBtn', function () {
var vaultid = $(this).data('vault_id');
var merchantid = $(this).data('merchant_id');
console.log('vaultid=' + vaultid);
window.location.href = '/tokenvault/Permission/' + "?vault_id=" + vaultid + "&merchant_id=" + merchantid;
});*/
//備份Modal被觸發時執行
$('#backup-modal').on('show.bs.modal', function (e) {
...
...
@@ -268,7 +283,9 @@
vault_id: vId
},
success: function (response) {
downloadJsonFile(response.data.json, response.data.fileName);
if (response.isSuccess) {
downloadJsonFile(response.data.json, response.data.fileName);
}
},
error: function (xhr, status, error) {
// 在發生錯誤時的處理邏輯
...
...
@@ -276,16 +293,6 @@
}
});
});
//還原按鈕
$(document).on('click', '.restituteBtn', function () {
var vaultid = $(this).data('vault_id');
var merchantid = $(this).data('merchant_id');
console.log('vaultid=' + vaultid);
window.location.href = '/tokenvault/Permission/' + "?vault_id=" + vaultid + "&merchant_id=" + merchantid;
});
function downloadJsonFile(jsonStr, fileName) {
const blob = new Blob([jsonStr], { type: 'application/json' }); // 建立 Blob 物件
const url = URL.createObjectURL(blob); // 建立 Blob URL
...
...
@@ -297,6 +304,75 @@
}
//還原Modal被觸發時執行
//重置
let restituteLabelText = $("#restituteLabel").text();
$('#restitute-modal').on('show.bs.modal', function (e) {
//show.bs.modal = BS內建,觸發時執行
$('#restituteJson').val('');
let file = $('#restituteJson')[0].files[0];
$("#restituteLabel").text(restituteLabelText);
let btn = $(e.relatedTarget);//抓取觸發按鈕的資料
let mId = btn.data('merchant_id');
let vId = btn.data('vault_id');
let modal = $(this);//要修改的modal就是現在開啟的這個modal
modal.find('#restituteConfirm').data('merchant_id', mId);
modal.find('#restituteConfirm').data('vault_id', vId);
});
//改變成上傳的檔案名
$('#restituteJson').on('change', function () {
let file = event.target.files[0];
let fileName = file.name;
$(this).siblings('label').text(fileName);
});
//上傳
$('#restituteConfirm').on('click', function(){
let file = $('#restituteJson')[0].files[0];
let mId = $(this).data('merchant_id');
let vId = $(this).data('vault_id');
let reader = new FileReader();
reader.onload = function (e) {
let jsonContent = e.target.result;
$.ajax({
url: '/TokenVault/Restitute', // 替換為適當的控制器方法路徑
type: 'POST', // 或 'GET',根據實際需求
data: {
merchant_id: mId,
vault_id: vId,
json: jsonContent
},
success: function (response) {
//console.log(response);
var currentDate = new Date();
var currentDateTimeString = currentDate.toLocaleString();
$('#restituteLog').val("time -> " + currentDateTimeString + "\n" + "state -> " + response.message);
let log = "";
response.data?.forEach(function (element, index) {
log = $('#restituteLog').val();
thisFail = "fail" + index + " -> " + element;
$('#restituteLog').val(log + "\n" + thisFail)
});
},
error: function (xhr, status, error) {
// 在發生錯誤時的處理邏輯
console.error(error);
}
});
};
if(file != null){
reader.readAsText(file);
}
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment