Commit 72a29395 authored by Jason's avatar Jason

1.key remove modal修正

2.key import
3.顯示QRCODE
parent 5fbf8e49
...@@ -17,6 +17,8 @@ using backstage.Models; ...@@ -17,6 +17,8 @@ using backstage.Models;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace backstage.Controllers namespace backstage.Controllers
{ {
...@@ -31,11 +33,13 @@ namespace backstage.Controllers ...@@ -31,11 +33,13 @@ namespace backstage.Controllers
private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IStringLocalizer<UserController> _localizer; private readonly IStringLocalizer<UserController> _localizer;
private readonly string _currentLanguage; private readonly string _currentLanguage;
// 在您的類別中注入 IWebHostEnvironment 服務
private readonly IWebHostEnvironment _webHostEnvironment;
/// <summary> /// <summary>
/// 讀取組態用 /// 讀取組態用
/// </summary> /// </summary>
public KeyController(IConfiguration config, ICallApi callApi, IHttpContextAccessor httpContextAccessor, IStringLocalizer<UserController> localizer) public KeyController(IConfiguration config, ICallApi callApi, IHttpContextAccessor httpContextAccessor, IStringLocalizer<UserController> localizer, IWebHostEnvironment webHostEnvironment)
{ {
_config = config; _config = config;
_callApi = callApi; _callApi = callApi;
...@@ -44,6 +48,7 @@ namespace backstage.Controllers ...@@ -44,6 +48,7 @@ namespace backstage.Controllers
var requestCultureFeature = _httpContextAccessor.HttpContext.Features.Get<IRequestCultureFeature>(); var requestCultureFeature = _httpContextAccessor.HttpContext.Features.Get<IRequestCultureFeature>();
var currentCulture = requestCultureFeature.RequestCulture.Culture; var currentCulture = requestCultureFeature.RequestCulture.Culture;
_currentLanguage = currentCulture.TwoLetterISOLanguageName; _currentLanguage = currentCulture.TwoLetterISOLanguageName;
_webHostEnvironment = webHostEnvironment;
} }
...@@ -102,7 +107,7 @@ namespace backstage.Controllers ...@@ -102,7 +107,7 @@ namespace backstage.Controllers
/// <returns></returns> /// <returns></returns>
[Authorize(Policy = "AdminOnly")] [Authorize(Policy = "AdminOnly")]
[HttpPost] [HttpPost]
public async Task<ResultModel> CreateKey(string key_name) public async Task<ResultModel> CreateKey(string key_name, string key1, string key2)
{ {
var result = new ResultModel(); var result = new ResultModel();
string msg; string msg;
...@@ -127,14 +132,22 @@ namespace backstage.Controllers ...@@ -127,14 +132,22 @@ namespace backstage.Controllers
return result; return result;
} }
// step1 create key // step1 create key
var url = _config["IP"] + "/security/key/generate"; var url = _config["IP"] + "/security/key/generate";
var httpMethod = HttpMethod.Post; var httpMethod = HttpMethod.Post;
var parameters = new Dictionary<string, string> var parameters = new Dictionary<string, string>
{ {
}; };
if (!string.IsNullOrEmpty(key1) && !string.IsNullOrEmpty(key1))
{
parameters = new Dictionary<string, string>
{
{ "QRData","["+key1+","+key2+"]"}
};
}
var apiResult = await _callApi.CallAPI(url, parameters, httpMethod); var apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
if (apiResult.IsSuccess) if (apiResult.IsSuccess)
{ {
...@@ -143,7 +156,33 @@ namespace backstage.Controllers ...@@ -143,7 +156,33 @@ namespace backstage.Controllers
var Response = JsonConvert.DeserializeObject<Response>(apiResult.Data.ToString()); var Response = JsonConvert.DeserializeObject<Response>(apiResult.Data.ToString());
if (Response.r == 0) if (Response.r == 0)
{ {
// 取得 wwwroot 資料夾的絕對路徑
string wwwrootPath = _webHostEnvironment.WebRootPath;
// 確認儲存圖檔的目標資料夾存在,如果不存在則建立它
string imagesFolder = Path.Combine(wwwrootPath, "images");
Directory.CreateDirectory(imagesFolder);
List<string> downloadPaths = new List<string>();
for (int i = 0; i < Response.img.Length; i++)
{
string imageUrl = Response.img[i];
string fileName = $"key_part{i + 1}.png";
string imagePath = Path.Combine(imagesFolder, fileName);
using (HttpClient client = new HttpClient())
{
// 下載圖檔位元組數據
byte[] imageBytes = await client.GetByteArrayAsync(imageUrl);
// 將圖檔寫入目標路徑
System.IO.File.WriteAllBytes(imagePath, imageBytes);
// 添加下載路徑到集合中
string downloadPath = Path.Combine("/images", fileName);
downloadPaths.Add(downloadPath);
}
}
result.Data = downloadPaths;
#region step2 combine key #region step2 combine key
url = _config["IP"] + "/security/key/combine"; url = _config["IP"] + "/security/key/combine";
...@@ -177,6 +216,7 @@ namespace backstage.Controllers ...@@ -177,6 +216,7 @@ namespace backstage.Controllers
} }
result.IsSuccess = true; result.IsSuccess = true;
result.Message = msg; result.Message = msg;
return result; return result;
} }
else else
...@@ -314,7 +354,7 @@ namespace backstage.Controllers ...@@ -314,7 +354,7 @@ namespace backstage.Controllers
/// <returns></returns> /// <returns></returns>
[Authorize(Policy = "AdminOnly")] [Authorize(Policy = "AdminOnly")]
[HttpPost] [HttpPost]
public async Task<ResultModel> EditKey(int keyId,string name, int active) public async Task<ResultModel> EditKey(int keyId, string name, int active)
{ {
var result = new ResultModel(); var result = new ResultModel();
string msg; string msg;
......
...@@ -14,6 +14,9 @@ namespace backstage.Models.Keys ...@@ -14,6 +14,9 @@ namespace backstage.Models.Keys
public int active { get; set; } public int active { get; set; }
public string expiration { get; set; } public string expiration { get; set; }
public string[] img { get; set; } public string[] img { get; set; }
public string key1 { get; set; }
public string key2 { get; set; }
} }
public class ListKeysResponse public class ListKeysResponse
......
...@@ -11,7 +11,7 @@ namespace TokenVault_management.Models ...@@ -11,7 +11,7 @@ namespace TokenVault_management.Models
public int r { get; set; } public int r { get; set; }
public Object m { get; set; } public Object m { get; set; }
public Object data { get; set; } public Object data { get; set; }
public string[] img { get; set; }
public string flags { get; set; } public string flags { get; set; }
public List<string> failInfo { get; set; } public List<string> failInfo { get; set; }
......
...@@ -117,6 +117,9 @@ ...@@ -117,6 +117,9 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="Import Key" xml:space="preserve">
<value>匯入鑰匙</value>
</data>
<data name="Modify the number of Token Vault Entrys this month" xml:space="preserve"> <data name="Modify the number of Token Vault Entrys this month" xml:space="preserve">
<value>本月修改代碼化保險庫入口數量</value> <value>本月修改代碼化保險庫入口數量</value>
</data> </data>
......
...@@ -141,6 +141,9 @@ ...@@ -141,6 +141,9 @@
<data name="Choose department" xml:space="preserve"> <data name="Choose department" xml:space="preserve">
<value>選擇部門</value> <value>選擇部門</value>
</data> </data>
<data name="Close" xml:space="preserve">
<value>關閉</value>
</data>
<data name="Confirm" xml:space="preserve"> <data name="Confirm" xml:space="preserve">
<value>確認</value> <value>確認</value>
</data> </data>
...@@ -195,6 +198,12 @@ ...@@ -195,6 +198,12 @@
<data name="Inactive" xml:space="preserve"> <data name="Inactive" xml:space="preserve">
<value>未啟用</value> <value>未啟用</value>
</data> </data>
<data name="Key part1" xml:space="preserve">
<value>第一組Key</value>
</data>
<data name="Key part2" xml:space="preserve">
<value>第二組Key</value>
</data>
<data name="Keys List" xml:space="preserve"> <data name="Keys List" xml:space="preserve">
<value>鑰匙列表</value> <value>鑰匙列表</value>
</data> </data>
...@@ -216,6 +225,12 @@ ...@@ -216,6 +225,12 @@
<data name="Number of users" xml:space="preserve"> <data name="Number of users" xml:space="preserve">
<value>使用者數量</value> <value>使用者數量</value>
</data> </data>
<data name="Please confirm to delete key." xml:space="preserve">
<value>請確認刪除鑰匙</value>
</data>
<data name="Please save the QR code properly." xml:space="preserve">
<value>請妥善儲存QR code</value>
</data>
<data name="Remove User" xml:space="preserve"> <data name="Remove User" xml:space="preserve">
<value>移除使用者</value> <value>移除使用者</value>
</data> </data>
......
@using Microsoft.AspNetCore.Mvc.Localization 
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer @inject IViewLocalizer Localizer
@model List<backstage.Models.Keys.Key> @model List<backstage.Models.Keys.Key>
@{ @{
...@@ -19,6 +20,11 @@ ...@@ -19,6 +20,11 @@
max-width: 100%; max-width: 100%;
max-height: 100%; max-height: 100%;
} }
.hidden {
display: none;
}
</style> </style>
...@@ -86,7 +92,7 @@ ...@@ -86,7 +92,7 @@
<a data-toggle="modal" data-target="#editProject" title="Modify"> <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="#editProject" title="Revise"> <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> <i class="fa-solid fa-pen-to-square"></i>
</a> </a>
...@@ -146,7 +152,25 @@ ...@@ -146,7 +152,25 @@
<div> <div>
<input type="text" class="form-control input-sm" id="key_name"> <input type="text" class="form-control input-sm" id="key_name">
</div> </div>
</div> <!--End of id:--> </div>
<div class="form-group">
<button id="import_key_btn" type="button" class="btn btn-primary mr-2">@Localizer["Import Key"]</button>
</div>
<div class="hidden" id="recoverKeyForm">
<div class="form-group">
<label class="control-label">@Localizer["Key part1"]:</label>
<div>
<input type="text" class="form-control input-sm" id="key1">
</div>
</div>
<div class="form-group">
<label class="control-label">@Localizer["Key part2"]:</label>
<div>
<input type="text" class="form-control input-sm" id="key2">
</div>
</div>
</div>
<!--<div class="form-group"> <!--<div class="form-group">
<label class="control-label" for="projectType">類型:</label> <label class="control-label" for="projectType">類型:</label>
<div> <div>
...@@ -161,29 +185,29 @@ ...@@ -161,29 +185,29 @@
<!-- Andorid Adv--> <!-- Andorid Adv-->
<!--<div id="andoridAdvID" class="andoridAdv"> <!--<div id="andoridAdvID" class="andoridAdv">
<div class="form-group"> <div class="form-group">
<label class="control-label" for="packageName">套件名稱:</label> <label class="control-label" for="packageName">套件名稱:</label>
<div> <div>
<input type="text" class="form-control input-sm" id="packageName" placeholder="例如 com.example"> <input type="text" class="form-control input-sm" id="packageName" placeholder="例如 com.example">
</div>
</div> </div>
<div class="form-group"> </div>
<label class="control-label" for="packageName">SHA-1指紋憑證:</label> <div class="form-group">
<div> <label class="control-label" for="packageName">SHA-1指紋憑證:</label>
<input type="text" class="form-control input-sm" id="fingerPrint" placeholder="例如: AA:BB:CC:DD:EE:00:11:22:33:44:FF:GG:HH:II:JJ:55:66:77:88:99"> <div>
</div> <input type="text" class="form-control input-sm" id="fingerPrint" placeholder="例如: AA:BB:CC:DD:EE:00:11:22:33:44:FF:GG:HH:II:JJ:55:66:77:88:99">
</div>--> </div>
</div>-->
<!--End of app id:--> <!--End of app id:-->
<!--</div>--> <!-- End of Andorid Adv--> <!--</div>--> <!-- End of Andorid Adv-->
<!-- iOS Adv--> <!-- iOS Adv-->
<!--<div id="iOSAdvID" class="iOSAdv"> <!--<div id="iOSAdvID" class="iOSAdv">
<div class="form-group"> <div class="form-group">
<label class="control-label" for="bundleID">繫結識別碼:</label> <label class="control-label" for="bundleID">繫結識別碼:</label>
<div> <div>
<input type="text" class="form-control input-sm" id="bundleID" placeholder="例如 com.example.MyApp"> <input type="text" class="form-control input-sm" id="bundleID" placeholder="例如 com.example.MyApp">
</div> </div>
</div>--> </div>-->
<!--End of app id:--> <!--End of app id:-->
<!-- <div class="description col-sm-12 text-center"> <!-- <div class="description col-sm-12 text-center">
當您新增一個App後,系統會自動產生一組API金鑰,可至App列表中檢視 當您新增一個App後,系統會自動產生一組API金鑰,可至App列表中檢視
...@@ -242,7 +266,7 @@ ...@@ -242,7 +266,7 @@
<label class="form-check-label" for="uniqueY"> <label class="form-check-label" for="uniqueY">
@Localizer["啟用"] @Localizer["啟用"]
</label> </label>
<input class="form-check-input" type="checkbox" name="active" value="1"> <input class="form-check-input" type="checkbox" id="is_enable" name="active" value="1">
</div> </div>
...@@ -265,15 +289,15 @@ ...@@ -265,15 +289,15 @@
</div><!-- END of Modal--> </div><!-- END of Modal-->
<!--END of New App Popup Form--> <!--END of New App Popup Form-->
<div class="modal fade " id="deleteProject" role="dialog" tabindex="-1" aria-modal="true"> <div class="modal fade " id="deleteProject" style=" padding-right: 17px;" role="dialog" tabindex="-1" aria-modal="true">
<div class="modal-dialog modal-sm modalforMemberGo"> <div class="modal-dialog modal-md modalforMemberGo">
<!-- Modal content--> <!-- Modal content-->
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h4> <h4>
刪除專案 @Localizer["Delete key"]
</h4> </h4>
</div> <!--END of div "modal-header"--> </div> <!--END of div "modal-header"-->
...@@ -281,12 +305,13 @@ ...@@ -281,12 +305,13 @@
<form> <form>
<p> <p>
是否確定要刪除專案? @Localizer["Please confirm to delete key."]
</p> </p>
<div class="SubmitBlock SubmitBlock_sm"> <div class="SubmitBlock SubmitBlock_sm">
<button id="confirmBtn" class="btn btn-mainblue-solid" style="margin-right: 10px; width: 80px">@Localizer["Confirm"]</button> <button id="confirmBtn" class="btn btn-mainblue-solid">@Localizer["Confirm"]</button>
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal" style="margin-right: 10px; width: 80px">@Localizer["Cancel"]</button> <button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal">@Localizer["Cancel"]</button>
</div> </div>
</form> </form>
...@@ -303,13 +328,53 @@ ...@@ -303,13 +328,53 @@
</div><!-- END of div "modal-dialog modal-lg" --> </div><!-- END of div "modal-dialog modal-lg" -->
</div> </div>
@section Scripts{ <!--QRCODE圖片下載-->
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <!-- 建立 Modal 來顯示圖片 -->
<script nonce="KUY8VewuvyUYVEIvEFue4vwyiuf"> <div id="imageModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="col-12 text-center">
<p class="qr-code-message">@Localizer["Please save the QR code properly."]</p>
</div>
</div>
<div class="row">
<div class="col-6">
<img id="image1" src="" alt="圖片">
</div>
<div class="col-6">
<img id="image2" src="" alt="圖片">
</div>
</div>
<div class="row">
<div class="col-6">
<a id="downloadBtn1" class="btn btn-primary" href="#" download>下載Key_part1</a>
</div>
<div class="col-6">
<a id="downloadBtn2" class="btn btn-primary" href="#" download>下載Key_part2</a>
</div>
</div>
</div>
<div class="SubmitBlock SubmitBlock_sm text-center">
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal">@Localizer["Close"]</button>
</div>
</div>
</div>
</div>
</div>
@section Scripts{
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script nonce="KUY8VewuvyUYVEIvEFue4vwyiuf">
$('document').ready(function () { $('document').ready(function () {
var msg = '@TempData["msg"]'; var msg = '@TempData["msg"]';
var IsSuccess = '@TempData["IsSuccess"]'; var IsSuccess = '@TempData["IsSuccess"]';
console.log(IsSuccess + msg); $('#imageModal').modal('hide');
if (msg != '') { if (msg != '') {
showAlert(IsSuccess, msg); showAlert(IsSuccess, msg);
} }
...@@ -330,6 +395,10 @@ ...@@ -330,6 +395,10 @@
console.log('selectKeyId=' + selectKeyId); console.log('selectKeyId=' + selectKeyId);
}); });
// 页面加载完成后,隐藏 recoverKeyForm
document.getElementById("recoverKeyForm").classList.remove("show");
// 页面加载完成后,隐藏 maskSettingsAdvID
//刪除鑰匙 //刪除鑰匙
$("#confirmBtn").on("click", function (e) { $("#confirmBtn").on("click", function (e) {
...@@ -364,6 +433,7 @@ ...@@ -364,6 +433,7 @@
//新增鑰匙 //新增鑰匙
$("#CreateKey").on("click", function (e) { $("#CreateKey").on("click", function (e) {
var keyName = $('#key_name').val(); var keyName = $('#key_name').val();
$.ajax({ $.ajax({
url: "/Key/CreateKey", url: "/Key/CreateKey",
...@@ -371,13 +441,24 @@ ...@@ -371,13 +441,24 @@
data: { key_name: keyName}, data: { key_name: keyName},
success: function (response) { success: function (response) {
// API 呼叫成功的處理程式碼 // API 呼叫成功的處理程式碼
console.log('response=' + JSON.stringify( response));
showAlert(response.isSuccess, response.message) showAlert(response.isSuccess, response.message)
if (response.isSuccess) { if (response.isSuccess) {
$('#newApp').modal('hide'); $('#newApp').modal('hide');
setTimeout(function () { var imageUrl = response.data.toString();
location.reload(); console.log('imageUrl=' + imageUrl);
}, 2000); // 使用 split 方法拆分 URL 字串
var imageUrls = imageUrl.split(",");
// 設定圖片元素的 src 屬性
$('#image1').attr('src', imageUrls[0]);
$('#image2').attr('src', imageUrls[1]);
$('#downloadBtn1').attr('href', imageUrls[0]);
$('#downloadBtn2').attr('href', imageUrls[1]);
$('#imageModal').modal();
//setTimeout(function () {
// location.reload();
//}, 2000);
} }
}, },
error: function (xhr, status, error) { error: function (xhr, status, error) {
...@@ -387,6 +468,10 @@ ...@@ -387,6 +468,10 @@
}); });
}); });
$('#import_key_btn').on('click', function (e) {
document.getElementById("recoverKeyForm").classList.toggle("show");
});
//打開編輯鑰匙modal //打開編輯鑰匙modal
$(".reviseKeyBtn").on("click", function (e) { $(".reviseKeyBtn").on("click", function (e) {
...@@ -396,9 +481,8 @@ ...@@ -396,9 +481,8 @@
$('#edit_key_name').val($(this).data('keyname')); $('#edit_key_name').val($(this).data('keyname'));
var active = $(this).data('active'); var active = $(this).data('active');
console.log('active=' + active); console.log('active=' + active);
$('input[name="active"][value="' + active + '"]').prop('checked', true); $('#is_enable').prop('checked', active == "1"); // 根據active的值設置#is_enable的選擇狀態
$('#editApp').modal();
}); });
//送出編輯鑰匙 //送出編輯鑰匙
...@@ -437,5 +521,5 @@ ...@@ -437,5 +521,5 @@
}) })
</script> </script>
} }
...@@ -185,7 +185,7 @@ ...@@ -185,7 +185,7 @@
<!-- partial:./partials/_sidebar.html --> <!-- partial:./partials/_sidebar.html -->
<nav class="sidebar sidebar-offcanvas" id="sidebar"> <nav class="sidebar sidebar-offcanvas" id="sidebar">
<div class="versionNo"> <div class="versionNo">
@Localizer["version"]: v1.23 @Localizer["version"]: v2.0
</div> </div>
<ul class="nav "> <ul class="nav ">
<li class="nav-item"> <li class="nav-item">
......
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
} }
// 页面加载完成后,隐藏 maskSettingsAdvID // 页面加载完成后,隐藏 maskSettingsAdvID
document.getElementById("maskSettingsAdvID").classList.remove("show"); document.getElementById("maskSettingsAdvID").classList.remove("show");
//新增mask //新增mask
......
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