diff --git a/src/common/Sinet.Universal.Admin.Application.Contracts/Account/IServerInfoAppService.cs b/src/common/Sinet.Universal.Admin.Application.Contracts/Account/IServerInfoAppService.cs new file mode 100644 index 0000000..f33835b --- /dev/null +++ b/src/common/Sinet.Universal.Admin.Application.Contracts/Account/IServerInfoAppService.cs @@ -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 LoginByPass(string name, string pass, CancellationToken cancellationToken = default); + } +} diff --git a/src/common/Sinet.Universal.Admin.RCL/AdminBlazorClientModule.cs b/src/common/Sinet.Universal.Admin.RCL/AdminBlazorClientModule.cs deleted file mode 100644 index 9de998c..0000000 --- a/src/common/Sinet.Universal.Admin.RCL/AdminBlazorClientModule.cs +++ /dev/null @@ -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 - { - } -} diff --git a/src/common/Sinet.Universal.Admin.RCL/AdminBlazorServerModule.cs b/src/common/Sinet.Universal.Admin.RCL/AdminBlazorServerModule.cs index 64029e7..50e6302 100644 --- a/src/common/Sinet.Universal.Admin.RCL/AdminBlazorServerModule.cs +++ b/src/common/Sinet.Universal.Admin.RCL/AdminBlazorServerModule.cs @@ -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(); context.Services.AddScoped(); + context.Services.AddScoped(); + context.Services.AddScoped(); context.Services.AddScoped(); context.Services.AddScoped(s => s.GetRequiredService()); diff --git a/src/common/Sinet.Universal.Admin.RCL/App.razor b/src/common/Sinet.Universal.Admin.RCL/App.razor index fb05966..a949a53 100644 --- a/src/common/Sinet.Universal.Admin.RCL/App.razor +++ b/src/common/Sinet.Universal.Admin.RCL/App.razor @@ -1,13 +1,40 @@ @using Sinet.Universal.Admin.RCL.Shared - - - - - - - Not found - -

Sorry, there's nothing at this address.

-
-
-
+@inherits ProComponentBase + + + + + + + @* *@ + + + +
+ +
+
+
+
+
+ + Not found + +

Sorry, there's nothing at this address.

