优化 登录流程

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="/" /> <base href="/" />
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" /> <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 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" /> <link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet @rendermode="InteractiveServer" /> <HeadOutlet @rendermode="InteractiveServer" />
</head> </head>

View File

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

View File

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

View File

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

View File

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

View File

@ -51,9 +51,9 @@ namespace Learn.VideoAnalysis
builder.Configuration.GetSection("AppConfig").Bind(AppCommon.Config); builder.Configuration.GetSection("AppConfig").Bind(AppCommon.Config);
//³õʼ»¯ ²å¼þ //³õʼ»¯ ²å¼þ
Speaker.Init(); //Speaker.Init();
RedisExpand.Init(); //RedisExpand.Init();
SenseVoice.Init(); //SenseVoice.Init();
builder.Services.AddScoped(sp => builder.Services.AddScoped(sp =>
@ -81,13 +81,7 @@ namespace Learn.VideoAnalysis
builder.Services.AddHttpClient(); builder.Services.AddHttpClient();
builder.Services.AddSingleton<MoonshotClient>(); builder.Services.AddSingleton<MoonshotClient>();
builder.Services.AddSingleton<IBserGPT, KIMI_GPT>(); 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(); var app = builder.Build();