From 4f4412e6f7d9ebf41a6e5fba66a42d3dab42597b Mon Sep 17 00:00:00 2001 From: Jon P Smith Date: Tue, 27 Dec 2022 11:33:18 +0000 Subject: [PATCH] Localized AuthRoles & AuthUsers --- .../Pages/AuthRoles/Create.cshtml | 15 +++-- .../Pages/AuthRoles/Delete.cshtml | 15 +++-- .../Pages/AuthRoles/Delete.cshtml.cs | 11 +++- .../Pages/AuthRoles/Edit.cshtml | 18 ++++-- .../Pages/AuthRoles/Edit.cshtml.cs | 10 ++- .../Pages/AuthRoles/_PartialCreateEdit.cshtml | 12 +++- .../Pages/AuthUsers/Delete.cshtml | 14 ++++- .../Pages/AuthUsers/Delete.cshtml.cs | 11 +++- .../Pages/AuthUsers/Edit.cshtml | 32 +++++++--- .../Pages/AuthUsers/Edit.cshtml.cs | 11 +++- .../Pages/AuthUsers/ListUsers.cshtml | 23 ++++--- .../Pages/AuthUsers/SyncUsers.cshtml | 27 +++++--- .../Pages/AuthUsers/SyncUsers.cshtml.cs | 11 +++- .../Resources/AppLocalizeResource.fr.resx | 62 ++++++++++++++++++- .../wwwroot/js/site.js | 8 +-- 15 files changed, 218 insertions(+), 62 deletions(-) diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Create.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Create.cshtml index cff653ba..13f5af52 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Create.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Create.cshtml @@ -14,12 +14,16 @@
- +
- +
@@ -31,8 +35,11 @@
- - Cancel + + + @SimpleLocalizer.LocalizeString("Cancel", this) +
diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Delete.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Delete.cshtml index 75847c87..dc06d0ac 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Delete.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Delete.cshtml @@ -1,14 +1,21 @@ @page +@using LocalizeMessagesAndErrors +@using Microsoft.AspNetCore.Mvc.TagHelpers @model Example1.RazorPages.IndividualAccounts.Pages.AuthRoles.DeleteModel - +@inject ISimpleLocalizer SimpleLocalizer

Delete Role

-

Are you sure you want to delete the @Model.RoleName ?

+

+ @SimpleLocalizer.LocalizeFormatted($"Are you sure you want to delete the {Model.RoleName} ?", this) +

