Skip to content

Commit

Permalink
Localized AuthRoles & AuthUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
JonPSmith committed Dec 27, 2022
1 parent 96acaa8 commit 4f4412e
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
<div class="col-md-12">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div>
<label class="control-label">Role Name</label>
<label class="control-label">
@SimpleLocalizer.LocalizeString("Role Name", this)
</label>
<input asp-for="Data.RoleName" class="form-control" />
<span asp-validation-for="Data.RoleName" class="text-danger"></span>
</div>
<div>
<label class="control-label">Role description</label>
<label class="control-label">
@SimpleLocalizer.LocalizeString("Role description", this)
</label>
<input asp-for="Data.Description" class="form-control" />
<span asp-validation-for="Data.Description" class="text-danger"></span>
</div>
Expand All @@ -31,8 +35,11 @@
</div>

<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListRoles">Cancel</a>
<input type="submit" value=@SimpleLocalizer.LocalizeString("Create", this)
class="btn btn-primary" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListRoles">
@SimpleLocalizer.LocalizeString("Cancel", this)
</a>
</div>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
@page
@using LocalizeMessagesAndErrors
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Example1.RazorPages.IndividualAccounts.Pages.AuthRoles.DeleteModel

@inject ISimpleLocalizer SimpleLocalizer

<h1>Delete Role</h1>

<h3>Are you sure you want to delete the <span class="h2">@Model.RoleName</span> ?</h3>
<h3>
@SimpleLocalizer.LocalizeFormatted($"Are you sure you want to delete the {Model.RoleName} ?", this)
</h3>
<div>
<form method="post">
@Html.HiddenFor(model => model.RoleName)
<input type="submit" value="Delete" class="btn btn-danger" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListRoles">Cancel</a>
<input type="submit" value=@SimpleLocalizer.LocalizeString("Delete", this)
class="btn btn-danger" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListRoles">
@SimpleLocalizer.LocalizeString("Cancel", this)
</a>
</form>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,9 +29,13 @@ public IActionResult OnGet(string roleName)
public async Task<IActionResult> 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();
}
}
}
18 changes: 14 additions & 4 deletions Example1.RazorPages.IndividualAccounts/Pages/AuthRoles/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
@page
@using LocalizeMessagesAndErrors
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Example1.RazorPages.IndividualAccounts.Pages.AuthRoles.EditModel
@inject ISimpleLocalizer SimpleLocalizer

<div class="h3">Editing <span class="h1">@Model.Data.RoleName</span> role.</div>
<div class="h3">
@SimpleLocalizer.LocalizeFormatted($"Editing {Model.Data.RoleName} role.", this)
</div>

<hr />
<div class="row">
Expand All @@ -10,7 +15,9 @@
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@Html.HiddenFor(x => x.Data.RoleName)
<div>
<label class="control-label">Role description</label>
<label class="control-label">
@SimpleLocalizer.LocalizeString("Role description", this)
</label>
<input asp-for="Data.Description" class="form-control" />
<span asp-validation-for="Data.Description" class="text-danger"></span>
</div>
Expand All @@ -22,8 +29,11 @@
</div>

<div class="form-group">
<input type="submit" value="Update" class="btn btn-primary" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListRoles">Cancel</a>
<input type="submit" value=@SimpleLocalizer.LocalizeString("Update", this)
class="btn btn-primary" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListRoles">
@SimpleLocalizer.LocalizeString("Cancel", this)
</a>
</div>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,9 +41,12 @@ public async Task<IActionResult> 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();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
@inject ISimpleLocalizer SimpleLocalizer
@model RoleCreateUpdateDto

@{
var selectedLocalized = SimpleLocalizer.LocalizeString("Selected", this);
var selectLocalized = SimpleLocalizer.LocalizeString("Select", this);
}

<table class="table">
<thead>
<tr>
Expand Down Expand Up @@ -40,10 +45,11 @@
@Model.PermissionsWithSelect[i].Selected,
new { id = Model.PermissionsWithSelect[i].PermissionName})
<button type="button" class='btn-sm @(Model.PermissionsWithSelect[i].Selected ? "btn-primary" : "btn-secondary")'
onclick="TogglePermissionSelect(this, '@Model.PermissionsWithSelect[i].PermissionName')">
onclick="TogglePermissionSelect(this, '@Model.PermissionsWithSelect[i].PermissionName',
'@selectLocalized', '@selectedLocalized')">
@(Model.PermissionsWithSelect[i].Selected
? SimpleLocalizer.LocalizeString("Selected", this)
: SimpleLocalizer.LocalizeString("Select", this))
? selectedLocalized
: selectLocalized)
</button>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
@page
@using LocalizeMessagesAndErrors
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Example1.RazorPages.IndividualAccounts.Pages.AuthUsers.DeleteModel
@inject ISimpleLocalizer SimpleLocalizer

<h1>Delete AuthUser</h1>

