Aspnetzero 8.8 (Angular + .NET Core)
We create "public" users on the fly who have access to a limited set of features.
For these users, the default language (french) is ignored, even when we set it as a user setting before authenticating.
Here's the workflow :
- The user access the page : www.oursite.com/public
- From this page we call a custom method in the tokenAuthService to create a new temporary user and return his accesstoken :
var publicUser = Authorization.Users.User.CreateTenantAdminUser(AbpSession.TenantId.Value, $"{userName}@public.com");
- We then Authenticate the user and return the AuthenticateResultModel back to the frontend
- Now that our user is authenticated, in the login.service.ts we redirect the user to a landing page
this.processAuthenticateResult(result, 'publiclanding');
Problem : the language is English even though the tenant default language setting is set to french.
And we tried to override the default setting for the user as follows (in tokenAuthService, right before authenticating) :
_settingManager.ChangeSettingForUser(publicUser.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, "fr");
but it doesn't work either.
From what I can read from this page : https://aspnetboilerplate.com/Pages/Documents/Localization#asp-net-core, the user setting should be preferred over other settings, right ?
3 Answer(s)
-
0
Hi @daws
From what I can read from this page : https://aspnetboilerplate.com/Pages/Documents/Localization#asp-net-core, the user setting should be preferred over other settings, right ?
Yes, this is correct. Do you see the French language when you refresh the page ?
-
0
No I don't. It's still in English.
In the AbpSettings table, the language setting has not been set for my public user.
I can maybe provide the full code for public user creation :
private async Task<AuthenticateResultModel> PublicAuthenticationForTenantId(int tenantId) { using (AbpSession.Use(tenantId, null)) { using (UnitOfWorkManager.Current.SetTenantId(tenantId)) { var password = ...; var userName = $"{Guid.NewGuid():N}"; Authorization.Users.User.CreateTenantAdminUser(AbpSession.TenantId.Value, $"{userName}@public.com"); publicUser.UserName = userName; publicUser.Name = StaticUserPublic.Name; publicUser.Surname = StaticUserPublic.Surname; publicUser.IsEmailConfirmed = true; publicUser.ShouldChangePasswordOnNextLogin = false; publicUser.IsActive = true; publicUser.Password = new PasswordHasher<User>(new OptionsWrapper<PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(publicUser, password); publicUser.Roles = new Collection<UserRole>(); var role = await _roleManager.GetRoleByNameAsync(StaticRoleNames.Tenants.Public); publicUser.Roles.Add(new UserRole(AbpSession.TenantId, publicUser.Id, role.Id)); CheckErrors(await _userManager.CreateAsync(publicUser)); var defaultLanguage = _settingManager.GetSettingValueForTenant(LocalizationSettingNames.DefaultLanguage, tenantId); _settingManager.ChangeSettingForUser(publicUser.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, defaultLanguage); CurrentUnitOfWork.SaveChanges(); //To get new user's Id. return await Authenticate(new AuthenticateModel { UserNameOrEmailAddress = publicUser.UserName, Password = password, RememberClient = true, SingleSignIn = false }); } } }
-
0
Hi,
In the AbpSettings table, the language setting has not been set for my public user.
If the user's tenant and user have the same setting, it will not be saved for the user. Is it possible to share your public website url via [email protected] ?
Thanks,