查询角色

This commit is contained in:
杨毅 2024-09-17 11:18:41 +08:00
parent 7cb1b09dc3
commit 6cf319996f
2 changed files with 46 additions and 1 deletions

View File

@ -9,6 +9,7 @@ using System.Drawing;
using System.IO.Compression;
using System.Security.Claims;
using static asg_form.Controllers.login;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace asg_form.Controllers
{
@ -384,6 +385,46 @@ namespace asg_form.Controllers
[Route("api/v1/admin/rolealluser")]
[HttpGet]
[Authorize]
public async Task<ActionResult<object>> RoleuserAsync(string rolename)
{
if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
{
List<post_user> data = new List<post_user>();
var users= await userManager.GetUsersInRoleAsync(rolename);
foreach (var user1 in users)
{
post_user post_User = new post_user();
post_User.id = user1.Id;
post_User.name = user1.UserName;
post_User.email = user1.Email;
post_User.officium = user1.officium;
post_User.chinaname = user1.chinaname;
post_User.Base64 = user1.UserBase64;
post_User.Roles = (List<string>?)await userManager.GetRolesAsync(user1);
data.Add(post_User);
}
return data;
}
else
{
return BadRequest(new error_mb { code = 400, message = "无管理员" });
}
}
[Route("api/v1/admin/excel/all")]
[HttpGet]
[Authorize]

View File

@ -534,7 +534,11 @@ namespace asg_form.Controllers
}
if (user.Integral == null)
{
user.Integral = 0;
await userManager.UpdateAsync(user);
}
var claims = new List<Claim>();