完成Web页面登录逻辑
This commit is contained in:
parent
4bb5c1a36b
commit
ea00a9fc16
|
@ -0,0 +1,12 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace Sinet.Universal.Admin
|
||||
{
|
||||
public interface IUserAccountAppService : IApplicationService, ITransientDependency
|
||||
{
|
||||
Task<string> LoginByPass(string name, string pass, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace Sinet.Universal.Admin.RCL
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(AdminApplicationContractsModule)
|
||||
)]
|
||||
public class AdminBlazorClientModule
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Sinet.Universal.Admin.RCL.Services;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace Sinet.Universal.Admin.RCL
|
||||
|
@ -15,6 +16,8 @@ namespace Sinet.Universal.Admin.RCL
|
|||
context.Services.AddScoped<CookieStorage>();
|
||||
context.Services.AddScoped<GlobalConfig>();
|
||||
|
||||
context.Services.AddScoped<IAppService,BaseAppService>();
|
||||
|
||||
context.Services.AddScoped<AuthenticationService>();
|
||||
context.Services.AddScoped<CustomAuthenticationStateProvider>();
|
||||
context.Services.AddScoped<AuthenticationStateProvider>(s => s.GetRequiredService<CustomAuthenticationStateProvider>());
|
||||
|
|
|
@ -1,13 +1,40 @@
|
|||
@using Sinet.Universal.Admin.RCL.Shared
|
||||
<Router AppAssembly="@typeof(App).Assembly">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
<LayoutView Layout="@typeof(MainLayout)">
|
||||
<p role="alert">Sorry, there's nothing at this address.</p>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
@inherits ProComponentBase
|
||||
<CascadingAuthenticationState>
|
||||
<Router AppAssembly="@typeof(App).Assembly">
|
||||
<Found Context="routeData">
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
||||
@* <FocusOnNavigate RouteData="@routeData" Selector="h1" /> *@
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<MApp>
|
||||
<div style="height:100%;margin:0;padding:0;">
|
||||
<Sinet.Universal.Admin.RCL.Pages.Authentication.Login_v1 />
|
||||
</div>
|
||||
</MApp>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
<LayoutView Layout="@typeof(MainLayout)">
|
||||
<p role="alert">Sorry, there's nothing at this address.</p>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
</CascadingAuthenticationState>
|
||||
|
||||
@code{
|
||||
|
||||
[Inject]
|
||||
IAppService appService { get; set;}
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
appService.ReAuthenticate(CurrentUser);
|
||||
base.OnInitialized();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Users;
|
||||
|
||||
namespace Sinet.Universal.Admin.RCL
|
||||
{
|
||||
public interface IAppService
|
||||
{
|
||||
void ReAuthenticate(ICurrentUser user);
|
||||
|
||||
void AuthenticateUser(IEnumerable<Claim> claims);
|
||||
}
|
||||
}
|
|
@ -214,10 +214,12 @@
|
|||
</MCol>
|
||||
</MRow>
|
||||
|
||||
<Sinet.Universal.Admin.Web.Pages.App.Invoice.Components.InvoiceList />
|
||||
<Sinet.Universal.Admin.RCL.Pages.App.Invoice.Components.InvoiceList />
|
||||
|
||||
@code {
|
||||
|
||||
|
||||
|
||||
private List<DataTableHeader<PermissionDto>> _headers = new List<DataTableHeader<PermissionDto>>
|
||||
{
|
||||
new() { Text = "MODULE", Sortable = false, Value = nameof(PermissionDto.Module) },
|
||||
|
@ -251,6 +253,14 @@
|
|||
|
||||
_userData = UserService.GetList().FirstOrDefault(u => u.Id == Id);
|
||||
|
||||
if (CurrentUser != null && _userData != null)
|
||||
{
|
||||
_userData.UserName = CurrentUser.Name;
|
||||
_userData.Email = CurrentUser.Email;
|
||||
_userData.Mobile = CurrentUser.PhoneNumber;
|
||||
_userData.Role = CurrentUser.Roles.First();
|
||||
}
|
||||
|
||||
UpdateTabTitle();
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ public class UserPage
|
|||
|
||||
public List<UserDto> GetPageDatas()
|
||||
{
|
||||
|
||||
|
||||
return GetFilterDatas().Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
<h5 class="mt-2 mb-12">Welcome to Sinet.Universal.Admin! 👋</h5>
|
||||
|
||||
<MTextField TValue="string"
|
||||
Label="Email"
|
||||
Label="Email" OnInput="NameChanged"
|
||||
Placeholder="john@example.com"
|
||||
Outlined
|
||||
Outlined @bind-Value="Name"
|
||||
HideDetails="@("auto")">
|
||||
</MTextField>
|
||||
<MTextField TValue="string"
|
||||
Class="mt-10"
|
||||
Label="Password"
|
||||
Class="mt-10" OnInput="PassChanged"
|
||||
Label="Password" @bind-Value="Pass"
|
||||
Type="@(_show ? "text" : "password")"
|
||||
Placeholder="john@example.com"
|
||||
AppendIcon="@(_show ? "mdi-eye" : "mdi-eye-off")"
|
||||
|
|
|
@ -20,6 +20,18 @@ public partial class Login
|
|||
[Parameter]
|
||||
public StringNumber? Elevation { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> NameChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string? Pass { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> PassChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string CreateAccountRoute { get; set; } = $"pages/authentication/register-v1";
|
||||
|
||||
|
|
|
@ -6,18 +6,11 @@
|
|||
@inject NavigationManager Nav
|
||||
|
||||
<div class="d-flex align-center" style="height:calc(100% - 96px)">
|
||||
<Sinet.Universal.Admin.RCL.Pages.Authentication.Components.Login OnLogin="LoginTo" />
|
||||
<Sinet.Universal.Admin.RCL.Pages.Authentication.Components.Login @bind-Name="@UserName" @bind-Pass="@Password" OnLogin="LoginTo" />
|
||||
</div>
|
||||
|
||||
<MFooter Padless Height=96 Style="background:transparent;">
|
||||
<MRow Justify="JustifyTypes.Center">
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank" class="neutral-lighten-3--text" style="text-decoration:none;font-size:14px;">浙ICP备2021013592号-1</a>
|
||||
</MRow>
|
||||
</MFooter>
|
||||
|
||||
@code{
|
||||
void LoginTo()
|
||||
{
|
||||
Nav.NavigateTo(GlobalVariables.DefaultRoute, true);
|
||||
}
|
||||
}
|
||||
</MFooter>
|
|
@ -0,0 +1,54 @@
|
|||
using System.Security.Claims;
|
||||
using Volo.Abp.Identity;
|
||||
|
||||
namespace Sinet.Universal.Admin.RCL.Pages.Authentication
|
||||
{
|
||||
public partial class Login_v1
|
||||
{
|
||||
[Inject]
|
||||
public IUserAccountAppService UserAccountAppService { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IAppService _appService { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IIdentityUserAppService UserAppService { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IPopupService PopupService { get; set; }
|
||||
|
||||
public string? UserName { get; set; }
|
||||
|
||||
public string? Password { get; set; }
|
||||
|
||||
public async Task LoginTo()
|
||||
{
|
||||
try
|
||||
{
|
||||
//var users = await UserAppService.GetListAsync(new GetIdentityUsersInput());
|
||||
var res = await UserAccountAppService.LoginByPass(UserName, Password);
|
||||
|
||||
if(res == "Succeeded")
|
||||
{
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim(ClaimTypes.Sid, UserName),
|
||||
new Claim(ClaimTypes.Name, UserName )
|
||||
};
|
||||
//_appService.AuthenticateUser(claims);
|
||||
await PopupService.EnqueueSnackbarAsync("登录成功,正在跳转!", AlertTypes.Success);
|
||||
|
||||
await Task.Delay(1000);
|
||||
Nav.NavigateTo($"/app/redirect_login?name={UserName}&pass={Password}", true);
|
||||
}
|
||||
else
|
||||
await PopupService.EnqueueSnackbarAsync("登录失败!", AlertTypes.Error);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await PopupService.EnqueueSnackbarAsync($"登录失败: {ex.Message}", AlertTypes.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
{
|
||||
if(firstRender)
|
||||
{
|
||||
Nav.NavigateTo(GlobalVariables.DefaultLoginRoute, true);
|
||||
Nav.NavigateTo(GlobalVariables.DefaultRoute, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
using Sinet.Universal.Admin.RCL.Pages.App.User;
|
||||
using System.Security.Claims;
|
||||
using Volo.Abp.Users;
|
||||
using static Volo.Abp.Identity.IdentityPermissions;
|
||||
|
||||
namespace Sinet.Universal.Admin.RCL.Services
|
||||
{
|
||||
public class BaseAppService : IAppService
|
||||
{
|
||||
private readonly CustomAuthenticationStateProvider _authenticationStateProvider;
|
||||
|
||||
public BaseAppService(CustomAuthenticationStateProvider authenticationStateProvider)
|
||||
{
|
||||
_authenticationStateProvider = authenticationStateProvider;
|
||||
}
|
||||
|
||||
public void AuthenticateUser(IEnumerable<Claim> claims)
|
||||
{
|
||||
_authenticationStateProvider.AuthenticateUser(claims);
|
||||
}
|
||||
|
||||
public void ReAuthenticate(ICurrentUser user)
|
||||
{
|
||||
if(user != null && user.IsAuthenticated)
|
||||
{
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim(ClaimTypes.Sid, user.Id.ToString()),
|
||||
new Claim(ClaimTypes.Name, user.Name )
|
||||
};
|
||||
AuthenticateUser(claims);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.13" />
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.Components" Version="7.4.1" />
|
||||
<PackageReference Include="Volo.Abp.Identity.AspNetCore" Version="7.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -36,7 +37,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
<Folder Include="Base\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -179,7 +179,6 @@
|
|||
"Children": [
|
||||
{
|
||||
"Id": 28,
|
||||
"Hide": true,
|
||||
"Title": "Account Settings",
|
||||
"Icon": "mdi-circle",
|
||||
"Href": "pages/others/account-settings"
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System;
|
||||
using Volo.Abp.Account.Settings;
|
||||
using Volo.Abp.Settings;
|
||||
using Volo.Abp;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Identity.AspNetCore;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Sinet.Universal.Admin
|
||||
{
|
||||
public class UserAccountAppService : ApplicationService, IUserAccountAppService
|
||||
{
|
||||
private readonly ILogger<ServerInfoAppService> _logger;
|
||||
|
||||
protected AbpSignInManager SignInManager { get; }
|
||||
protected IdentityUserManager UserManager { get; }
|
||||
protected UserManager<Volo.Abp.Identity.IdentityUser> _userManager { get; }
|
||||
protected ISettingProvider SettingProvider { get; }
|
||||
protected IdentitySecurityLogManager IdentitySecurityLogManager { get; }
|
||||
protected IOptions<IdentityOptions> IdentityOptions { get; }
|
||||
|
||||
|
||||
public UserAccountAppService(
|
||||
ILogger<ServerInfoAppService> logger
|
||||
, AbpSignInManager signInManager
|
||||
, UserManager<Volo.Abp.Identity.IdentityUser> userManager
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
SignInManager = signInManager;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public async Task<string> LoginByPass(string name, string pass, CancellationToken cancellationToken = default)
|
||||
{
|
||||
_logger.LogInformation("LoginByPass");
|
||||
|
||||
var user = await _userManager.FindByNameAsync(name);
|
||||
if(user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = await SignInManager.CheckPasswordSignInAsync(user, pass, false);
|
||||
|
||||
if(result.Succeeded)
|
||||
return result.ToString();
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("app/redirect_login")]
|
||||
public async Task<IActionResult> RedirectLogin(string name, string pass, string redirect = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = await SignInManager.PasswordSignInAsync(name, pass, false, false);
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return new RedirectResult(redirect??"/");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
using Volo.Abp.Account;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.AutoMapper;
|
||||
using Volo.Abp.FeatureManagement;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Identity.AspNetCore;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.PermissionManagement;
|
||||
using Volo.Abp.SettingManagement;
|
||||
|
@ -21,6 +24,17 @@ namespace Sinet.Universal.Admin;
|
|||
)]
|
||||
public class AdminApplicationModule : AbpModule
|
||||
{
|
||||
|
||||
//public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
//{
|
||||
// PreConfigure<IdentityBuilder>(identityBuilder =>
|
||||
// {
|
||||
// identityBuilder.AddSignInManager<AbpSignInManager>()
|
||||
// .AddUserValidator<AbpIdentityUserValidator>(); ;
|
||||
// });
|
||||
// base.PreConfigureServices(context);
|
||||
//}
|
||||
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpAutoMapperOptions>(options =>
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Account.Application" Version="7.4.1" />
|
||||
<PackageReference Include="Volo.Abp.Identity.Application" Version="7.4.1" />
|
||||
<PackageReference Include="Volo.Abp.Identity.AspNetCore" Version="7.4.1" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.Application" Version="7.4.1" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Application" Version="7.4.1" />
|
||||
<PackageReference Include="Volo.Abp.FeatureManagement.Application" Version="7.4.1" />
|
||||
|
|
|
@ -85,6 +85,7 @@ public class AdminBlazorModule : AbpModule
|
|||
options.UseLocalServer();
|
||||
options.UseAspNetCore();
|
||||
});
|
||||
builder.AddServer(options => { options.UseAspNetCore().DisableTransportSecurityRequirement(); });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:44351/",
|
||||
"applicationUrl": "http://localhost:44351/",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"App": {
|
||||
"SelfUrl": "https://localhost:44351",
|
||||
"RedirectAllowedUrls": "https://localhost:44351"
|
||||
"SelfUrl": "http://localhost:44351",
|
||||
"RedirectAllowedUrls": "http://localhost:44351"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Default": "Server=localhost;Port=3306;Database=su-admin;Uid=root;Pwd=123456;"
|
||||
},
|
||||
"AuthServer": {
|
||||
"Authority": "https://localhost:44351",
|
||||
"Authority": "http://localhost:44351",
|
||||
"RequireHttpsMetadata": "false"
|
||||
},
|
||||
"StringEncryption": {
|
||||
|
|
Loading…
Reference in New Issue