Learn.VideoAnalysis/VideoAnalysis/Components/Pages/Login.razor.cs

73 lines
2.3 KiB
C#

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;
using System.Linq.Expressions;
using System.Threading.Tasks;
using VideoAnalysisCore.Common;
using VideoAnalysisCore.Enum;
using VideoAnalysisCore.Model;
using VideoAnalysisCore.Model.Dto;
namespace Learn.VideoAnalysis.Components.Pages
{
public partial class Login : ComponentBase
{
[Inject] IHttpContextAccessor HttpContextAccessor { get; set; } = default!;
[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>
/// 输入的账号
/// </summary>
public string InputAccount = string.Empty;
/// <summary>
/// 输入的密码
/// </summary>
public string InputPassword= string.Empty;
/// <summary>
/// 初始化
/// </summary>
protected override void OnInitialized()
{
}
/// <summary>
/// 登录函数
/// </summary>
public async Task LoginFunAsync()
{
if (string.IsNullOrEmpty(InputAccount) || string.IsNullOrEmpty(InputPassword))
{
await _notice.Open(new NotificationConfig()
{
Message = "提示",
Description = "账号/密码必填",
NotificationType = NotificationType.Warning
});
}
if (InputAccount == "admin" && InputPassword == "q1w2e3!@#")
{
await session.SetAsync("Login", true);
NavigationManager.NavigateTo("/");
}
else
{
await _notice.Open(new NotificationConfig()
{
Message = "提示",
Description = "账号/密码输入错误",
NotificationType = NotificationType.Warning
});
}
}
}
}