Commit 03904ec9 authored by nickchen's avatar nickchen 🎨

add: license page

parent bec52ba1
...@@ -24,6 +24,8 @@ using Microsoft.AspNetCore.Localization; ...@@ -24,6 +24,8 @@ using Microsoft.AspNetCore.Localization;
using System.Text.Json; using System.Text.Json;
using DocumentFormat.OpenXml.Office2010.Excel; using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Wordprocessing; using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Spreadsheet;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace backstage.Controllers namespace backstage.Controllers
{ {
...@@ -1870,5 +1872,67 @@ namespace backstage.Controllers ...@@ -1870,5 +1872,67 @@ namespace backstage.Controllers
return RedirectToAction(nameof(Login)); return RedirectToAction(nameof(Login));
} }
} [Authorize(Policy = "AdminOnly")]
[HttpGet]
public async Task<IActionResult> UploadLicense()
{
var url = _config["IP"] + "/license/get";
var httpMethod = HttpMethod.Post;
var parameters = new Dictionary<string, string>();
var apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
if (apiResult.IsSuccess)
{
try
{
var licenseResponse = JsonConvert.DeserializeObject<LicenseResponse>(apiResult.Data.ToString());
if (licenseResponse.r == 0)
{
var license = licenseResponse.License;
return View(license);
}
}
catch
{
}
}
return View(new License());
}
[Authorize(Policy = "AdminOnly")]
[HttpPost]
public async Task<ResultModel> UploadLicenseAjax(string license)
{
var result = new ResultModel();
var url = _config["IP"] + "/license";
var httpMethod = HttpMethod.Post;
var parameters = new Dictionary<string, string>
{
{ "license", license }
};
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 = "License update completed.";
return result;
}
}
catch
{
}
}
result.IsSuccess = false;
result.Message = "License update fail.";
return result;
}
}
} }
\ No newline at end of file
...@@ -49,7 +49,7 @@ namespace backstage.Models.Users ...@@ -49,7 +49,7 @@ namespace backstage.Models.Users
} }
public class emaildata public class emaildata
{ {
public int id { get; set; } public int id { get; set; }
...@@ -118,6 +118,24 @@ public class emaildata ...@@ -118,6 +118,24 @@ public class emaildata
} }
public class LicenseResponse
{
//user/list response
public int r { get; set; }
public Object m { get; set; }
public string flags { get; set; }
public License License { get; set; }
}
public class License
{
public string Product_name { get; set; }
public string Expiration_date { get; set; }
public string Product_max_version { get; set; }
public string Department { get; set; }
public string Creation_date { get; set; }
public string Name { get; set; }
public string Other { get; set; }
}
} }
...@@ -119,14 +119,15 @@ ...@@ -119,14 +119,15 @@
@section Scripts{ @section Scripts{
<script nonce="KUY8VewuvyUYVEIvEFue4vwyiuf"> <script nonce="KUY8VewuvyUYVEIvEFue4vwyiuf">
var msg = '@TempData["msg"]';
var msg = '@TempData["msg"]';
var IsSuccess = '@TempData["IsSuccess"]'; var IsSuccess = '@TempData["IsSuccess"]';
console.log(IsSuccess + msg); console.log(IsSuccess + msg);
if (msg != '') { if (msg != '') {
showAlert(IsSuccess, msg); showAlert(IsSuccess, msg);
} }
$('.userRow').each(function () { $('.userRow').each(function () {
var uid = $(this).find('td:first-child').text(); // 獲取行中的 UID 值 var uid = $(this).find('td:first-child').text(); // 獲取行中的 UID 值
console.log('uid=' + uid) console.log('uid=' + uid)
......
@using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer @inject IViewLocalizer Localizer
@model backstage.Models.Users.UserResponse @model backstage.Models.Users.License
@{ @{
bool isAdmin = User.IsInRole("Admin"); bool isAdmin = User.IsInRole("Admin");
string disabledClass = isAdmin ? "" : "disabled"; string disabledClass = isAdmin ? "" : "disabled";
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
</div> </div>
<div class="col-md-4 col-lg-6 form-group0"> <div class="col-md-4 col-lg-6 form-group0">
<div class="SubmitBlock0 SubmitBlock_sm0"> <div class="SubmitBlock0 SubmitBlock_sm0">
<button type="button" id="" class="btn btn-primary">Upload</button> <button type="button" id="Upload" class="btn btn-primary">Upload</button>
</div> </div>
</div> </div>
</div> </div>
...@@ -54,31 +54,31 @@ ...@@ -54,31 +54,31 @@
<tbody> <tbody>
<tr> <tr>
<th style=" border-left: solid 1px #d9d9d9;">Product Name</th> <th style=" border-left: solid 1px #d9d9d9;">Product Name</th>
<td>Token Vault</td> <td>@Model.Product_name</td>
</tr> </tr>
<tr> <tr>
<th>Expireation Date</th> <th>Expireation Date</th>
<td>2033-07-21 17:00:30</td> <td>@Model.Expiration_date</td>
</tr> </tr>
<tr> <tr>
<th>Product Max Version</th> <th>Product Max Version</th>
<td>1.0</td> <td>@Model.Product_max_version</td>
</tr> </tr>
<tr> <tr>
<th>Department</th> <th>Department</th>
<td>Taipay</td> <td>@Model.Department</td>
</tr> </tr>
<tr> <tr>
<th>Creation Date</th> <th>Creation Date</th>
<td>2023-07-17 17:49:30</td> <td>@Model.Creation_date</td>
</tr> </tr>
<tr> <tr>
<th>Name</th> <th>Name</th>
<td>API License</td> <td>@Model.Name</td>
</tr> </tr>
<tr> <tr>
<th style=" border-right: solid 0.1px #d9d9d9;">Other</th> <th style=" border-right: solid 0.1px #d9d9d9;">Other</th>
<td></td> <td>@Model.Other</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
...@@ -89,3 +89,53 @@ ...@@ -89,3 +89,53 @@
</div> </div>
</div> </div>
@section Scripts{
<script nonce="KUY8VewuvyUYVEIvEFue4vwyiuf">
var msg = '@TempData["msg"]';
var IsSuccess = '@TempData["IsSuccess"]';
console.log(IsSuccess + msg);
if (msg != '') {
showAlert(IsSuccess, msg);
}
//改變成上傳的檔案名
$('#uploadLicenseFile').on('change', function () {
let file = event.target.files[0];
let fileName = file.name;
$(this).siblings('label').text(fileName);
});
$('#Upload').on('click', function () {
let file = $('#uploadLicenseFile')[0].files[0];
let reader = new FileReader();
reader.onload = function (e) {
let fileContent = e.target.result;
$.ajax({
url: '/user/UploadLicenseAjax', // 替換為適當的控制器方法路徑
type: 'POST', // 或 'GET',根據實際需求
data: {
license: fileContent,
},
success: function (response) {
//console.log(response);
showAlert(response.isSuccess, response.message)
setTimeout(function () {
location.reload();
}, 2000);
},
error: function (xhr, status, error) {
// 在發生錯誤時的處理邏輯
//console.log(xhr.responseText);
showAlert(false, "發生錯誤");
}
});
};
if (file != null) {
reader.readAsText(file);
}
})
</script>
}
\ No newline at end of file
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