优化 登录流程

This commit is contained in:
小肥羊 2024-11-12 11:07:45 +08:00
parent 0229ae490b
commit dcc3664b0c
7 changed files with 50 additions and 38 deletions

View File

@ -7,8 +7,9 @@
<base href="/" />
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" />
<link href="_content/AntDesign.ProLayout/css/ant-design-pro-layout-blazor.css" rel="stylesheet" />
<link rel="stylesheet" href="Learn.VideoAnalysis.bundle.scp.css" />
<link href="./css/site.css" rel="stylesheet" />
<link href="Learn.VideoAnalysis.styles.css" rel="stylesheet" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet @rendermode="InteractiveServer" />
</head>

View File

@ -1,6 +1,7 @@
using AntDesign.Extensions.Localization;
using AntDesign.ProLayout;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using Microsoft.Identity.Client.Extensions.Msal;
using System.Globalization;
using System.Net.Http.Json;
@ -14,6 +15,7 @@ namespace VideoAnalysisRazor.Layouts
[Inject] IHttpContextAccessor HttpContextAccessor { get; set; } = default!;
[Inject] private ReuseTabsService TabService { get; set; }
[Inject] private ProtectedSessionStorage session { get; set; } = default!;
bool collapsed;
void Toggle()
@ -21,13 +23,16 @@ namespace VideoAnalysisRazor.Layouts
collapsed = !collapsed;
}
protected override async Task OnInitializedAsync()
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!CheckLogin())
if (!await CheckLogin())
{
NavigationManager.NavigateTo("/Login");
return;
}
}
protected override async Task OnInitializedAsync()
{
_menuData = [
new MenuDataItem
{
@ -46,9 +51,9 @@ namespace VideoAnalysisRazor.Layouts
];
}
public bool CheckLogin()
public async Task<bool> CheckLogin()
{
return HttpContextAccessor.HttpContext?.Session.GetInt32("Login") == 1;
return (await session.GetAsync<bool>("Login")).Value;
}
void Reload()
{

View File

@ -7,7 +7,7 @@
@using VideoAnalysisCore.Model.Dto
<div style="width:100%;height:100%">
<section style="width:100%;height:100%">
<!-- 背景颜色 -->
<div class="color"></div>
<div class="color"></div>
@ -22,7 +22,7 @@
<!-- 登录框 -->
<div class="container">
<div class="form">
<h2>登录</h2>
<h2>登录 视频分析平台</h2>
<form>
<div class="inputBox">
<input type="text" placeholder="账号" @bind="InputAccount">
@ -32,16 +32,18 @@
</div>
<div class="inputBox">
<input value="登录" @onclick="() => LoginFunAsync()">
<input type="button" class="submit" value="登录" @onclick="() => LoginFunAsync()">
</div>
@* <p class="forget">
忘记密码?<a href="#">
忘记密码?
<a href="#">
点击这里
</a>
</p>
<p class="forget">
没有账户?<a href="#">
</p> *@
@* <p class="forget">
没有账户?
<a href="#">
注册
</a>
</p> *@
@ -49,5 +51,4 @@
</div>
</div>
</div>
</div>
</section>

View File

@ -1,6 +1,7 @@
using AntDesign;
using AntDesign.TableModels;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
@ -19,6 +20,7 @@ namespace Learn.VideoAnalysis.Components.Pages
[Inject] private Repository<VideoTask> taskDB { get; set; } = default!;
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
[Inject] private INotificationService _notice { get; set; } = default!;
[Inject] private ProtectedSessionStorage session { get; set; } = default!;
/// <summary>
/// 输入的账号
@ -51,8 +53,7 @@ namespace Learn.VideoAnalysis.Components.Pages
}
if (InputAccount == "admin" && InputPassword == "q1w2e3!@#")
{
HttpContextAccessor.HttpContext?.Session
.SetInt32("Login", 1);
await session.SetAsync("Login", true);
NavigationManager.NavigateTo("/");
}
else

View File

@ -142,6 +142,7 @@ section {
position: relative;
width: 400px;
min-height: 400px;
height: 400px;
background: rgba(255, 255, 255, 0.1);
display: flex;
justify-content: center;
@ -158,6 +159,7 @@ section {
width: 100%;
height: 100%;
padding: 50px;
background: rgba(255, 255, 255, 0.1);
}
/* 되쩌깃痙湳駕 */
@ -218,14 +220,14 @@ section {
/* 되쩌객큐湳駕 */
.form .inputBox input[type="submit"] {
background: #fff;
color: #666;
max-width: 100px;
margin-bottom: 20px;
font-weight: 600;
cursor: pointer;
}
.submit {
background: #fff !important;
color: #666 !important;
max-width: 100px;
margin-bottom: 20px;
font-weight: 600;
cursor: pointer !important;
}
.forget {
margin-top: 6px;

View File

@ -1,7 +1,15 @@
<Router AppAssembly="typeof(Program).Assembly">
@using Learn.VideoAnalysis.Components.Pages
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<CascadingValue Value="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(VideoAnalysisRazor.Layouts.BasicLayout)" />
@if (routeData.PageType == typeof(Login))
{
<RouteView RouteData="@routeData" />
}
else
{
<RouteView RouteData="routeData" DefaultLayout="typeof(VideoAnalysisRazor.Layouts.BasicLayout)" />
}
</CascadingValue>
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>

View File

@ -51,9 +51,9 @@ namespace Learn.VideoAnalysis
builder.Configuration.GetSection("AppConfig").Bind(AppCommon.Config);
//³õʼ»¯ ²å¼þ
Speaker.Init();
RedisExpand.Init();
SenseVoice.Init();
//Speaker.Init();
//RedisExpand.Init();
//SenseVoice.Init();
builder.Services.AddScoped(sp =>
@ -81,13 +81,7 @@ namespace Learn.VideoAnalysis
builder.Services.AddHttpClient();
builder.Services.AddSingleton<MoonshotClient>();
builder.Services.AddSingleton<IBserGPT, KIMI_GPT>();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
var app = builder.Build();