@Html.HiddenFor(model => model.RoleName) - - Cancel + + + @SimpleLocalizer.LocalizeString("Cancel", this) +
\ No newline at end of file diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Delete.cshtml.cs b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Delete.cshtml.cs index f92df17d..1a5ed0f5 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Delete.cshtml.cs +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Delete.cshtml.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using AuthPermissions.AdminCode; +using GenericServices.AspNetCore; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -28,9 +29,13 @@ public IActionResult OnGet(string roleName) public async Task OnPost() { var status = await _authRolesAdmin.DeleteRoleAsync(RoleName, true); - return status.HasErrors - ? RedirectToPage("ErrorPage", new { allErrors = status.GetAllErrors() }) - : RedirectToPage("ListRoles", new { message = status.Message }); + + if (status.IsValid) + return RedirectToPage("ListRoles", new { message = status.Message }); + + //Errors + status.CopyErrorsToModelState(ModelState); + return Page(); } } } diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml index 73c20ace..297bf975 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml @@ -1,7 +1,12 @@ @page +@using LocalizeMessagesAndErrors +@using Microsoft.AspNetCore.Mvc.TagHelpers @model Example1.RazorPages.IndividualAccounts.Pages.AuthRoles.EditModel +@inject ISimpleLocalizer SimpleLocalizer -
Editing @Model.Data.RoleName role.
+
+ @SimpleLocalizer.LocalizeFormatted($"Editing {Model.Data.RoleName} role.", this) +

@@ -10,7 +15,9 @@
@Html.HiddenFor(x => x.Data.RoleName)
- +
@@ -22,8 +29,11 @@
diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml.cs b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml.cs index f6ea8252..62c10c0e 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml.cs +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using AuthPermissions.AdminCode; using ExamplesCommonCode.CommonAdmin; +using GenericServices.AspNetCore; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; @@ -40,9 +41,12 @@ public async Task OnPost() var status = await _authRolesAdmin .UpdateRoleToPermissionsAsync(Data.RoleName, Data.GetSelectedPermissionNames(), Data.Description); - return status.HasErrors - ? RedirectToPage("ErrorPage", new { allErrors = status.GetAllErrors() }) - : RedirectToPage("ListRoles", new { message = status.Message }); + if (status.IsValid) + return RedirectToPage("ListRoles", new { message = status.Message }); + + //Errors + status.CopyErrorsToModelState(ModelState); + return Page(); } } diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/_PartialCreateEdit.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/_PartialCreateEdit.cshtml index 3928e079..43d52afe 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/_PartialCreateEdit.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/_PartialCreateEdit.cshtml @@ -3,6 +3,11 @@ @inject ISimpleLocalizer SimpleLocalizer @model RoleCreateUpdateDto +@{ + var selectedLocalized = SimpleLocalizer.LocalizeString("Selected", this); + var selectLocalized = SimpleLocalizer.LocalizeString("Select", this); +} + @@ -40,10 +45,11 @@ @Model.PermissionsWithSelect[i].Selected, new { id = Model.PermissionsWithSelect[i].PermissionName}) diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Delete.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Delete.cshtml index a4b54796..cf1f609b 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Delete.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Delete.cshtml @@ -1,9 +1,14 @@ @page +@using LocalizeMessagesAndErrors +@using Microsoft.AspNetCore.Mvc.TagHelpers @model Example1.RazorPages.IndividualAccounts.Pages.AuthUsers.DeleteModel +@inject ISimpleLocalizer SimpleLocalizer

Delete AuthUser

-

Are you sure you want to delete this user?

+

+ @SimpleLocalizer.LocalizeString("Are you sure you want to delete this user?", this) +

@@ -22,7 +27,10 @@
@Html.HiddenFor(model => model.UserId) - - Cancel + + + @SimpleLocalizer.LocalizeString("Cancel", this) +
diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Delete.cshtml.cs b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Delete.cshtml.cs index 7370221d..bbccaf0c 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Delete.cshtml.cs +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Delete.cshtml.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using AuthPermissions.AdminCode; +using GenericServices.AspNetCore; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -35,9 +36,13 @@ public async Task OnGet(string userId) public async Task OnPost() { var status = await _authUsersAdmin.DeleteUserAsync(UserId); - return status.HasErrors - ? RedirectToPage("ErrorPage", new { allErrors = status.GetAllErrors() }) - : RedirectToPage("ListUsers", new { message = status.Message }); + + if (status.IsValid) + return RedirectToPage("ListUsers", new { message = status.Message }); + + //Errors + status.CopyErrorsToModelState(ModelState); + return Page(); } } } diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml index 0cdc7dd3..0f4e4641 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml @@ -1,9 +1,16 @@ @page +@using LocalizeMessagesAndErrors +@using Microsoft.AspNetCore.Mvc.TagHelpers @model Example1.RazorPages.IndividualAccounts.Pages.AuthUsers.EditModel +@inject ISimpleLocalizer SimpleLocalizer -

Edit

+

+ @SimpleLocalizer.LocalizeString("Edit", this) +

-

Edit the user's information

+

+ @SimpleLocalizer.LocalizeString("Edit the user's information", this) +


@@ -11,25 +18,34 @@
@Html.Hidden("Data.UserId", Model.Data.UserId)
- +
- +
- @Html.LabelFor(model => model.Data.RolesSelectList, new { @class = "col-sm-2 col-form-label" }) -
+ +
diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml.cs b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml.cs index 5fee1a24..244b506c 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml.cs +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using AuthPermissions.AdminCode; using Example1.RazorPages.IndividualAccounts.Model; +using GenericServices.AspNetCore; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -31,9 +32,13 @@ public async Task OnGet(string userId) public async Task OnPost() { var status = await _authUsersAdmin.UpdateUserAsync(Data.UserId, Data.Email, Data.UserName, Data.SelectedRoleNames); - return status.HasErrors - ? RedirectToPage("ErrorPage", new { allErrors = status.GetAllErrors() }) - : RedirectToPage("ListUsers", new { message = status.Message }); + + if (status.IsValid) + return RedirectToPage("ListUsers", new { message = status.Message }); + + //Errors + status.CopyErrorsToModelState(ModelState); + return Page(); } } } diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml index 5b881a6a..3891dac8 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/ListUsers.cshtml @@ -1,5 +1,8 @@ @page +@using LocalizeMessagesAndErrors +@using Microsoft.AspNetCore.Mvc.TagHelpers @model ListUsersModel +@inject ISimpleLocalizer SimpleLocalizer

Auth users

@@ -8,23 +11,25 @@

@Model.Message

} -Sync with authentication provider's users + + @SimpleLocalizer.LocalizeString("Sync with authentication provider's users", this) +

@@ -42,9 +47,13 @@ @string.Join(", ", item.RoleNames) } diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml index e29c8813..77c2b2ff 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml @@ -1,22 +1,29 @@ @page @using global::AuthPermissions.AdminCode +@using LocalizeMessagesAndErrors +@using Microsoft.AspNetCore.Mvc.TagHelpers @model Example1.RazorPages.IndividualAccounts.Pages.AuthUsers.SyncUsersModel +@inject ISimpleLocalizer SimpleLocalizer @if (!@Model.Data.Any()) { -

There are no changes to apply to the AuthUsers

+

+ @SimpleLocalizer.LocalizeString("There are no changes to apply to the AuthUsers", this) +

return; } -

Changes needed based on authentication provider's users

+

+ @SimpleLocalizer.LocalizeString("Changes needed based on authentication provider's users", this) +

- UserName + @SimpleLocalizer.LocalizeString("UserName", this) - Email + @SimpleLocalizer.LocalizeString("Email", this) - AuthRoles + @SimpleLocalizer.LocalizeString("Roles", this) - Edit | Delete + @SimpleLocalizer.LocalizeString("Edit | Delete", this)
- Edit + + @SimpleLocalizer.LocalizeString("Edit", this) + | - Delete + + @SimpleLocalizer.LocalizeString("Delete", this) +
- - - - + + + + @@ -24,7 +31,7 @@ { @@ -44,8 +51,10 @@
Change typeEmailUserNameRoles Count@SimpleLocalizer.LocalizeString("Change type", this)@SimpleLocalizer.LocalizeString("Email", this)@SimpleLocalizer.LocalizeString("UserName", this)@SimpleLocalizer.LocalizeString("Roles count", this)
- @Model.Data[i].FoundChangeType + @SimpleLocalizer.LocalizeString(Model.Data[i].FoundChangeType.ToString(), this) @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.UserId)}", Model.Data[i].UserId) @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.FoundChangeType)}", Model.Data[i].FoundChangeType)
- - Cancel + + + @SimpleLocalizer.LocalizeString("Cancel", this) + diff --git a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml.cs b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml.cs index c26fa5fe..e340d9f4 100644 --- a/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml.cs +++ b/Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/SyncUsers.cshtml.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using AuthPermissions.AdminCode; +using GenericServices.AspNetCore; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -26,9 +27,13 @@ public async Task OnGet() public async Task OnPost() { var status = await _authUsersAdmin.ApplySyncChangesAsync(Data); - return status.HasErrors - ? RedirectToPage("ErrorPage", new { allErrors = status.GetAllErrors() }) - : RedirectToPage("ListUsers", new { message = status.Message }); + + if (status.IsValid) + return RedirectToPage("ListUsers", new { message = status.Message }); + + //Errors + status.CopyErrorsToModelState(ModelState); + return Page(); } } } diff --git a/Example1.RazorPages.IndividualAccounts/Resources/AppLocalizeResource.fr.resx b/Example1.RazorPages.IndividualAccounts/Resources/AppLocalizeResource.fr.resx index d5ab42a4..7e23e7e3 100644 --- a/Example1.RazorPages.IndividualAccounts/Resources/AppLocalizeResource.fr.resx +++ b/Example1.RazorPages.IndividualAccounts/Resources/AppLocalizeResource.fr.resx @@ -123,6 +123,15 @@ Application + + Appliquer le changement de synchronisation + + + Voulez-vous vraiment supprimer le {0} ? + + + Voulez-vous vraiment supprimer cet utilisateur ? + Comptes individuels d'ASP.NET Core @@ -135,6 +144,15 @@ AuthPermissions : base de données en mémoire (utilise SQLite en mémoire) + + Annuler + + + Changer le type + + + Modifications nécessaires en fonction des utilisateurs du fournisseur d'authentification + Cookie ou jeton @@ -144,21 +162,39 @@ Créer un nouveau rôle + + Créer + Créer un nouveau rôle Bases de données + + Supprimer l'utilisateur authentifié + Effacer Description - + + Modifier les informations de l'utilisateur + + + Modifier | Effacer + + Éditer + + Modification du rôle {0} + + + E-mail + Exemple 1 - examen des rôles/autorisations, plus la localisation @@ -171,6 +207,9 @@ Multilocataire ? + + Pas de changement + Noter @@ -180,9 +219,18 @@ Autorisations + + Description du rôle + Nom de rôle + + Les rôles comptent + + + Rôles + Sélectionner @@ -195,4 +243,16 @@ Affiche les bases des rôles et des autorisations, ainsi que la prise en charge multilingue. + + Synchroniser avec les utilisateurs du fournisseur d'authentification + + + Il n'y a aucun changement à appliquer aux AuthUsers + + + Mise à jour + + + Nom d'utilisateur + \ No newline at end of file diff --git a/Example1.RazorPages.IndividualAccounts/wwwroot/js/site.js b/Example1.RazorPages.IndividualAccounts/wwwroot/js/site.js index 9c60a0d0..134b9d6c 100644 --- a/Example1.RazorPages.IndividualAccounts/wwwroot/js/site.js +++ b/Example1.RazorPages.IndividualAccounts/wwwroot/js/site.js @@ -4,14 +4,14 @@ // Write your JavaScript code. //Used in Edit / Create of a Role -function TogglePermissionSelect(button, idOfInput) { - if ($(button).text().trim() === 'Selected') { - $(button).text('Select'); +function TogglePermissionSelect(button, idOfInput, selectLocalized, selectedLocalized) { + if ($(button).text().trim() === selectedLocalized) { + $(button).text(selectLocalized); $(button).removeClass('btn-primary'); $(button).addClass('btn-secondary'); $('#' + idOfInput).val(false); } else { - $(button).text('Selected'); + $(button).text(selectedLocalized); $(button).removeClass('btn-secondary'); $(button).addClass('btn-primary'); $('#' + idOfInput).val(true);