<h3>Are you sure you want to delete this user?</h3>
<h3>
@SimpleLocalizer.LocalizeString("Are you sure you want to delete this user?", this)
</h3>
<div>
<dl class="row">

Expand All @@ -22,7 +27,10 @@
</dl>
<form method="post">
@Html.HiddenFor(model => model.UserId)
<input type="submit" value="Delete" class="btn btn-danger" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListUsers">Cancel</a>
<input type="submit" value=@SimpleLocalizer.LocalizeString("Delete", this)
class="btn btn-danger" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListUsers">
@SimpleLocalizer.LocalizeString("Cancel", this)
</a>
</form>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using AuthPermissions.AdminCode;
using GenericServices.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

Expand Down Expand Up @@ -35,9 +36,13 @@ public async Task<IActionResult> OnGet(string userId)
public async Task<IActionResult> 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();
}
}
}
32 changes: 24 additions & 8 deletions Example1.RazorPages.IndividualAccounts/Pages/AuthUsers/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
@page
@using LocalizeMessagesAndErrors
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Example1.RazorPages.IndividualAccounts.Pages.AuthUsers.EditModel
@inject ISimpleLocalizer SimpleLocalizer

<h1>Edit</h1>
<h1>
@SimpleLocalizer.LocalizeString("Edit", this)
</h1>

<h4>Edit the user's information</h4>
<h4>
@SimpleLocalizer.LocalizeString("Edit the user's information", this)
</h4>
<hr />
<div class="row">
<div class="col-md-8">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@Html.Hidden("Data.UserId", Model.Data.UserId)
<div class="form-group">
<label asp-for="Data.Email" class="control-label"></label>
<label asp-for="Data.Email" class="control-label">
@SimpleLocalizer.LocalizeString("Email", this)
</label>
<input asp-for="Data.Email" class="form-control" />
<span asp-validation-for="Data.Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Data.UserName" class="control-label"></label>
<label asp-for="Data.UserName" class="control-label">
@SimpleLocalizer.LocalizeString("UserName", this)
</label>
<input asp-for="Data.UserName" class="form-control" />
<span asp-validation-for="Data.UserName" class="text-danger"></span>
</div>
<div class="form-group row">
@Html.LabelFor(model => model.Data.RolesSelectList, new { @class = "col-sm-2 col-form-label" })
<div class="col-sm-10">
<label asp-for="Data.Email" class="col-sm-2 control-label">
@SimpleLocalizer.LocalizeString("Roles", this)
</label>
<div class ="col-sm-10">
<select asp-for="Data.SelectedRoleNames" asp-items="Model.Data.RolesSelectList"></select>
</div>
</div>

<div class="form-group">
<input class="btn btn-primary" type="submit" value="Update" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListUsers">Cancel</a>
<input type="submit" value=@SimpleLocalizer.LocalizeString("Update", this)
class="btn btn-primary" />
<a class="btn btn-secondary" asp-area="" asp-page=".\ListUsers">
@SimpleLocalizer.LocalizeString("Cancel", this)
</a>
</div>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -31,9 +32,13 @@ public async Task<IActionResult> OnGet(string userId)
public async Task<IActionResult> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@page
@using LocalizeMessagesAndErrors
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model ListUsersModel
@inject ISimpleLocalizer SimpleLocalizer

<h1>Auth users</h1>

Expand All @@ -8,23 +11,25 @@
<h3 class="text-primary">@Model.Message</h3>
}

<a class="btn btn-primary" asp-area="" asp-page=".\SyncUsers">Sync with authentication provider's users</a>
<a class="btn btn-primary" asp-area="" asp-page=".\SyncUsers">
@SimpleLocalizer.LocalizeString("Sync with authentication provider's users", this)
</a>
<p></p>

<table class="table">
<thead>
<tr>
<th>
UserName
@SimpleLocalizer.LocalizeString("UserName", this)
</th>
<th>
Email
@SimpleLocalizer.LocalizeString("Email", this)
</th>
<th>
AuthRoles
@SimpleLocalizer.LocalizeString("Roles", this)
</th>
<th>
Edit | Delete
@SimpleLocalizer.LocalizeString("Edit | Delete", this)
</th>
</tr>
</thead>
Expand All @@ -42,9 +47,13 @@
@string.Join(", ", item.RoleNames)
</td>
<td>
<a asp-area="" asp-page=".\Edit" asp-route-userId="@item.UserId">Edit</a>
<a asp-area="" asp-page=".\Edit" asp-route-userId="@item.UserId">
@SimpleLocalizer.LocalizeString("Edit", this)
</a>
|
<a asp-area="" asp-page=".\Delete" asp-route-userId="@item.UserId">Delete</a>
<a asp-area="" asp-page=".\Delete" asp-route-userId="@item.UserId">
@SimpleLocalizer.LocalizeString("Delete", this)
</a>
</td>
</tr>
}
Expand Down
Loading

0 comments on commit 4f4412e

Please sign in to comment.