Skip to content

Commit

Permalink
fix: issues 1269、1237、1226
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 committed Apr 26, 2024
1 parent 4151467 commit a081a13
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Services/Masa.Auth.Service.Admin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,9 @@

await builder.MigrateDbContextAsync<AuthDbContext>(async (context, services) =>
{
builder.Services.AddOidcCache(publicConfiguration);
await builder.Services.AddOidcDbContext<AuthDbContext>(async option =>
{
builder.Services.AddOidcCache(publicConfiguration);

await new AuthSeedData().SeedAsync(builder);

await option.SeedStandardResourcesAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<ItemContent Context="data">
<MListItemContent>
<MListItemTitle>
@if (RoleDisabled(data.Item!))
@if (RoleDisabled(data.Item))
{
<span class="body2 error--text">
@($"{data.Item!.Name}-(由于绑定次数限制,无法选择此角色)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override Task OnParametersSetAsync()
return base.OnParametersSetAsync();
}

protected override bool RoleDisabled(RoleSelectDto role) => role.Limit != 0 && role.AvailableQuantity < TeamUserCount;
protected override bool RoleDisabled(RoleSelectDto? role) => role != null && role.Limit != 0 && role.AvailableQuantity < TeamUserCount;

public async Task ReloadAsync()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Web/Masa.Auth.Web.Sso/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public async Task<IActionResult> Logout(string logoutId = "")

foreach (var cookies in HttpContext.Request.Cookies)
{
if (cookies.Key == CookieKeyConfig.LangCookieKey)
continue;

HttpContext.Response.Cookies.Delete(cookies.Key);
}

Expand Down
9 changes: 9 additions & 0 deletions src/Web/Masa.Auth.Web.Sso/Global/CookieKeyConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Auth.Web.Sso.Global;

public static class CookieKeyConfig
{
public const string LangCookieKey = "GlobalConfig_Lang";
}
31 changes: 31 additions & 0 deletions src/Web/Masa.Auth.Web.Sso/Global/CookieStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Auth.Web.Sso.Global;

public class CookieStorage
{
private readonly IJSRuntime _jsRuntime;

public CookieStorage(IJSRuntime jsRuntime)
{
_jsRuntime = jsRuntime;
}

public async Task<string> GetAsync(string key)
{
return await _jsRuntime.InvokeAsync<string>(JsInteropConstants.GetCookie, key);
}

public async void SetAsync<T>(string key, T? value)
{
try
{
await _jsRuntime.InvokeVoidAsync(JsInteropConstants.SetCookie, key, value?.ToString());
}
catch
{
// ignored
}
}
}
1 change: 1 addition & 0 deletions src/Web/Masa.Auth.Web.Sso/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
{
distributedCacheOptions.UseStackExchangeRedisCache(redisOption);
});
builder.Services.AddScoped<CookieStorage>();
var identityServerBuilder = builder.Services.AddOidcCacheStorage(redisOption)
.AddIdentityServer(options =>
{
Expand Down
11 changes: 10 additions & 1 deletion src/Web/Masa.Auth.Web.Sso/Shared/SimpleLayout.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@using System.Globalization
@inherits SsoLayoutComponentBase
@inject IJSRuntime JS
@inject CookieStorage CookieStorage

<CascadingValue Value="LanguageProvider">
<MApp>
Expand Down Expand Up @@ -40,7 +41,6 @@
</CascadingValue>

@code {

void ChangeLanguage(){
string _targetCulture = "";
if (LanguageProvider.Culture.Name == "en-US")
Expand All @@ -59,4 +59,13 @@
await JS.InvokeVoidAsync("console.log", $"error: {e.ToString()}");
return true;
}

protected override async Task OnInitializedAsync()
{
var lang = await CookieStorage.GetAsync(CookieKeyConfig.LangCookieKey);
if (!string.IsNullOrWhiteSpace(lang))
{
LanguageProvider.SetCulture(new CultureInfo(lang));
}
}
}

0 comments on commit a081a13

Please sign in to comment.