From b9282ea420a85c08b834667d0d8eb74109c6cae0 Mon Sep 17 00:00:00 2001 From: wangyu Date: Tue, 14 Nov 2023 23:29:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=99=BB=E5=BD=95=E7=99=BB?= =?UTF-8?q?=E5=87=BA=E3=80=81=E8=A7=92=E8=89=B2=E5=88=97=E8=A1=A8=E7=AE=80?= =?UTF-8?q?=E5=8D=95=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClientModule.cs | 35 ++++- .../MainWindow.xaml | 4 +- .../Services/ClientAppService.cs | 75 ++++++++- .../Sinet.Universal.Admin.RCL/App.razor | 75 +++++---- .../Global/GlobalVariableData.cs | 13 ++ .../Global/TokenInfo.cs | 52 +++++++ .../Interfaces/IAppService.cs | 8 +- .../Pages/App/Role/List.razor | 145 ++++++++++++++++++ .../Pages/App/Role/List.razor.cs | 49 ++++++ .../Pages/App/User/List.razor.cs | 3 + .../Pages/App/User/View.razor | 18 ++- .../Pages/Authentication/Login-v1.razor.cs | 15 +- .../Services/BaseAppService.cs | 27 +++- .../Shared/Login.razor | 13 +- .../Sinet.Universal.Admin.RCL.csproj | 1 + .../wwwroot/nav/nav.json | 15 +- .../Account/UserAccountAppService.cs | 8 + .../AdminBlazorModule.cs | 3 + .../Services/ServerHostAppService.cs | 28 ++++ 19 files changed, 502 insertions(+), 85 deletions(-) create mode 100644 src/common/Sinet.Universal.Admin.RCL/Global/GlobalVariableData.cs create mode 100644 src/common/Sinet.Universal.Admin.RCL/Global/TokenInfo.cs create mode 100644 src/common/Sinet.Universal.Admin.RCL/Pages/App/Role/List.razor create mode 100644 src/common/Sinet.Universal.Admin.RCL/Pages/App/Role/List.razor.cs create mode 100644 src/server/Sinet.Universal.Admin.Server.Host/Services/ServerHostAppService.cs diff --git a/src/client/Sinet.Universal.Admin.Client/ClientModule.cs b/src/client/Sinet.Universal.Admin.Client/ClientModule.cs index ad554eb..738486d 100644 --- a/src/client/Sinet.Universal.Admin.Client/ClientModule.cs +++ b/src/client/Sinet.Universal.Admin.Client/ClientModule.cs @@ -3,30 +3,46 @@ using Masa.Blazor; using Microsoft.Extensions.DependencyInjection; using Sinet.Universal.Admin.Client.Services; using Sinet.Universal.Admin.RCL; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Volo.Abp.Autofac; using Volo.Abp.Modularity; +using System.Reflection; +using System.IO; +using System.Net.Http; +using System.Net.Http.Headers; +using Volo.Abp.Http.Client; +using Sinet.Universal.Admin.RCL.Global; namespace Sinet.Universal.Admin.Client { - [DependsOn( typeof(AdminHttpApiClientModule), typeof(AdminBlazorServerModule), typeof(AbpAutofacModule))] - public class ClientModule : AbpModule + public class ClientModule : AbpModule { public override void PreConfigureServices(ServiceConfigurationContext context) { + PreConfigure(options => + { + options.ProxyClientActions.Add((remoteServiceName, context, client) => + { + //var appService = context.GetRequiredService(); + //var accessToken = appService.AccessToken; + if (!string.IsNullOrEmpty(GlobalVariableData.AccessToken)) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GlobalVariableData.AccessToken); + } + }); + }); } + public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddSingleton(); + var config = context.Services.GetConfiguration(); + context.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(config["RemoteServices:Default:BaseUrl"]) }); + + context.Services.AddSingleton(); context.Services.AddMasaBlazor(options => { options.Defaults = new Dictionary?>() @@ -41,6 +57,9 @@ namespace Sinet.Universal.Admin.Client }; }); + var basePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(AdminBlazorServerModule)).Location) ?? throw new Exception("Get the assembly root directory exception!"); + context.Services.AddNav(Path.Combine(basePath, $"wwwroot/nav/nav.json")); + context.Services.AddWpfBlazorWebView(); #if DEBUG context.Services.AddBlazorWebViewDeveloperTools(); diff --git a/src/client/Sinet.Universal.Admin.Client/MainWindow.xaml b/src/client/Sinet.Universal.Admin.Client/MainWindow.xaml index 85a3d9d..f88490f 100644 --- a/src/client/Sinet.Universal.Admin.Client/MainWindow.xaml +++ b/src/client/Sinet.Universal.Admin.Client/MainWindow.xaml @@ -5,8 +5,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:rcl="clr-namespace:Sinet.Universal.Admin.RCL;assembly=Sinet.Universal.Admin.RCL" xmlns:blazor="clr-namespace:Microsoft.AspNetCore.Components.WebView.Wpf;assembly=Microsoft.AspNetCore.Components.WebView.Wpf" - mc:Ignorable="d" - Title="MainWindow" Height="900" Width="1400"> + mc:Ignorable="d" WindowStartupLocation="CenterScreen" + Title="Sinet.Universal.Admin" Height="900" Width="1400"> diff --git a/src/client/Sinet.Universal.Admin.Client/Services/ClientAppService.cs b/src/client/Sinet.Universal.Admin.Client/Services/ClientAppService.cs index 496e325..ea85010 100644 --- a/src/client/Sinet.Universal.Admin.Client/Services/ClientAppService.cs +++ b/src/client/Sinet.Universal.Admin.Client/Services/ClientAppService.cs @@ -1,17 +1,78 @@ -using Sinet.Universal.Admin.RCL; +using Microsoft.AspNetCore.Components; +using Sinet.Universal.Admin.RCL; +using Sinet.Universal.Admin.RCL.Global; using Sinet.Universal.Admin.RCL.Services; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IdentityModel.Tokens.Jwt; +using System.Net.Http; +using System.Security.Claims; +using System.Text.Json; +using Volo.Abp.Users; namespace Sinet.Universal.Admin.Client.Services { public class ClientAppService : BaseAppService { - public ClientAppService(CustomAuthenticationStateProvider authenticationStateProvider) : base(authenticationStateProvider) + private readonly HttpClient _httpClient; + private readonly CookieStorage _cookieStorage; + + public ClientAppService(CustomAuthenticationStateProvider authenticationStateProvider, NavigationManager navigationManager + , CookieStorage cookieStorage + , HttpClient httpClient + ) : base(authenticationStateProvider, navigationManager) { + _httpClient = httpClient; + _cookieStorage = cookieStorage; } + + public override async Task AuthenticateUserAsync(ICurrentUser user) + { + GlobalVariableData.AccessToken = await _cookieStorage.GetAsync("token"); + if(!string.IsNullOrEmpty(GlobalVariableData.AccessToken)) + { + var tokenInfo = new JwtSecurityToken(GlobalVariableData.AccessToken); + var claims = new List + { + new Claim(ClaimTypes.Sid, tokenInfo.Payload.FirstOrDefault(p => p.Key == "sub").Value.ToString()), + new Claim(ClaimTypes.Name, tokenInfo.Payload.FirstOrDefault(p => p.Key == "unique_name").Value.ToString() ) + }; + AuthenticateUser(claims); + } + } + + public override async Task LoginToServer(string username, string password) + { + var getTokenContent = new FormUrlEncodedContent(new Dictionary() + { + {"client_id", "Admin_App"}, + {"grant_type", "password"}, + {"username", username}, + {"password", password}, + {"scope", "Admin profile openid email roles offline_access"}, + }); + + var res = _httpClient.PostAsync("connect/token", getTokenContent).Result; + if (res.IsSuccessStatusCode) + { + var resObj = res.Content.ReadAsStringAsync().Result; + var token = JsonSerializer.Deserialize(resObj); + _cookieStorage.SetAsync("token", token.AccessToken); + _navigationManager.NavigateTo("/", true); + } + else if (res.StatusCode == System.Net.HttpStatusCode.BadRequest) + { + var resObj = res.Content.ReadAsStringAsync().Result; + } + else + { + var resObj = res.Content.ReadAsStringAsync().Result?.ToString(); + } + } + + public override Task LogOut() + { + _cookieStorage.SetAsync("token", string.Empty); + return base.LogOut(); + } + } } diff --git a/src/common/Sinet.Universal.Admin.RCL/App.razor b/src/common/Sinet.Universal.Admin.RCL/App.razor index a949a53..93fea69 100644 --- a/src/common/Sinet.Universal.Admin.RCL/App.razor +++ b/src/common/Sinet.Universal.Admin.RCL/App.razor @@ -1,40 +1,59 @@ @using Sinet.Universal.Admin.RCL.Shared +@using System.Security.Claims +@using Volo.Abp.Security.Claims @inherits ProComponentBase - - - - - - - @* *@ - - - -
- -
-
-
-
-
- - Not found - -

Sorry, there's nothing at this address.

-
-
-
-
+ + + + + + + + @* *@ + + + +
+ +
+
+
+
+
+ + Not found + +

Sorry, there's nothing at this address.

+
+
+
+
+
@code{ [Inject] - IAppService appService { get; set;} + IAppService appService { get; set; } - protected override void OnInitialized() + [Inject] + public IPopupService PopupService { get; set; } + + Exception _exception { get; set; } + + protected override async void OnInitialized() { - appService.ReAuthenticate(CurrentUser); + await appService.AuthenticateUserAsync(CurrentUser); base.OnInitialized(); } + private void OnHandle(Exception exception) + { + _exception = exception; + } + + private async void OnAfterHandle(Exception exception) + { + //await PopupService.EnqueueSnackbarAsync(exception); + } + } \ No newline at end of file diff --git a/src/common/Sinet.Universal.Admin.RCL/Global/GlobalVariableData.cs b/src/common/Sinet.Universal.Admin.RCL/Global/GlobalVariableData.cs new file mode 100644 index 0000000..946a8f6 --- /dev/null +++ b/src/common/Sinet.Universal.Admin.RCL/Global/GlobalVariableData.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinet.Universal.Admin.RCL.Global +{ + public class GlobalVariableData + { + public static string AccessToken { get; set; } + } +} diff --git a/src/common/Sinet.Universal.Admin.RCL/Global/TokenInfo.cs b/src/common/Sinet.Universal.Admin.RCL/Global/TokenInfo.cs new file mode 100644 index 0000000..d1b5c2d --- /dev/null +++ b/src/common/Sinet.Universal.Admin.RCL/Global/TokenInfo.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace Sinet.Universal.Admin.RCL.Global +{ + public class TokenInfo + { + [JsonPropertyName("access_token")] + public string AccessToken { get; set; } + + [JsonPropertyName("token_type")] + public string TokenType { get; set; } + + [JsonPropertyName("expires_in")] + public int ExpiresIn { get; set; } + + [JsonPropertyName("refresh_token")] + public string RefreshToken { get; set; } + + [JsonPropertyName("id_token")] + public string IdToken { get; set; } + + public DateTime ExpireTime + { + get + { + return GetJwtTokenInfo().ValidTo.ToLocalTime(); + } + } + + private JwtSecurityToken JwtTokenInfo { get; set; } + + private JwtSecurityToken JwtIdTokenInfo { get; set; } + + public JwtSecurityToken GetJwtTokenInfo() + { + JwtTokenInfo ??= new JwtSecurityToken(AccessToken); + return JwtTokenInfo; + } + + public JwtSecurityToken GetJwtIdTokenInfo() + { + JwtIdTokenInfo ??= new JwtSecurityToken(RefreshToken); + return JwtIdTokenInfo; + } + } +} diff --git a/src/common/Sinet.Universal.Admin.RCL/Interfaces/IAppService.cs b/src/common/Sinet.Universal.Admin.RCL/Interfaces/IAppService.cs index cc17504..4d04009 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Interfaces/IAppService.cs +++ b/src/common/Sinet.Universal.Admin.RCL/Interfaces/IAppService.cs @@ -10,8 +10,14 @@ namespace Sinet.Universal.Admin.RCL { public interface IAppService { - void ReAuthenticate(ICurrentUser user); + public string AccessToken { get; set; } + + Task AuthenticateUserAsync(ICurrentUser user); void AuthenticateUser(IEnumerable claims); + + Task LoginToServer(string username, string password); + + Task LogOut(); } } diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/App/Role/List.razor b/src/common/Sinet.Universal.Admin.RCL/Pages/App/Role/List.razor new file mode 100644 index 0000000..4838df7 --- /dev/null +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/App/Role/List.razor @@ -0,0 +1,145 @@ +@page "/app/role/list" +@using Sinet.Universal.Admin.RCL.Data.App.User +@using Sinet.Universal.Admin.RCL.Data.App.User.Dto +@using Volo.Abp.Identity +@inherits ProComponentBase +@inject NavigationManager Nav + + + +
Filters
+ @* + + + + + + + + + + + + + *@ +
+
+ + +@* + + + Show: + + + entries + + + + + mdi-magnify + + + + Add User + + + + *@ + + + + @header.Text + + + @switch (context.Header.Value) + { + case nameof(IdentityRoleDto.Name): + @context.Item.Name + break; + case (nameof(IdentityRoleDto.IsPublic)): + + break; + case (nameof(IdentityRoleDto.IsStatic)): + + break; + case (nameof(IdentityRoleDto.IsDefault)): + + break; + case "Action": + + + + fa:fas fa-ellipsis-v + + + + + + fa:fas fa-user-tie + Details + + + fa:far fa-edit + Edit + + + fa:far fa-trash-alt + Delete + + + + + break; + default: + @context.Value + break; + } + + + +@* +
+
Showing @((_userPage.PageIndex-1)*_userPage.PageSize+1) to @(_userPage.PageIndex*_userPage.PageSize) of @_userPage.CurrentCount entries
+ @if (_userPage.PageCount > 0) + { + + } +
+
*@ +
+ +@* *@ \ No newline at end of file diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/App/Role/List.razor.cs b/src/common/Sinet.Universal.Admin.RCL/Pages/App/Role/List.razor.cs new file mode 100644 index 0000000..ea042b1 --- /dev/null +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/App/Role/List.razor.cs @@ -0,0 +1,49 @@ +using Sinet.Universal.Admin.RCL.Data.App.User; +using Sinet.Universal.Admin.RCL.Data.App.User.Dto; +using Volo.Abp.Account; +using Volo.Abp.Identity; + +namespace Sinet.Universal.Admin.RCL.Pages.App.Role +{ + public partial class List + { + [Inject] + public IIdentityRoleAppService IdentityRoleAppService { get; set; } + + public List RoleList { get; set; } + + public bool? _visible; + private List _pageSizes = new() { 10, 25, 50, 100 }; + private readonly List> _headers = new() + { + new() { Text = "RoleName", Value = nameof(IdentityRoleDto.Name), CellClass = "" }, + new() { Text = "IsPublic", Value = nameof(IdentityRoleDto.IsPublic) }, + new() { Text = "IsDefault", Value = nameof(IdentityRoleDto.IsDefault) }, + new() { Text = "IsStatic", Value = nameof(IdentityRoleDto.IsStatic) }, + new() { Text = "ACTIONS", Value = "Action", Sortable = false } + }; + private readonly Dictionary _roleIconMap = UserService.GetRoleIconMap(); + + protected override async Task OnInitializedAsync() + { + var roles = await IdentityRoleAppService.GetAllListAsync(); + RoleList = roles.Items.ToList(); + base.OnInitializedAsync(); + } + + private void NavigateToDetails(Guid id) + { + Nav.NavigateTo($"/app/user/view/{id}"); + } + + private void NavigateToEdit(Guid id) + { + Nav.NavigateTo($"/app/role/edit/{id}"); + } + + private void AddUserData(UserDto userData) + { + //_userPage.UserDatas.Insert(0, userData); + } + } +} diff --git a/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/List.razor.cs b/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/List.razor.cs index 125a9ff..13b39f6 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/List.razor.cs +++ b/src/common/Sinet.Universal.Admin.RCL/Pages/App/User/List.razor.cs @@ -1,10 +1,13 @@ using Sinet.Universal.Admin.RCL.Data.App.User; using Sinet.Universal.Admin.RCL.Data.App.User.Dto; +using Volo.Abp.Account; +using Volo.Abp.Identity; namespace Sinet.Universal.Admin.RCL.Pages.App.User { public partial class List { + public bool? _visible; public UserPage _userPage = new(UserService.GetList()); private List _pageSizes = new() { 10, 25, 50, 100 }; 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 bbf50dc..049a908 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 @@ -2,6 +2,7 @@ @page "/app/user/view/{Id}" @using Sinet.Universal.Admin.RCL.Data.App.User @using Sinet.Universal.Admin.RCL.Data.App.User.Dto +@using Volo.Abp.Account @inherits ProComponentBase @@ -235,6 +236,9 @@ [Inject] private NavigationManager NavigationManager { get; set; } = null!; + [Inject] + private IProfileAppService ProfileAppService { get; set; } + [CascadingParameter] private IPageTabsProvider? PageTabsProvider { get; set; } @@ -247,18 +251,20 @@ set { _userData = value; } } - protected override void OnInitialized() + protected override async void OnInitialized() { base.OnInitialized(); _userData = UserService.GetList().FirstOrDefault(u => u.Id == Id); - if (CurrentUser != null && _userData != null) + var user = await ProfileAppService.GetAsync(); + + if (user != null && _userData != null) { - _userData.UserName = CurrentUser.Name; - _userData.Email = CurrentUser.Email; - _userData.Mobile = CurrentUser.PhoneNumber; - _userData.Role = CurrentUser.Roles.First(); + _userData.FullName = user.Name; + _userData.UserName = user.Name; + _userData.Email = user.Email; + _userData.Mobile = user.PhoneNumber; } UpdateTabTitle(); 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 index cb5c9ce..a3f546f 100644 --- 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 @@ -11,9 +11,6 @@ namespace Sinet.Universal.Admin.RCL.Pages.Authentication [Inject] public IAppService _appService { get; set; } - [Inject] - public IIdentityUserAppService UserAppService { get; set; } - [Inject] public IPopupService PopupService { get; set; } @@ -25,21 +22,11 @@ namespace Sinet.Universal.Admin.RCL.Pages.Authentication { 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 _appService.LoginToServer(UserName, Password); 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); diff --git a/src/common/Sinet.Universal.Admin.RCL/Services/BaseAppService.cs b/src/common/Sinet.Universal.Admin.RCL/Services/BaseAppService.cs index c03afff..b9361e1 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Services/BaseAppService.cs +++ b/src/common/Sinet.Universal.Admin.RCL/Services/BaseAppService.cs @@ -1,17 +1,25 @@ -using Sinet.Universal.Admin.RCL.Pages.App.User; -using System.Security.Claims; +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; + protected readonly NavigationManager _navigationManager; - public BaseAppService(CustomAuthenticationStateProvider authenticationStateProvider) + protected readonly CustomAuthenticationStateProvider _authenticationStateProvider; + + public string AccessToken { get; set; } + + public BaseAppService(CustomAuthenticationStateProvider authenticationStateProvider, NavigationManager navigationManager) { _authenticationStateProvider = authenticationStateProvider; + _navigationManager = navigationManager; + } + + public virtual async Task LoginToServer(string username, string password) + { + } public void AuthenticateUser(IEnumerable claims) @@ -19,7 +27,7 @@ namespace Sinet.Universal.Admin.RCL.Services _authenticationStateProvider.AuthenticateUser(claims); } - public void ReAuthenticate(ICurrentUser user) + public virtual Task AuthenticateUserAsync(ICurrentUser user) { if(user != null && user.IsAuthenticated) { @@ -30,7 +38,14 @@ namespace Sinet.Universal.Admin.RCL.Services }; AuthenticateUser(claims); } + return Task.CompletedTask; } + + public virtual Task LogOut() + { + _authenticationStateProvider.Logout(); + return Task.CompletedTask; + } } } diff --git a/src/common/Sinet.Universal.Admin.RCL/Shared/Login.razor b/src/common/Sinet.Universal.Admin.RCL/Shared/Login.razor index 60c8ed4..a025ecc 100644 --- a/src/common/Sinet.Universal.Admin.RCL/Shared/Login.razor +++ b/src/common/Sinet.Universal.Admin.RCL/Shared/Login.razor @@ -18,16 +18,25 @@ - + fa:fas fa-sign-in-alt - Login v2 + Log Out + + @code{ + [Inject] + IAppService appService { get; set;} + + async void LogOut(){ + await appService.LogOut(); + } +} 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 0fdfa9d..b8890c9 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 @@ -16,6 +16,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 60077ba..4b1cf5b 100644 --- a/src/common/Sinet.Universal.Admin.RCL/wwwroot/nav/nav.json +++ b/src/common/Sinet.Universal.Admin.RCL/wwwroot/nav/nav.json @@ -86,27 +86,20 @@ }, { "Id": 14, - "Title": "User", + "Title": "Account", "Icon": "mdi-account-outline", "Children": [ { "Id": 15, - "Title": "List", + "Title": "User", "Icon": "mdi-circle", "Href": "app/user/list" }, { "Id": 16, - "Title": "View", + "Title": "Role", "Icon": "mdi-circle", - "Href": "app/user/view", - "Target": "Self" - }, - { - "Id": 17, - "Title": "Edit", - "Icon": "mdi-circle", - "Href": "app/user/edit", + "Href": "app/role/list", "Target": "Self" } ] diff --git a/src/server/Sinet.Universal.Admin.Application/Account/UserAccountAppService.cs b/src/server/Sinet.Universal.Admin.Application/Account/UserAccountAppService.cs index f1ed0ae..732e166 100644 --- a/src/server/Sinet.Universal.Admin.Application/Account/UserAccountAppService.cs +++ b/src/server/Sinet.Universal.Admin.Application/Account/UserAccountAppService.cs @@ -69,5 +69,13 @@ namespace Sinet.Universal.Admin return null; } + + + [HttpGet("app/logout")] + public async Task SignOut(string redirect = null, CancellationToken cancellationToken = default) + { + await SignInManager.SignOutAsync(); + return new RedirectResult(redirect ?? "/"); + } } } diff --git a/src/server/Sinet.Universal.Admin.Server.Host/AdminBlazorModule.cs b/src/server/Sinet.Universal.Admin.Server.Host/AdminBlazorModule.cs index 6a1c82a..f41c11b 100644 --- a/src/server/Sinet.Universal.Admin.Server.Host/AdminBlazorModule.cs +++ b/src/server/Sinet.Universal.Admin.Server.Host/AdminBlazorModule.cs @@ -43,6 +43,7 @@ using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.VirtualFileSystem; using Sinet.Universal.Admin.RCL; using System.Reflection; +using Sinet.Universal.Admin.Server.Host.Services; namespace Sinet.Universal.Admin; @@ -106,6 +107,8 @@ public class AdminBlazorModule : AbpModule var basePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(AdminBlazorServerModule)).Location) ?? throw new Exception("Get the assembly root directory exception!"); context.Services.AddNav(Path.Combine(basePath, $"wwwroot/nav/nav.json")); + context.Services.AddScoped(); + ConfigureAuthentication(context); ConfigureUrls(configuration); ConfigureBundles(); diff --git a/src/server/Sinet.Universal.Admin.Server.Host/Services/ServerHostAppService.cs b/src/server/Sinet.Universal.Admin.Server.Host/Services/ServerHostAppService.cs new file mode 100644 index 0000000..f8ad368 --- /dev/null +++ b/src/server/Sinet.Universal.Admin.Server.Host/Services/ServerHostAppService.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Components; +using Sinet.Universal.Admin.RCL; +using Sinet.Universal.Admin.RCL.Services; +using System.Threading.Tasks; + +namespace Sinet.Universal.Admin.Server.Host.Services +{ + public class ServerHostAppService : BaseAppService + { + public ServerHostAppService( + CustomAuthenticationStateProvider authenticationStateProvider + , NavigationManager navigationManager) : base(authenticationStateProvider, navigationManager) + { + } + + public override Task LoginToServer(string username, string password) + { + _navigationManager.NavigateTo($"/app/redirect_login?name={username}&pass={password}", true); + return Task.CompletedTask; + } + + public override Task LogOut() + { + _navigationManager.NavigateTo($"/app/logout", true); + return Task.CompletedTask; + } + } +}