User list
This commit is contained in:
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
@ -4,6 +4,7 @@
|
||||
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "cli .NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
|
3
Makefile
3
Makefile
@ -3,6 +3,9 @@ CONFIG=Debug
|
||||
FRAMEWORK=net8.0
|
||||
DESTDIR=/tmp/yavsc
|
||||
|
||||
all:
|
||||
@dotnet build --nologo 2>/dev/null |grep error
|
||||
|
||||
clean:
|
||||
dotnet clean
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace Yavsc.ApiControllers.accounting
|
||||
public UserInfo[] GetUserHint(string name)
|
||||
{
|
||||
return _dbContext.Users.Where(u=>u.UserName.IndexOf(name)>0)
|
||||
.Select(u=>new UserInfo(u.Id, u.UserName, u.Avatar))
|
||||
.Select(u=>new UserInfo(u.Id, u.UserName, u.Email, u.Avatar))
|
||||
.Take(10).ToArray();
|
||||
}
|
||||
}
|
||||
|
@ -7,15 +7,17 @@ namespace Yavsc.Abstract.Identity
|
||||
|
||||
}
|
||||
|
||||
public UserInfo(string userId, string userName, string avatar)
|
||||
public UserInfo(string userId, string userName, string email, string avatar)
|
||||
{
|
||||
UserId = userId;
|
||||
UserName = userName;
|
||||
Email = email;
|
||||
Avatar = avatar;
|
||||
}
|
||||
public string UserId { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Email { get; }
|
||||
public string Avatar { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace Yavsc.Models.Haircut.Views
|
||||
public class HaircutQueryProviderInfo : HaircutQueryComonInfo {
|
||||
public HaircutQueryProviderInfo(HairCutQuery query) : base (query)
|
||||
{
|
||||
ClientInfo = new UserInfo(query.Client.Id, query.Client.UserName, query.Client.Avatar);
|
||||
ClientInfo = new UserInfo(query.Client.Id, query.Client.UserName, query.Client.Email, query.Client.Avatar);
|
||||
}
|
||||
public UserInfo ClientInfo { get; set; }
|
||||
|
||||
@ -39,7 +39,7 @@ namespace Yavsc.Models.Haircut.Views
|
||||
public HaircutQueryClientInfo(HairCutQuery query) : base (query)
|
||||
{
|
||||
var user = query.PerformerProfile.Performer;
|
||||
ProviderInfo = new UserInfo(user.Id, user.UserName, user.Avatar);
|
||||
ProviderInfo = new UserInfo(user.Id, user.UserName, user.Email, user.Avatar);
|
||||
}
|
||||
public UserInfo ProviderInfo { get; set; }
|
||||
|
||||
|
@ -412,8 +412,8 @@ namespace Yavsc.Controllers
|
||||
}
|
||||
|
||||
[Authorize("AdministratorOnly")]
|
||||
[Route("Account/UserList/{pageNum}/{len?}")]
|
||||
public async Task<IActionResult> UserList(int pageNum, int pageLen = defaultLen)
|
||||
[Route("Account/UserList/{pageNum?}/{len?}")]
|
||||
public async Task<IActionResult> UserList(int pageNum=0, int pageLen = defaultLen)
|
||||
{
|
||||
var users = _dbContext.Users.OrderBy(u=>u.UserName);
|
||||
var shown = pageNum * pageLen;
|
||||
@ -423,8 +423,6 @@ namespace Yavsc.Controllers
|
||||
ViewBag.hasNext = users.Count() > (toShow.Count() + shown);
|
||||
ViewBag.nextpage = pageNum+1;
|
||||
ViewBag.pageLen = pageLen;
|
||||
// ApplicationUser user;
|
||||
// user.EmailConfirmed
|
||||
return View(toShow.ToArray());
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,22 @@ namespace Yavsc.Controllers
|
||||
this._dbContext = context;
|
||||
}
|
||||
|
||||
private async Task<bool> EnsureRoleList () {
|
||||
public async Task<IActionResult> Role(string id)
|
||||
{
|
||||
var role = await _roleManager.FindByIdAsync(id);
|
||||
if (role == null) return NotFound();
|
||||
RoleUserCollection roleUserCollection = new RoleUserCollection
|
||||
{
|
||||
Id = id,
|
||||
Name = role.Name,
|
||||
Users = (await this._userManager.GetUsersInRoleAsync(role.Name))
|
||||
.Select(u => new UserInfo (id, u.UserName, u.Email, u.Avatar)).ToArray()
|
||||
};
|
||||
return View(roleUserCollection);
|
||||
}
|
||||
|
||||
private async Task<bool> EnsureRoleList()
|
||||
{
|
||||
// ensure all roles existence
|
||||
foreach (string roleName in new string[] {
|
||||
Constants.AdminGroupName,
|
||||
@ -78,7 +93,8 @@ namespace Yavsc.Controllers
|
||||
|
||||
var user = await _userManager.FindByIdAsync(User.GetUserId());
|
||||
// check all user groups exist
|
||||
if (!await EnsureRoleList()) {
|
||||
if (!await EnsureRoleList())
|
||||
{
|
||||
ModelState.AddModelError(null, "Could not ensure role list existence. aborting.");
|
||||
return new BadRequestObjectResult(ModelState);
|
||||
}
|
||||
@ -104,7 +120,8 @@ namespace Yavsc.Controllers
|
||||
await _userManager.FindByIdAsync(User.GetUserId()),
|
||||
Constants.AdminGroupName);
|
||||
|
||||
var roles = await _roleManager.Roles.Select(x => new RoleInfo {
|
||||
var roles = await _roleManager.Roles.Select(x => new RoleInfo
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name
|
||||
}).ToArrayAsync();
|
||||
@ -131,7 +148,7 @@ namespace Yavsc.Controllers
|
||||
public IActionResult Enroll(string roleName)
|
||||
{
|
||||
ViewBag.UserId = new SelectList(_dbContext.Users, "Id", "UserName");
|
||||
return View(new EnrolerViewModel{ RoleName = roleName });
|
||||
return View(new EnrolerViewModel { RoleName = roleName });
|
||||
}
|
||||
|
||||
[Authorize("AdministratorOnly")]
|
||||
@ -140,8 +157,8 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var newAdmin = await _dbContext.Users.FirstOrDefaultAsync(u=>u.Id==model.EnroledUserId);
|
||||
if (newAdmin==null) return NotFound();
|
||||
var newAdmin = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == model.EnroledUserId);
|
||||
if (newAdmin == null) return NotFound();
|
||||
var addToRoleResult = await _userManager.AddToRoleAsync(newAdmin, model.RoleName);
|
||||
if (addToRoleResult.Succeeded)
|
||||
{
|
||||
@ -156,10 +173,10 @@ namespace Yavsc.Controllers
|
||||
[Authorize("AdministratorOnly")]
|
||||
public async Task<IActionResult> Fire(string roleName, string userId)
|
||||
{
|
||||
var user = await _dbContext.Users.FirstOrDefaultAsync(u=>u.Id==userId);
|
||||
var user = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == userId);
|
||||
if (user == null) return NotFound();
|
||||
|
||||
return View(new FireViewModel{ RoleName = roleName, EnroledUserId = userId, EnroledUserName = user.UserName });
|
||||
return View(new FireViewModel { RoleName = roleName, EnroledUserId = userId, EnroledUserName = user.UserName });
|
||||
}
|
||||
|
||||
[Authorize("AdministratorOnly")]
|
||||
@ -168,8 +185,8 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var oldEnroled = await _dbContext.Users.FirstOrDefaultAsync(u=>u.Id==model.EnroledUserId);
|
||||
if (oldEnroled==null) return NotFound();
|
||||
var oldEnroled = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == model.EnroledUserId);
|
||||
if (oldEnroled == null) return NotFound();
|
||||
var removeFromRole = await _userManager.RemoveFromRoleAsync(oldEnroled, model.RoleName);
|
||||
if (removeFromRole.Succeeded)
|
||||
{
|
||||
|
@ -5,13 +5,11 @@ namespace Yavsc.ViewModels
|
||||
{
|
||||
public partial class EnrolerViewModel {
|
||||
|
||||
[Display(Name="EnroledLabel", ResourceType=typeof(EnrolerViewModel))]
|
||||
[YaRequired]
|
||||
[Required]
|
||||
public string EnroledUserId { get; set; }
|
||||
|
||||
|
||||
[Display(Name="RoleNameLabel", ResourceType=typeof(EnrolerViewModel))]
|
||||
[YaRequired]
|
||||
[Required]
|
||||
public string RoleName { get; set; }
|
||||
}
|
||||
}
|
68
src/Yavsc/Views/Account/UserList.cshtml
Normal file
68
src/Yavsc/Views/Account/UserList.cshtml
Normal file
@ -0,0 +1,68 @@
|
||||
@model ApplicationUser[]
|
||||
@{
|
||||
ViewData["Title"] = "Liste des utilisateurs";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<table >
|
||||
<thead>
|
||||
<th>
|
||||
@SR["Public info"]
|
||||
</th>
|
||||
<th>
|
||||
@SR["AdminOnly"]
|
||||
</th>
|
||||
|
||||
</thead>
|
||||
@foreach (var user in Model)
|
||||
{
|
||||
<tr style="border-width:2px;">
|
||||
<td>
|
||||
@Html.DisplayFor(m=>user)
|
||||
</td>
|
||||
<td>
|
||||
<dl>
|
||||
<dt>
|
||||
@SR["UserName"]
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(m=>user.UserName)
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>
|
||||
@SR["FullName"]
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(m=>user.FullName)
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>
|
||||
@SR["PostalAddress"]
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(m=>user.PostalAddress)
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>
|
||||
@SR["Email"]
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(m=>user.Email)
|
||||
@if (!user.EmailConfirmed) {
|
||||
<a asp-action="AdminSendConfirationEmail" asp-route-id="@user.Id" >Envoyer une demande de confirmation</a>
|
||||
}
|
||||
<a asp-action="AdminDelete" asp-route-id="@user.Id" >Supprimer</a>
|
||||
</dd>
|
||||
</dl>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
@if (ViewBag.hasNext)
|
||||
{
|
||||
<a asp-route-page="@ViewBag.nextpage" asp-route-len="@ViewBag.pageLen">Next page</a>
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>
|
||||
User"]
|
||||
User
|
||||
</th>
|
||||
<th>
|
||||
</th>
|
||||
@ -22,7 +22,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<img src="~/avatars/@(user.UserName).xs.png" alt="avatar"/>
|
||||
<span> @user.UserName </span>
|
||||
<span> @user.UserName <@(user.Email)> </span>
|
||||
</td>
|
||||
<td>
|
||||
<a asp-action="Fire" asp-route-RoleName="@Model.Name" asp-route-UserId="@user.UserId" class="btn btn-success" >
|
||||
|
Reference in New Issue
Block a user