119 lines
3.3 KiB
C#
119 lines
3.3 KiB
C#
using AppLibs.Libs;
|
|
using SysApp.Models;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Connections.Features;
|
|
using System.Diagnostics.Metrics;
|
|
using System.Security.Cryptography;
|
|
using System.Text.Encodings;
|
|
using System.Text;
|
|
using AppLibs.Libs.Crypt;
|
|
|
|
namespace SysApp.Controllers
|
|
{
|
|
public class StorageController : Controller
|
|
{
|
|
|
|
|
|
[PageInfor("6101", "Config Storage")]
|
|
public Task<IActionResult> Index()
|
|
{
|
|
return this.ViewAsync();
|
|
}
|
|
|
|
[PageInfor("6102", "Type Storage")]
|
|
public Task<IActionResult> Type()
|
|
{
|
|
return this.ViewAsync();
|
|
}
|
|
|
|
[PageInfor("6103", "Validation Domain")]
|
|
public Task<IActionResult> ValidationDomain()
|
|
{
|
|
return this.ViewAsync();
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> AddValidationDomain([FromForm] ValidationDomainModel model)
|
|
{
|
|
return Json(await model.AddAsync());
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> GetValidationDomain([FromForm] ValidationDomainModel model)
|
|
{
|
|
return await model.GetValidationDomainAsync();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> UpdateValidationDomain([FromForm] ValidationDomainModel model)
|
|
{
|
|
return Json(await model.UpdateAsync());
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> AddType([FromBody] TypeStorageServerModel model)
|
|
{
|
|
return Json(await model.AddAsync());
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> GetTypeStorage([FromForm] TypeStorageServerModel model)
|
|
{
|
|
return await model.GetTypeStoragesAsync();
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetTypeStorage()
|
|
{
|
|
return await TypeStorageServerModel.GetAllTypeStorage();
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetValidationDomain()
|
|
{
|
|
return await ValidationDomainModel.GetAllValidationDomain();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> UpdateType([FromBody] TypeStorageServerModel model)
|
|
{
|
|
return Json(await model.UpdateAsync());
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GenerationAccessToken()
|
|
{
|
|
var t1 = Task<string>.Run(() =>
|
|
{
|
|
var g = Guid.NewGuid();
|
|
return Base64UrlTextEncoder.Encode(g.ToByteArray().Concat(BitConverter.GetBytes(DateTime.UtcNow.ToFileTime())).ToArray());
|
|
});
|
|
|
|
var t2 = Task<string>.Run(() => {
|
|
var g = Guid.NewGuid();
|
|
var bytes = BitConverter.GetBytes(DateTime.UtcNow.Ticks);
|
|
|
|
Array.Resize(ref bytes, 16);
|
|
|
|
|
|
byte[] data = new byte[32];
|
|
bytes.CopyTo(data, 0);
|
|
g.ToByteArray().CopyTo(data, 16);
|
|
var hash = new CRC64();
|
|
|
|
return hash.HashToString(data);
|
|
|
|
});
|
|
await Task.WhenAll(t1, t2);
|
|
|
|
return Json(new
|
|
{
|
|
idToken = t2.Result.ToLower(),
|
|
tokenValue = t1.Result
|
|
});
|
|
}
|
|
}
|
|
}
|