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
|
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "cli .NET Core Launch (console)",
|
"name": "cli .NET Core Launch (console)",
|
||||||
"type": "coreclr",
|
"type": "coreclr",
|
||||||
|
3
Makefile
3
Makefile
@ -3,6 +3,9 @@ CONFIG=Debug
|
|||||||
FRAMEWORK=net8.0
|
FRAMEWORK=net8.0
|
||||||
DESTDIR=/tmp/yavsc
|
DESTDIR=/tmp/yavsc
|
||||||
|
|
||||||
|
all:
|
||||||
|
@dotnet build --nologo 2>/dev/null |grep error
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
dotnet clean
|
dotnet clean
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ namespace Yavsc.ApiControllers.accounting
|
|||||||
public UserInfo[] GetUserHint(string name)
|
public UserInfo[] GetUserHint(string name)
|
||||||
{
|
{
|
||||||
return _dbContext.Users.Where(u=>u.UserName.IndexOf(name)>0)
|
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();
|
.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;
|
UserId = userId;
|
||||||
UserName = userName;
|
UserName = userName;
|
||||||
|
Email = email;
|
||||||
Avatar = avatar;
|
Avatar = avatar;
|
||||||
}
|
}
|
||||||
public string UserId { get; set; }
|
public string UserId { get; set; }
|
||||||
|
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
public string Email { get; }
|
||||||
public string Avatar { get; set; }
|
public string Avatar { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,10 +56,10 @@ namespace Yavsc
|
|||||||
_localizer = stringLocalizerFactory.Create(typeof(ChatHub));
|
_localizer = stringLocalizerFactory.Create(typeof(ChatHub));
|
||||||
|
|
||||||
_cxManager = connexionManager;
|
_cxManager = connexionManager;
|
||||||
_cxManager.SetErrorHandler ((context, error) =>
|
_cxManager.SetErrorHandler ((context, error) =>
|
||||||
{
|
{
|
||||||
NotifyUser(NotificationTypes.Error, context, error);
|
NotifyUser(NotificationTypes.Error, context, error);
|
||||||
});
|
});
|
||||||
_logger = loggerFactory.CreateLogger<ChatHub>();
|
_logger = loggerFactory.CreateLogger<ChatHub>();
|
||||||
InputValidator = new HubInputValidator { NotifyUser = async (type, target, msg) => await this.NotifyUser(type, target, msg) };
|
InputValidator = new HubInputValidator { NotifyUser = async (type, target, msg) => await this.NotifyUser(type, target, msg) };
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ namespace Yavsc.Models.Haircut.Views
|
|||||||
public class HaircutQueryProviderInfo : HaircutQueryComonInfo {
|
public class HaircutQueryProviderInfo : HaircutQueryComonInfo {
|
||||||
public HaircutQueryProviderInfo(HairCutQuery query) : base (query)
|
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; }
|
public UserInfo ClientInfo { get; set; }
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ namespace Yavsc.Models.Haircut.Views
|
|||||||
public HaircutQueryClientInfo(HairCutQuery query) : base (query)
|
public HaircutQueryClientInfo(HairCutQuery query) : base (query)
|
||||||
{
|
{
|
||||||
var user = query.PerformerProfile.Performer;
|
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; }
|
public UserInfo ProviderInfo { get; set; }
|
||||||
|
|
||||||
|
@ -412,8 +412,8 @@ namespace Yavsc.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize("AdministratorOnly")]
|
[Authorize("AdministratorOnly")]
|
||||||
[Route("Account/UserList/{pageNum}/{len?}")]
|
[Route("Account/UserList/{pageNum?}/{len?}")]
|
||||||
public async Task<IActionResult> UserList(int pageNum, int pageLen = defaultLen)
|
public async Task<IActionResult> UserList(int pageNum=0, int pageLen = defaultLen)
|
||||||
{
|
{
|
||||||
var users = _dbContext.Users.OrderBy(u=>u.UserName);
|
var users = _dbContext.Users.OrderBy(u=>u.UserName);
|
||||||
var shown = pageNum * pageLen;
|
var shown = pageNum * pageLen;
|
||||||
@ -423,8 +423,6 @@ namespace Yavsc.Controllers
|
|||||||
ViewBag.hasNext = users.Count() > (toShow.Count() + shown);
|
ViewBag.hasNext = users.Count() > (toShow.Count() + shown);
|
||||||
ViewBag.nextpage = pageNum+1;
|
ViewBag.nextpage = pageNum+1;
|
||||||
ViewBag.pageLen = pageLen;
|
ViewBag.pageLen = pageLen;
|
||||||
// ApplicationUser user;
|
|
||||||
// user.EmailConfirmed
|
|
||||||
return View(toShow.ToArray());
|
return View(toShow.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,11 +30,26 @@ namespace Yavsc.Controllers
|
|||||||
this._dbContext = context;
|
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
|
// ensure all roles existence
|
||||||
foreach (string roleName in new string[] {
|
foreach (string roleName in new string[] {
|
||||||
Constants.AdminGroupName,
|
Constants.AdminGroupName,
|
||||||
Constants.StarGroupName,
|
Constants.StarGroupName,
|
||||||
Constants.PerformerGroupName,
|
Constants.PerformerGroupName,
|
||||||
Constants.FrontOfficeGroupName,
|
Constants.FrontOfficeGroupName,
|
||||||
Constants.StarHunterGroupName,
|
Constants.StarHunterGroupName,
|
||||||
@ -50,8 +65,8 @@ namespace Yavsc.Controllers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gives the (new if was not existing) administrator role
|
/// Gives the (new if was not existing) administrator role
|
||||||
@ -65,20 +80,21 @@ namespace Yavsc.Controllers
|
|||||||
{
|
{
|
||||||
// If some amdin already exists, make this method disapear
|
// If some amdin already exists, make this method disapear
|
||||||
var admins = await _userManager.GetUsersInRoleAsync(Constants.AdminGroupName);
|
var admins = await _userManager.GetUsersInRoleAsync(Constants.AdminGroupName);
|
||||||
if (admins != null && admins.Count > 0)
|
if (admins != null && admins.Count > 0)
|
||||||
{
|
{
|
||||||
// All is ok, nothing to do here.
|
// All is ok, nothing to do here.
|
||||||
if (User.IsInMsRole(Constants.AdminGroupName))
|
if (User.IsInMsRole(Constants.AdminGroupName))
|
||||||
{
|
{
|
||||||
|
|
||||||
return Ok(new { message = "you already got it." });
|
return Ok(new { message = "you already got it." });
|
||||||
}
|
}
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = await _userManager.FindByIdAsync(User.GetUserId());
|
var user = await _userManager.FindByIdAsync(User.GetUserId());
|
||||||
// check all user groups exist
|
// check all user groups exist
|
||||||
if (!await EnsureRoleList()) {
|
if (!await EnsureRoleList())
|
||||||
|
{
|
||||||
ModelState.AddModelError(null, "Could not ensure role list existence. aborting.");
|
ModelState.AddModelError(null, "Could not ensure role list existence. aborting.");
|
||||||
return new BadRequestObjectResult(ModelState);
|
return new BadRequestObjectResult(ModelState);
|
||||||
}
|
}
|
||||||
@ -103,11 +119,12 @@ namespace Yavsc.Controllers
|
|||||||
var youAreAdmin = await _userManager.IsInRoleAsync(
|
var youAreAdmin = await _userManager.IsInRoleAsync(
|
||||||
await _userManager.FindByIdAsync(User.GetUserId()),
|
await _userManager.FindByIdAsync(User.GetUserId()),
|
||||||
Constants.AdminGroupName);
|
Constants.AdminGroupName);
|
||||||
|
|
||||||
var roles = await _roleManager.Roles.Select(x => new RoleInfo {
|
var roles = await _roleManager.Roles.Select(x => new RoleInfo
|
||||||
|
{
|
||||||
Id = x.Id,
|
Id = x.Id,
|
||||||
Name = x.Name
|
Name = x.Name
|
||||||
}).ToArrayAsync();
|
}).ToArrayAsync();
|
||||||
foreach (var role in roles)
|
foreach (var role in roles)
|
||||||
{
|
{
|
||||||
var uinrole = await _userManager.GetUsersInRoleAsync(role.Name);
|
var uinrole = await _userManager.GetUsersInRoleAsync(role.Name);
|
||||||
@ -115,9 +132,9 @@ namespace Yavsc.Controllers
|
|||||||
role.UserCount = uinrole.Count();
|
role.UserCount = uinrole.Count();
|
||||||
}
|
}
|
||||||
var assembly = GetType().Assembly;
|
var assembly = GetType().Assembly;
|
||||||
ViewBag.ThisAssembly = assembly.FullName;
|
ViewBag.ThisAssembly = assembly.FullName;
|
||||||
ViewBag.RunTimeVersion = assembly.ImageRuntimeVersion;
|
ViewBag.RunTimeVersion = assembly.ImageRuntimeVersion;
|
||||||
var rolesArray = roles.ToArray();
|
var rolesArray = roles.ToArray();
|
||||||
return View(new AdminViewModel
|
return View(new AdminViewModel
|
||||||
{
|
{
|
||||||
Roles = rolesArray,
|
Roles = rolesArray,
|
||||||
@ -131,7 +148,7 @@ namespace Yavsc.Controllers
|
|||||||
public IActionResult Enroll(string roleName)
|
public IActionResult Enroll(string roleName)
|
||||||
{
|
{
|
||||||
ViewBag.UserId = new SelectList(_dbContext.Users, "Id", "UserName");
|
ViewBag.UserId = new SelectList(_dbContext.Users, "Id", "UserName");
|
||||||
return View(new EnrolerViewModel{ RoleName = roleName });
|
return View(new EnrolerViewModel { RoleName = roleName });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize("AdministratorOnly")]
|
[Authorize("AdministratorOnly")]
|
||||||
@ -140,8 +157,8 @@ namespace Yavsc.Controllers
|
|||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
var newAdmin = await _dbContext.Users.FirstOrDefaultAsync(u=>u.Id==model.EnroledUserId);
|
var newAdmin = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == model.EnroledUserId);
|
||||||
if (newAdmin==null) return NotFound();
|
if (newAdmin == null) return NotFound();
|
||||||
var addToRoleResult = await _userManager.AddToRoleAsync(newAdmin, model.RoleName);
|
var addToRoleResult = await _userManager.AddToRoleAsync(newAdmin, model.RoleName);
|
||||||
if (addToRoleResult.Succeeded)
|
if (addToRoleResult.Succeeded)
|
||||||
{
|
{
|
||||||
@ -156,10 +173,10 @@ namespace Yavsc.Controllers
|
|||||||
[Authorize("AdministratorOnly")]
|
[Authorize("AdministratorOnly")]
|
||||||
public async Task<IActionResult> Fire(string roleName, string userId)
|
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();
|
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")]
|
[Authorize("AdministratorOnly")]
|
||||||
@ -168,8 +185,8 @@ namespace Yavsc.Controllers
|
|||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
var oldEnroled = await _dbContext.Users.FirstOrDefaultAsync(u=>u.Id==model.EnroledUserId);
|
var oldEnroled = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == model.EnroledUserId);
|
||||||
if (oldEnroled==null) return NotFound();
|
if (oldEnroled == null) return NotFound();
|
||||||
var removeFromRole = await _userManager.RemoveFromRoleAsync(oldEnroled, model.RoleName);
|
var removeFromRole = await _userManager.RemoveFromRoleAsync(oldEnroled, model.RoleName);
|
||||||
if (removeFromRole.Succeeded)
|
if (removeFromRole.Succeeded)
|
||||||
{
|
{
|
||||||
|
@ -5,13 +5,11 @@ namespace Yavsc.ViewModels
|
|||||||
{
|
{
|
||||||
public partial class EnrolerViewModel {
|
public partial class EnrolerViewModel {
|
||||||
|
|
||||||
[Display(Name="EnroledLabel", ResourceType=typeof(EnrolerViewModel))]
|
[Required]
|
||||||
[YaRequired]
|
|
||||||
public string EnroledUserId { get; set; }
|
public string EnroledUserId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[Display(Name="RoleNameLabel", ResourceType=typeof(EnrolerViewModel))]
|
[Required]
|
||||||
[YaRequired]
|
|
||||||
public string RoleName { get; set; }
|
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">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
User"]
|
User
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
</th>
|
</th>
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<img src="~/avatars/@(user.UserName).xs.png" alt="avatar"/>
|
<img src="~/avatars/@(user.UserName).xs.png" alt="avatar"/>
|
||||||
<span> @user.UserName </span>
|
<span> @user.UserName <@(user.Email)> </span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a asp-action="Fire" asp-route-RoleName="@Model.Name" asp-route-UserId="@user.UserId" class="btn btn-success" >
|
<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