+
+
+
+
+ +@code{ + + [Inject] + IAppService appService { get; set;} + + protected override void OnInitialized() + { + appService.ReAuthenticate(CurrentUser); + base.OnInitialized(); + } + +} \ No newline at end of file diff --git a/src/common/Sinet.Universal.Admin.RCL/Interfaces/IAppService.cs b/src/common/Sinet.Universal.Admin.RCL/Interfaces/IAppService.cs new file mode 100644 index 0000000..cc17504 --- /dev/null +++ b/src/common/Sinet.Universal.Admin.RCL/Interfaces/IAppService.cs @@ -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 claims); + } +} diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/View.razor b/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/View.razor index 069270a..bbf50dc 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/View.razor +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/View.razor @@ -214,10 +214,12 @@ - + @code { + + private List> _headers = new List> { 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(); } diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/ViewModel/UserPage.cs b/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/ViewModel/UserPage.cs index abdc180..eee50cf 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/ViewModel/UserPage.cs +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/ViewModel/UserPage.cs @@ -59,6 +59,8 @@ public class UserPage public List GetPageDatas() { + + return GetFilterDatas().Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); } } diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Components/Login.razor b/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Components/Login.razor index 30c95b1..bd33950 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Components/Login.razor +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Components/Login.razor @@ -8,14 +8,14 @@
Welcome to Sinet.Universal.Admin! 👋
NameChanged { get; set; } + + [Parameter] + public string? Pass { get; set; } + + [Parameter] + public EventCallback PassChanged { get; set; } + [Parameter] public string CreateAccountRoute { get; set; } = $"pages/authentication/register-v1"; diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Login-v1.razor b/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Login-v1.razor index 4b6787d..b131eb2 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Login-v1.razor +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Login-v1.razor @@ -6,18 +6,11 @@ @inject NavigationManager Nav
- +
浙ICP备2021013592号-1 - - -@code{ - void LoginTo() - { - Nav.NavigateTo(GlobalVariables.DefaultRoute, true); - } -} \ No newline at end of file + \ No newline at end of file diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Login-v1.razor.cs b/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Login-v1.razor.cs new file mode 100644 index 0000000..17977ea --- /dev/null +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/Authentication/Login-v1.razor.cs @@ -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 + { + 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); + } + } + } +} diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/Home/Index.razor b/src/common/Sinet.Universal.Admin.RCL/Pages/Home/Index.razor index e0521c4..131826a 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Pages/Home/Index.razor +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/Home/Index.razor @@ -9,7 +9,7 @@ { if(firstRender) { - Nav.NavigateTo(GlobalVariables.DefaultLoginRoute, true); + Nav.NavigateTo(GlobalVariables.DefaultRoute, false); } } } diff --git a/src/common/Sinet.Universal.Admin.RCL/Services/BaseAppService.cs b/src/common/Sinet.Universal.Admin.RCL/Services/BaseAppService.cs new file mode 100644 index 0000000..c03afff --- /dev/null +++ b/src/common/Sinet.Universal.Admin.RCL/Services/BaseAppService.cs @@ -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 claims) + { + _authenticationStateProvider.AuthenticateUser(claims); + } + + public void ReAuthenticate(ICurrentUser user) + { + if(user != null && user.IsAuthenticated) + { + var claims = new List + { + new Claim(ClaimTypes.Sid, user.Id.ToString()), + new Claim(ClaimTypes.Name, user.Name ) + }; + AuthenticateUser(claims); + } + + } + } +} diff --git a/src/common/Sinet.Universal.Admin.RCL/Sinet.Universal.Admin.RCL.csproj b/src/common/Sinet.Universal.Admin.RCL/Sinet.Universal.Admin.RCL.csproj index ccebd35..2338944 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Sinet.Universal.Admin.RCL.csproj +++ b/src/common/Sinet.Universal.Admin.RCL/Sinet.Universal.Admin.RCL.csproj @@ -17,6 +17,7 @@ + @@ -36,7 +37,7 @@ - + diff --git a/src/common/Sinet.Universal.Admin.RCL/wwwroot/nav/nav.json b/src/common/Sinet.Universal.Admin.RCL/wwwroot/nav/nav.json index 399f5a3..60077ba 100644 --- a/src/common/Sinet.Universal.Admin.RCL/wwwroot/nav/nav.json +++ b/src/common/Sinet.Universal.Admin.RCL/wwwroot/nav/nav.json @@ -179,7 +179,6 @@ "Children": [ { "Id": 28, - "Hide": true, "Title": "Account Settings", "Icon": "mdi-circle", "Href": "pages/others/account-settings" diff --git a/src/server/Sinet.Universal.Admin.Application/Account/UserAccountAppService.cs b/src/server/Sinet.Universal.Admin.Application/Account/UserAccountAppService.cs new file mode 100644 index 0000000..f1ed0ae --- /dev/null +++ b/src/server/Sinet.Universal.Admin.Application/Account/UserAccountAppService.cs @@ -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 _logger; + + protected AbpSignInManager SignInManager { get; } + protected IdentityUserManager UserManager { get; } + protected UserManager _userManager { get; } + protected ISettingProvider SettingProvider { get; } + protected IdentitySecurityLogManager IdentitySecurityLogManager { get; } + protected IOptions IdentityOptions { get; } + + + public UserAccountAppService( + ILogger logger + , AbpSignInManager signInManager + , UserManager userManager + ) + { + _logger = logger; + SignInManager = signInManager; + _userManager = userManager; + } + + public async Task 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 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; + } + } +} diff --git a/src/server/Sinet.Universal.Admin.Application/AdminApplicationModule.cs b/src/server/Sinet.Universal.Admin.Application/AdminApplicationModule.cs index c42ff69..e294622 100644 --- a/src/server/Sinet.Universal.Admin.Application/AdminApplicationModule.cs +++ b/src/server/Sinet.Universal.Admin.Application/AdminApplicationModule.cs @@ -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.AddSignInManager() + // .AddUserValidator(); ; + // }); + // base.PreConfigureServices(context); + //} + public override void ConfigureServices(ServiceConfigurationContext context) { Configure(options => diff --git a/src/server/Sinet.Universal.Admin.Application/Sinet.Universal.Admin.Application.csproj b/src/server/Sinet.Universal.Admin.Application/Sinet.Universal.Admin.Application.csproj index e498a38..732a5ba 100644 --- a/src/server/Sinet.Universal.Admin.Application/Sinet.Universal.Admin.Application.csproj +++ b/src/server/Sinet.Universal.Admin.Application/Sinet.Universal.Admin.Application.csproj @@ -16,6 +16,7 @@ + diff --git a/src/server/Sinet.Universal.Admin.Server.Host/AdminBlazorModule.cs b/src/server/Sinet.Universal.Admin.Server.Host/AdminBlazorModule.cs index b0f7562..6a1c82a 100644 --- a/src/server/Sinet.Universal.Admin.Server.Host/AdminBlazorModule.cs +++ b/src/server/Sinet.Universal.Admin.Server.Host/AdminBlazorModule.cs @@ -85,6 +85,7 @@ public class AdminBlazorModule : AbpModule options.UseLocalServer(); options.UseAspNetCore(); }); + builder.AddServer(options => { options.UseAspNetCore().DisableTransportSecurityRequirement(); }); }); } diff --git a/src/server/Sinet.Universal.Admin.Server.Host/Properties/launchSettings.json b/src/server/Sinet.Universal.Admin.Server.Host/Properties/launchSettings.json index ac8302a..79322c7 100644 --- a/src/server/Sinet.Universal.Admin.Server.Host/Properties/launchSettings.json +++ b/src/server/Sinet.Universal.Admin.Server.Host/Properties/launchSettings.json @@ -19,7 +19,7 @@ "commandName": "Project", "dotnetRunMessages": "true", "launchBrowser": true, - "applicationUrl": "https://localhost:44351/", + "applicationUrl": "http://localhost:44351/", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/src/server/Sinet.Universal.Admin.Server.Host/appsettings.json b/src/server/Sinet.Universal.Admin.Server.Host/appsettings.json index a571c96..2072289 100644 --- a/src/server/Sinet.Universal.Admin.Server.Host/appsettings.json +++ b/src/server/Sinet.Universal.Admin.Server.Host/appsettings.json @@ -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": {