Commit 8c5dcc2c authored by nickchen's avatar nickchen 🎨

Merge branch 'nick'

parents fca0ca5d 80fb28a3
......@@ -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
{
......@@ -378,7 +379,7 @@ namespace backstage.Controllers
/// <returns></returns>
[Authorize(Policy = "AdminOnly")]
[HttpPost]
public async Task<ResultModel> EditKey(int keyId, string name, int active)
public async Task<ResultModel> EditKey(int keyId, string name, int active, int deletable)
{
var result = new ResultModel();
string msg;
......@@ -396,10 +397,11 @@ namespace backstage.Controllers
var httpMethod = HttpMethod.Put;
var parameters = new Dictionary<string, string>
{
{ "id",keyId.ToString()},
{ "name",name},
{ "active",active.ToString()},
};
{ "id", keyId.ToString()},
{ "name", name},
{ "active", active.ToString()},
{ "del", deletable.ToString()},
};
var apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
if (apiResult.IsSuccess)
......@@ -526,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
......@@ -25,6 +25,8 @@ using System.Dynamic;
using TokenVault_management.Models;
using Microsoft.Extensions.Localization;
using Microsoft.AspNetCore.Localization;
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.EntityFrameworkCore.Internal;
namespace backstage.Controllers
{
......@@ -2347,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
......@@ -2368,7 +2411,7 @@ namespace backstage.Controllers
var resultData = new
{
fileName = "vault.json",
fileName = fileName,
json = jsonRe
};
......@@ -2380,27 +2423,26 @@ 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;
}
}
/// <summary>
/// 備份vault ajax
/// </summary>
......@@ -2460,6 +2502,97 @@ namespace backstage.Controllers
}
}
/// <summary>
/// 刪除欄位 ajax
/// </summary>
/// <param name="vault_id"></param>
/// <param name="merchant_id"></param>
/// <param name="field_id"></param>
/// <returns></returns>
[Authorize(Policy = "AdminOnly")]
[HttpPost]
public async Task<ResultModel> DelField(int vault_id, int merchant_id, int field_id)
{
var result = new ResultModel();
// 取得使用者的 "token" Claim 值
//string token = User.FindFirstValue("token");
string msg;
var url = _config["IP"] + "/v2/vault";
var httpMethod = HttpMethod.Post;
var data = new[]{ new {
action = "DEL",
id = field_id,
}};
var parameters = new Dictionary<string, string>
{
{ "info", "FIELDS" },
{ "id", vault_id.ToString() },
{ "Merchant_id", merchant_id.ToString() },
{ "data", JsonConvert.SerializeObject(data)}
};
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;
}
else
{
result.IsSuccess = false;
}
}
catch (Exception ex)
{
result.IsSuccess = false;
}
}
else
{
result.IsSuccess = false;
}
if (result.IsSuccess)
{
switch (_currentLanguage)
{
case "en":
msg = "Delete field success.";
break;
case "zh":
msg = "欄位刪除成功";
break;
default:
msg = "欄位刪除成功";
break;
}
}
else
{
switch (_currentLanguage)
{
case "en":
msg = "Delete field Fail.";
break;
case "zh":
msg = "欄位刪除失敗";
break;
default:
msg = "欄位刪除失敗";
break;
}
}
result.Message = msg;
return result;
}
}
......
......@@ -12,6 +12,7 @@ namespace backstage.Models.Keys
public string encryption { get; set; }
public DateTime lastUpdate { get; set; }
public int active { get; set; }
public int deleteable { get; set; }
public string expiration { get; set; }
public string[] img { get; set; }
......
......@@ -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; }
}
......
......@@ -171,6 +171,9 @@
<data name="Default Mask ID" xml:space="preserve">
<value>預設遮罩ID</value>
</data>
<data name="Deletable" xml:space="preserve">
<value>可刪除</value>
</data>
<data name="Delete" xml:space="preserve">
<value>刪除</value>
</data>
......
......@@ -120,12 +120,18 @@
<data name="Add Field" xml:space="preserve">
<value>新增欄位</value>
</data>
<data name="Are you sure you want to delete the field?" xml:space="preserve">
<value>確定刪除欄位?</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>取消</value>
</data>
<data name="Choose department" xml:space="preserve">
<value>選擇部門</value>
</data>
<data name="Confirm" xml:space="preserve">
<value>確認</value>
</data>
<data name="Create Department" xml:space="preserve">
<value>新增部門</value>
</data>
......@@ -141,6 +147,9 @@
<data name="Delete" xml:space="preserve">
<value>刪除</value>
</data>
<data name="Delete field" xml:space="preserve">
<value>刪除欄位</value>
</data>
<data name="Description" xml:space="preserve">
<value>描述</value>
</data>
......
......@@ -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,27 +86,27 @@
<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">
<a data-toggle="modal" data-target="#editProject" title="Modify">
<a class="reviseKeyBtn" data-keyid="@k.id" data-keyname="@k.name" data-active="@k.active" data-toggle="modal" data-target="#editApp" title="Revise">
<i class="fa-solid fa-pen-to-square"></i>
</a>
<i class="fa-solid fa-pen-to-square"></i>
</a>
</td>
<td>
@*<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 data-toggle="modal" data-target="#deleteProject" title="Delete">
<a class="deleteKeyBtn" data-keyid="@k.id" data-toggle="modal" data-target="#deleteProject" title="Delete">
<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>
</td>
</tr>
......@@ -264,12 +264,16 @@
<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>*@
</div>
<div class="form-group">
<label class="form-check-label label-space" for="uniqueY">@Localizer["Deletable"]</label>
<input class="form-check-input" type="checkbox" id="deletableKey" name="deletable" value="1">
</div>
<div class="SubmitBlock">
......@@ -394,6 +398,7 @@
if (msg != '') {
showAlert(IsSuccess, msg);
}
$(".custom-tooltip").tooltip({
items: "[data-tooltip]",
content: function () {
......@@ -516,9 +521,10 @@
$('#edit_key_name').val($(this).data('keyname'));
var active = $(this).data('active');
console.log('active=' + active);
var deletable = $(this).data('deletable');
//console.log('active=' + active);
$('#is_enable').prop('checked', active == "1"); // 根據active的值設置#is_enable的選擇狀態
$('#deletableKey').prop('checked', deletable == "1");
});
//送出編輯鑰匙
......@@ -530,7 +536,8 @@
data: {
keyId: $('#edit_key_id').val(),
name: $('#edit_key_name').val(),
active:$('#editApp input[name="active"]:checked').val()
active: $('#editApp input[name="active"]:checked').val(),
deletable: $('#editApp input[name="deletable"]:checked').val()
},
success: function (response) {
......@@ -552,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);
}
});
}
}
});
})
......
......@@ -91,6 +91,10 @@
<a class="dropdown-item" asp-controller="User" asp-action="Logout">
<i class="mdi mdi-logout mr-2 text-danger"></i>@Localizer["Logout"]
</a>
<div class="dropdown-divider"></div>
<div class="versionNo">
@Localizer["version"]: v2.36
</div>
</div>
}
......@@ -185,9 +189,9 @@
<div class="container-fluid page-body-wrapper">
<!-- partial:./partials/_sidebar.html -->
<nav class="sidebar sidebar-offcanvas" id="sidebar">
<div class="versionNo">
@Localizer["version"]: v2.33
</div>
<!-- <div class="versionNo">
@Localizer["version"]: v2.34
</div> -->
<ul class="nav ">
<li class="nav-item">
<a class="nav-link" data-toggle="collapse" href="#Member" aria-expanded="false" aria-controls="Member">
......
......@@ -289,7 +289,8 @@
},
error: function (xhr, status, error) {
// 在發生錯誤時的處理邏輯
console.error(error);
console.log(xhr.responseText);
showAlert(false, "發生錯誤");
}
});
});
......@@ -362,7 +363,8 @@
},
error: function (xhr, status, error) {
// 在發生錯誤時的處理邏輯
console.error(error);
console.log(xhr.responseText);
showAlert(false, "發生錯誤");
}
});
};
......
......@@ -106,7 +106,7 @@
<th>@Localizer["Format"]</th>
<th>@Localizer["Enable"]</th>
<th>@Localizer["Manage"]</th>
<th>@Localizer["Delete"]</th>
</tr>
</thead>
<tbody id="tbody">
......@@ -127,6 +127,11 @@
<a class="btn btnPermission btn-sm masksBtn">@Localizer["Data Mask"]</a>
<a class="btn btnPermission btn-sm usersBtn">@Localizer["Users"] </a>
</td>
<td>
<a id="delFieldBtn" data-field_id="@i.id" data-field_name="@i.name" data-toggle="modal" data-target="#delete-field-modal" title="刪除">
<i class="fa-solid fa-trash-can"></i>
</a>
</td>
</tr>
}
}
......@@ -205,6 +210,34 @@
</div>
<!-- START delete field modal -->
<div class="modal fade " id="delete-field-modal" tabindex="-1" style=" padding-right: 17px;" aria-modal="true" role="dialog">
<div class="modal-dialog modal-md modalforMemberGo">
<div class="modal-content">
<div class="modal-header">
<h4>@Localizer["Delete field"] <span id="delFieldIdName"></span> </h4>
</div>
<div class="modal-body" style="padding-top:35px; padding-bottom: 35px">
<p>
@Localizer["Are you sure you want to delete the field?"]
</p>
<div class="SubmitBlock SubmitBlock_sm">
<button type="button" id="delFieldConfirmBtn" class="btn btn-mainblue-solid" 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">
</div>
</div>
</div>
</div>
<!-- END delete field modal -->
@section Scripts{
......@@ -239,8 +272,48 @@
});
// 欄位刪除Modal被觸發時執行
$('#delete-field-modal').on('show.bs.modal', function (e) {
//show.bs.modal = BS內建,觸發時執行
let btn = $(e.relatedTarget);//抓取觸發按鈕的資料
let fId = btn.data('field_id');
let fName = btn.data('field_name');
let modal = $(this);//要修改的modal就是現在開啟的這個modal
modal.find('#delFieldIdName').text(fId + "_" + fName);
modal.find('#delFieldConfirmBtn').data('field_id', fId);
});
// 確認刪除欄位按鈕點擊
$('#delFieldConfirmBtn').click(function () {
let mId = parseInt('@ViewBag.Merchant_id');
let vId = parseInt('@ViewBag.vault_id');
let fId = $(this).data('field_id');
$.ajax({
url: '/TokenVault/DelField',
type: 'POST',
data: {
merchant_id: mId,
vault_id: vId,
field_id: fId
},
success: function (result) {
//console.log(data);
showAlert(result.isSuccess, result.message);
if (result.isSuccess) {
$('#delete-field-modal').modal('hide');
setTimeout(function () {
location.reload();
}, 2000);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
showAlert(false, "發生錯誤");
}
});
});
////Modal按鈕
//$("#createFieldBtn").on("click", function () {
......
......@@ -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>}
......
......@@ -19293,9 +19293,9 @@ tbody {
/*版本號樣式*/
.versionNo {
color: #f2f2f2;
color: #abb8c3;
font-size: 0.825rem;
padding: 20px 16px 10px 16px
padding: 10px 16px 10px 16px
}
.floating-msg {
......@@ -19322,11 +19322,6 @@ tbody {
}
.versionNo {
color: #f2f2f2;
font-size: 0.825rem;
padding: 20px 16px 10px 16px
}
.custom-tooltip-width {
......
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