!93 feat(#I4ME4A): 增加模拟用户登录模块

* feat: 增加模拟账户登录逻辑
* feat: 增加认证服务模块
* feat: 增加重定向组件
* refactor: 增加后台文件
* wip: 临时提交
This commit is contained in:
Argo 2021-12-14 04:50:25 +00:00
parent affbfe1d88
commit 647cc252d4
13 changed files with 109 additions and 21 deletions

View File

@ -2,6 +2,8 @@
"solution": {
"path": "BootstrapAdmin.sln",
"projects": [
"..\\..\\Longbow.Utility\\src\\Bootstrap.Security.Blazor\\Bootstrap.Security.Blazor.csproj",
"..\\BootstrapBlazor\\src\\BootstrapBlazor\\BootstrapBlazor.csproj",
"src\\blazor\\admin\\BootstrapAdmin.DataAccess.EFCore\\BootstrapAdmin.DataAccess.EFCore.csproj",
"src\\blazor\\admin\\BootstrapAdmin.DataAccess.Models\\BootstrapAdmin.DataAccess.Models.csproj",
"src\\blazor\\admin\\BootstrapAdmin.DataAccess.PetaPoco\\BootstrapAdmin.DataAccess.PetaPoco.csproj",

View File

@ -153,6 +153,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapAdmin.DataAccess.P
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapAdmin.Web.Core", "src\blazor\admin\BootstrapAdmin.Web.Core\BootstrapAdmin.Web.Core.csproj", "{DA143654-C258-410D-B5DC-FE446ED99CE4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapBlazor", "..\BootstrapBlazor\src\BootstrapBlazor\BootstrapBlazor.csproj", "{02BC5E4F-83DF-4255-9831-41D7AE7D4DDC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.Security.Blazor", "..\..\Longbow.Utility\src\Bootstrap.Security.Blazor\Bootstrap.Security.Blazor.csproj", "{A704A8DB-BB87-40DF-9F91-EFF21741BD88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -215,6 +219,14 @@ Global
{DA143654-C258-410D-B5DC-FE446ED99CE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA143654-C258-410D-B5DC-FE446ED99CE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA143654-C258-410D-B5DC-FE446ED99CE4}.Release|Any CPU.Build.0 = Release|Any CPU
{02BC5E4F-83DF-4255-9831-41D7AE7D4DDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02BC5E4F-83DF-4255-9831-41D7AE7D4DDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02BC5E4F-83DF-4255-9831-41D7AE7D4DDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02BC5E4F-83DF-4255-9831-41D7AE7D4DDC}.Release|Any CPU.Build.0 = Release|Any CPU
{A704A8DB-BB87-40DF-9F91-EFF21741BD88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A704A8DB-BB87-40DF-9F91-EFF21741BD88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A704A8DB-BB87-40DF-9F91-EFF21741BD88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A704A8DB-BB87-40DF-9F91-EFF21741BD88}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -251,6 +263,8 @@ Global
{7E3861AB-F797-4A9F-B7CE-0E35751FFCD9} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
{20D03C52-0F8B-47B6-BCA8-CF0812F82722} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
{DA143654-C258-410D-B5DC-FE446ED99CE4} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
{02BC5E4F-83DF-4255-9831-41D7AE7D4DDC} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
{A704A8DB-BB87-40DF-9F91-EFF21741BD88} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {221EAE38-5F75-4391-9A48-E462A9F3B8FC}

View File

@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="6.1.1-beta03" />
<!--<PackageReference Include="BootstrapBlazor" Version="6.1.1-beta03" />-->
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\BootstrapBlazor\src\BootstrapBlazor\BootstrapBlazor.csproj" />
<ProjectReference Include="..\BootstrapAdmin.DataAccess.Models\BootstrapAdmin.DataAccess.Models.csproj" />
</ItemGroup>

View File

@ -1,11 +1,14 @@
<BootstrapBlazorRoot>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<PageTitle>@Title</PageTitle>
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(NotFoundLayout)" />
</NotFound>
</Router>
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<PageTitle>@Title</PageTitle>
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(NotFoundLayout)" />
</NotFound>
</Router>
</CascadingAuthenticationState>
</BootstrapBlazorRoot>

View File

@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\Longbow.Utility\src\Bootstrap.Security.Blazor\Bootstrap.Security.Blazor.csproj" />
<ProjectReference Include="..\BootstrapAdmin.DataAccess.EFCore\BootstrapAdmin.DataAccess.EFCore.csproj" />
<ProjectReference Include="..\BootstrapAdmin.DataAccess.PetaPoco\BootstrapAdmin.DataAccess.PetaPoco.csproj" />
</ItemGroup>

View File

@ -12,14 +12,3 @@
<Select Items="@Items" @bind-Value="Value.Define" ShowLabel="true" />
</div>
</div>
@code {
private IEnumerable<SelectedItem>? Items { get; set; } = typeof(EnumDictDefine).ToSelectList(new SelectedItem("", "全部"));
[Parameter]
[NotNull]
public DictsSearchModel? Value { get; set; }
[Parameter]
public EventCallback<DictsSearchModel> ValueChanged { get; set; }
}

View File

@ -0,0 +1,26 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Models;
namespace BootstrapAdmin.Web.Components
{
/// <summary>
///
/// </summary>
public partial class DictSearch
{
private IEnumerable<SelectedItem>? Items { get; set; } = typeof(EnumDictDefine).ToSelectList(new SelectedItem("", "全部"));
/// <summary>
///
/// </summary>
[Parameter]
[NotNull]
public DictsSearchModel? Value { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public EventCallback<DictsSearchModel> ValueChanged { get; set; }
}
}

View File

@ -0,0 +1,28 @@
namespace BootstrapAdmin.Web.Components
{
/// <summary>
///
/// </summary>
public class RedirectToLogin : ComponentBase
{
[Inject]
[NotNull]
private NavigationManager? Navigation { get; set; }
#if DEBUG
/// <summary>
///
/// </summary>
/// <param name="firstRender"></param>
protected override void OnAfterRender(bool firstRender)
{
Navigation.NavigateTo($"/Account/Login", true);
}
#else
protected override void OnInitialized()
{
Navigation.NavigateTo($"/Account/Login", true);
}
#endif
}
}

View File

@ -1,4 +1,6 @@
using BootstrapAdmin.Web.Services;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Components.Authorization;
using System.Text;
namespace Microsoft.Extensions.DependencyInjection
@ -61,6 +63,9 @@ namespace Microsoft.Extensions.DependencyInjection
// 增加 BootstrapBlazor 组件
services.AddBootstrapBlazor();
// 增加认证授权服务
services.AddBootstrapAdminAuthentication<RoleService>();
// 增加 BootstrapApp 上下文服务
services.AddSingleton<BootstrapAppContext>();

View File

@ -0,0 +1,14 @@
using Bootstrap.Security.Blazor;
namespace BootstrapAdmin.Web.Services
{
class RoleService : IRoleService
{
/// <summary>
/// 通过当前登录用户名获取角色集合方法
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public List<string> GetRolesByUserName(string userName) => new List<string>() { "Administrators" };
}
}

View File

@ -30,4 +30,7 @@
<Footer>
<div class="flex-fill text-center text-dark">Bootstrap Admin Blazor 版 &copy;</div>
</Footer>
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
</Layout>

View File

@ -1,5 +1,6 @@
{
"DetailedErrors": true,
"SimulateUserName": "Admin",
"AutoGenerateDatabase": true,
"DB": [
{

View File

@ -21,6 +21,7 @@
"Url": "https://client.blazor.zone/api/Interface/Log"
}
},
"SimulateUserName": "Admin",
"AutoGenerateDatabase": true,
"DB": [
{