update TWA Management v0.0.1

This commit is contained in:
2025-11-05 10:08:06 +07:00
parent d4e91c7960
commit b4b191f829
73 changed files with 2249 additions and 418 deletions

View File

@ -0,0 +1,17 @@
using AppLibs.Libs;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace TWASys_App.Controllers
{
[AllowAnonymous]
public class LoginController : Controller
{
[Layout(LayoutOptions.Custom, "Login")]
[PageInfor("10001", "Login")]
public async Task<IActionResult> Index()
{
return await this.ViewAsync();
}
}
}

View File

@ -1,13 +1,9 @@
using AppLibs.Libs;
using TWASys_App.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;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebUtilities;
using System.Security.Cryptography;
using TWASys_App.Models;
using TWASys_App.Models.ServerInfo;
namespace TWASys_App.Controllers
@ -83,36 +79,40 @@ namespace TWASys_App.Controllers
return Json(await model.UpdateAsync());
}
[HttpPost]
public async Task<IActionResult> SetStorageData([FromForm] StorageModel model)
{
return Json(await model.AddAsync());
}
[HttpGet]
public async Task<IActionResult> GenerationAccessToken()
{
var t1 = Task<string>.Run(() =>
var t1 = Task<Guid>.Run(() =>
{
var g = Guid.NewGuid();
return Base64UrlTextEncoder.Encode(g.ToByteArray().Concat(BitConverter.GetBytes(DateTime.UtcNow.ToFileTime())).ToArray());
return UUID7.NewUuid7();
});
var t2 = Task<string>.Run(() => {
var g = Guid.NewGuid();
var bytes = BitConverter.GetBytes(DateTime.UtcNow.Ticks);
var tokenValue = Base64UrlTextEncoder.Encode(
Guid.NewGuid().ToByteArray()
.Concat(BitConverter.GetBytes(DateTime.UtcNow.ToFileTimeUtc()))
.ToArray()
);
using var sha = SHA256.Create();
var idToken = WebEncoders.Base64UrlEncode(sha.ComputeHash(
System.Text.Encoding.UTF8.GetBytes(tokenValue)
));
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);
return idToken;
});
await Task.WhenAll(t1, t2);
return Json(new
{
idToken = t2.Result.ToLower(),
tokenValue = t1.Result
idToken = t1.Result.ToString(),
tokenValue = t2.Result.ToLower()
});
}