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;
using Microsoft.Extensions.Localization;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace backstage.Controllers
{
......@@ -31,11 +33,13 @@ namespace backstage.Controllers
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IStringLocalizer<UserController> _localizer;
private readonly string _currentLanguage;
// 在您的類別中注入 IWebHostEnvironment 服務
private readonly IWebHostEnvironment _webHostEnvironment;
/// <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;
_callApi = callApi;
......@@ -44,6 +48,7 @@ namespace backstage.Controllers
var requestCultureFeature = _httpContextAccessor.HttpContext.Features.Get<IRequestCultureFeature>();
var currentCulture = requestCultureFeature.RequestCulture.Culture;
_currentLanguage = currentCulture.TwoLetterISOLanguageName;
_webHostEnvironment = webHostEnvironment;
}
......@@ -102,7 +107,7 @@ namespace backstage.Controllers
/// <returns></returns>
[Authorize(Policy = "AdminOnly")]
[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();
string msg;
......@@ -127,14 +132,22 @@ namespace backstage.Controllers
return result;
}
// step1 create key
var url = _config["IP"] + "/security/key/generate";
var httpMethod = HttpMethod.Post;
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);
if (apiResult.IsSuccess)
{
......@@ -143,7 +156,33 @@ namespace backstage.Controllers
var Response = JsonConvert.DeserializeObject<Response>(apiResult.Data.ToString());
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
url = _config["IP"] + "/security/key/combine";
......@@ -177,6 +216,7 @@ namespace backstage.Controllers
}
result.IsSuccess = true;
result.Message = msg;
return result;
}
else
......@@ -314,7 +354,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)
{
var result = new ResultModel();
string msg;
......
......@@ -14,6 +14,9 @@ namespace backstage.Models.Keys
public int active { get; set; }
public string expiration { get; set; }
public string[] img { get; set; }
public string key1 { get; set; }
public string key2 { get; set; }
}
public class ListKeysResponse
......
......@@ -11,7 +11,7 @@ namespace TokenVault_management.Models
public int r { get; set; }
public Object m { get; set; }
public Object data { get; set; }
public string[] img { get; set; }
public string flags { get; set; }
public List<string> failInfo { get; set; }
......
......@@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</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">
<value>本月修改代碼化保險庫入口數量</value>
</data>
......
......@@ -141,6 +141,9 @@
<data name="Choose department" xml:space="preserve">
<value>選擇部門</value>
</data>
<data name="Close" xml:space="preserve">
<value>關閉</value>
</data>
<data name="Confirm" xml:space="preserve">
<value>確認</value>
</data>
......@@ -195,6 +198,12 @@
<data name="Inactive" xml:space="preserve">
<value>未啟用</value>
</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">
<value>鑰匙列表</value>
</data>
......@@ -216,6 +225,12 @@
<data name="Number of users" xml:space="preserve">
<value>使用者數量</value>
</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">
<value>移除使用者</value>
</data>
......
@using Microsoft.AspNetCore.Mvc.Localization

@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
@model List<backstage.Models.Keys.Key>
@{
......@@ -19,6 +20,11 @@
max-width: 100%;
max-height: 100%;
}
.hidden {
display: none;
}
</style>
......@@ -86,7 +92,7 @@
<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>
</a>
......@@ -146,7 +152,25 @@
<div>
<input type="text" class="form-control input-sm" id="key_name">
</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">
<label class="control-label" for="projectType">類型:</label>
<div>
......@@ -242,7 +266,7 @@
<label class="form-check-label" for="uniqueY">
@Localizer["啟用"]
</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>
......@@ -265,15 +289,15 @@
</div><!-- END of Modal-->
<!--END of New App Popup Form-->
<div class="modal fade " id="deleteProject" role="dialog" tabindex="-1" aria-modal="true">
<div class="modal-dialog modal-sm modalforMemberGo">
<div class="modal fade " id="deleteProject" style=" padding-right: 17px;" role="dialog" tabindex="-1" aria-modal="true">
<div class="modal-dialog modal-md modalforMemberGo">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4>
刪除專案
@Localizer["Delete key"]
</h4>
</div> <!--END of div "modal-header"-->
......@@ -281,12 +305,13 @@
<form>
<p>
是否確定要刪除專案?
@Localizer["Please confirm to delete key."]
</p>
<div class="SubmitBlock SubmitBlock_sm">
<button id="confirmBtn" class="btn btn-mainblue-solid" style="margin-right: 10px; width: 80px">@Localizer["Confirm"]</button>
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal" style="margin-right: 10px; width: 80px">@Localizer["Cancel"]</button>
<button id="confirmBtn" class="btn btn-mainblue-solid">@Localizer["Confirm"]</button>
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal">@Localizer["Cancel"]</button>
</div>
</form>
......@@ -303,13 +328,53 @@
</div><!-- END of div "modal-dialog modal-lg" -->
</div>
<!--QRCODE圖片下載-->
<!-- 建立 Modal 來顯示圖片 -->
<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 () {
var msg = '@TempData["msg"]';
var IsSuccess = '@TempData["IsSuccess"]';
console.log(IsSuccess + msg);
$('#imageModal').modal('hide');
if (msg != '') {
showAlert(IsSuccess, msg);
}
......@@ -330,6 +395,10 @@
console.log('selectKeyId=' + selectKeyId);
});
// 页面加载完成后,隐藏 recoverKeyForm
document.getElementById("recoverKeyForm").classList.remove("show");
// 页面加载完成后,隐藏 maskSettingsAdvID
//刪除鑰匙
$("#confirmBtn").on("click", function (e) {
......@@ -364,6 +433,7 @@
//新增鑰匙
$("#CreateKey").on("click", function (e) {
var keyName = $('#key_name').val();
$.ajax({
url: "/Key/CreateKey",
......@@ -371,13 +441,24 @@
data: { key_name: keyName},
success: function (response) {
// API 呼叫成功的處理程式碼
console.log('response=' + JSON.stringify( response));
showAlert(response.isSuccess, response.message)
if (response.isSuccess) {
$('#newApp').modal('hide');
setTimeout(function () {
location.reload();
}, 2000);
var imageUrl = response.data.toString();
console.log('imageUrl=' + imageUrl);
// 使用 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) {
......@@ -387,6 +468,10 @@
});
});
$('#import_key_btn').on('click', function (e) {
document.getElementById("recoverKeyForm").classList.toggle("show");
});
//打開編輯鑰匙modal
$(".reviseKeyBtn").on("click", function (e) {
......@@ -396,9 +481,8 @@
$('#edit_key_name').val($(this).data('keyname'));
var active = $(this).data('active');
console.log('active=' + active);
$('input[name="active"][value="' + active + '"]').prop('checked', true);
$('#is_enable').prop('checked', active == "1"); // 根據active的值設置#is_enable的選擇狀態
$('#editApp').modal();
});
//送出編輯鑰匙
......
......@@ -185,7 +185,7 @@
<!-- partial:./partials/_sidebar.html -->
<nav class="sidebar sidebar-offcanvas" id="sidebar">
<div class="versionNo">
@Localizer["version"]: v1.23
@Localizer["version"]: v2.0
</div>
<ul class="nav ">
<li class="nav-item">
......
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