Compare commits
No commits in common. "c21b8be5e1e6f4afef6993fd8291dbbe3930a0f4" and "18b2228e48d0f987c35064257a9791db0961a7e9" have entirely different histories.
c21b8be5e1
...
18b2228e48
@ -12,11 +12,6 @@
|
|||||||
<h2>创建新账户。</h2>
|
<h2>创建新账户。</h2>
|
||||||
<hr />
|
<hr />
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger" role="alert"></div>
|
<div asp-validation-summary="ModelOnly" class="text-danger" role="alert"></div>
|
||||||
<div class="form-floating mb-3">
|
|
||||||
<input asp-for="Input.UserName" class="form-control" autocomplete="username" aria-required="true" placeholder="luolan" />
|
|
||||||
<label asp-for="Input.UserName">用户名</label>
|
|
||||||
<span asp-validation-for="Input.UserName" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-floating mb-3">
|
<div class="form-floating mb-3">
|
||||||
<input asp-for="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
|
<input asp-for="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
|
||||||
<label asp-for="Input.Email">电子邮件</label>
|
<label asp-for="Input.Email">电子邮件</label>
|
||||||
|
@ -110,12 +110,9 @@ namespace AGSS.Areas.Identity.Pages.Account
|
|||||||
|
|
||||||
|
|
||||||
[MaxLength(10)]
|
[MaxLength(10)]
|
||||||
|
[Display(Name = "Confirm password")]
|
||||||
public string Sex { get; set; }
|
public string Sex { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[MaxLength(10)]
|
|
||||||
public string UserName { get; set; }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -134,7 +131,7 @@ namespace AGSS.Areas.Identity.Pages.Account
|
|||||||
var user = CreateUser();
|
var user = CreateUser();
|
||||||
user.Id = Guid.NewGuid().ToString();
|
user.Id = Guid.NewGuid().ToString();
|
||||||
user.Sex = Input.Sex;
|
user.Sex = Input.Sex;
|
||||||
await _userStore.SetUserNameAsync(user, Input.UserName, CancellationToken.None);
|
await _userStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
|
||||||
await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
|
await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
|
||||||
var result = await _userManager.CreateAsync(user, Input.Password);
|
var result = await _userManager.CreateAsync(user, Input.Password);
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ namespace AGSS.Controllers.Admin
|
|||||||
return Ok(new ReturnTemplate(200, "删除子级字典成功", null));
|
return Ok(new ReturnTemplate(200, "删除子级字典成功", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpGet]
|
||||||
public IActionResult GetChildDictionaries([FromBody] ChildDictionaryRequest request)
|
public IActionResult GetChildDictionaries([FromBody] ChildDictionaryRequest request)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(request.Value))
|
if (string.IsNullOrWhiteSpace(request.Value))
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AGSS.Models;
|
|
||||||
using AGSS.Models.DTOs;
|
using AGSS.Models.DTOs;
|
||||||
using AGSS.Models.Entities;
|
using AGSS.Models.Entities;
|
||||||
using AGSS.Models.Template;
|
using AGSS.Models.Template;
|
||||||
using AGSS.Services;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace AGSS.Controllers.Admin;
|
namespace AGSS.Controllers.Admin;
|
||||||
|
|
||||||
@ -22,20 +19,6 @@ namespace AGSS.Controllers.Admin;
|
|||||||
[Route("api/v1/[controller]/[action]")]
|
[Route("api/v1/[controller]/[action]")]
|
||||||
public class AdminRoleControllers:ControllerBase
|
public class AdminRoleControllers:ControllerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 用户服务实例,用于执行与用户相关的操作。
|
|
||||||
/// 该服务提供了一系列方法来处理用户的查询和更新等操作,
|
|
||||||
/// 包括但不限于获取用户详细信息、修改用户资料等功能。
|
|
||||||
/// </summary>
|
|
||||||
private readonly UserService _userService;
|
|
||||||
|
|
||||||
public AdminRoleControllers(UserService userService, RoleManager<RoleModel> roleManager, UserManager<UserModel> userManager)
|
|
||||||
{
|
|
||||||
_userService = userService;
|
|
||||||
_roleManager = roleManager;
|
|
||||||
_userManager = userManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 角色管理器,用于处理角色相关的操作,如创建、查询等。
|
/// 角色管理器,用于处理角色相关的操作,如创建、查询等。
|
||||||
/// 此角色管理器实例主要用于与RoleModel类型的实体进行交互,
|
/// 此角色管理器实例主要用于与RoleModel类型的实体进行交互,
|
||||||
@ -53,7 +36,11 @@ public class AdminRoleControllers:ControllerBase
|
|||||||
/// 管理员角色控制器,用于处理与角色相关的操作,如添加角色、分配角色给用户以及通过角色查询用户。
|
/// 管理员角色控制器,用于处理与角色相关的操作,如添加角色、分配角色给用户以及通过角色查询用户。
|
||||||
/// 该控制器下的所有方法都需要管理员权限才能访问。
|
/// 该控制器下的所有方法都需要管理员权限才能访问。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
public AdminRoleControllers(RoleManager<RoleModel> roleManager, UserManager<UserModel> userManager)
|
||||||
|
{
|
||||||
|
_roleManager = roleManager;
|
||||||
|
_userManager = userManager;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 添加新角色
|
/// 添加新角色
|
||||||
@ -61,12 +48,12 @@ public class AdminRoleControllers:ControllerBase
|
|||||||
/// <param name="role">要添加的角色信息</param>
|
/// <param name="role">要添加的角色信息</param>
|
||||||
/// <returns>返回操作结果,包含状态码、消息和数据</returns>
|
/// <returns>返回操作结果,包含状态码、消息和数据</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> AddRole(string rolename,string normalizedname)
|
public async Task<IActionResult> AddRole(string rolename)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var result = await _roleManager.CreateAsync(new RoleModel(){Id = Guid.Empty.ToString(),Name = rolename,NormalizedName = normalizedname});
|
var result = await _roleManager.CreateAsync(new RoleModel(){Id = new Guid().ToString(),Name = rolename,NormalizedName = rolename});
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
return Ok(new ReturnTemplate(200,"创建成功",""));
|
return Ok(new ReturnTemplate(200,"创建成功",""));
|
||||||
@ -169,13 +156,8 @@ public class AdminRoleControllers:ControllerBase
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
[HttpGet]
|
|
||||||
public async Task<IActionResult> AllRole()
|
|
||||||
{
|
|
||||||
|
|
||||||
return Ok(new ReturnTemplate(200,"查询成功啦!", _roleManager.Roles.ToList()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -187,22 +169,18 @@ public class AdminRoleControllers:ControllerBase
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> SearchUserFromRole([FromBody] SearchUserFromRoleRequest request)
|
public async Task<IActionResult> SearchUserFromRole([FromBody] SearchUserFromRoleRequest request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IList<UserProfile> usersInRole = null;
|
|
||||||
if (string.IsNullOrWhiteSpace(request.RoleName))
|
if (string.IsNullOrWhiteSpace(request.RoleName))
|
||||||
{
|
{
|
||||||
usersInRole = await _userService.GetUsersProfileByUserNameAsync(request.UserName);
|
return Ok(new ReturnTemplate(400, "角色名称不能为空,就像凌云心里不能没有我一样", null));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
var role = await _roleManager.FindByNameAsync(request.RoleName);
|
||||||
|
if (role == null)
|
||||||
{
|
{
|
||||||
var usersInRole1 = await _userService.GetUsersProfileInRoleAsync(request.RoleName);
|
return Ok(new ReturnTemplate(400, "你输入的角色不存在哦!", null));
|
||||||
usersInRole = usersInRole1.Where(a => a.UserName.Contains(request.UserName)).ToList();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var usersInRole = await _userManager.GetUsersInRoleAsync(role.Name);
|
||||||
var totalUsers = usersInRole.Count;
|
var totalUsers = usersInRole.Count;
|
||||||
|
|
||||||
var pagedUsers = usersInRole
|
var pagedUsers = usersInRole
|
||||||
@ -224,9 +202,6 @@ public class AdminRoleControllers:ControllerBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SearchUserFromRoleRequest
|
public class SearchUserFromRoleRequest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public string UserName { get; set; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 表示角色的名称。此属性用于指定或获取与用户管理相关的角色名称。
|
/// 表示角色的名称。此属性用于指定或获取与用户管理相关的角色名称。
|
||||||
/// 在进行角色分配、查询等操作时,需要提供正确的角色名称以确保操作的成功执行。
|
/// 在进行角色分配、查询等操作时,需要提供正确的角色名称以确保操作的成功执行。
|
||||||
@ -261,6 +236,6 @@ public class AdminRoleControllers:ControllerBase
|
|||||||
/// 表示属于特定角色的用户列表。该属性用于存储和返回在给定角色下的所有用户。
|
/// 表示属于特定角色的用户列表。该属性用于存储和返回在给定角色下的所有用户。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>此列表通常作为查询结果的一部分,例如通过角色名搜索用户时返回的数据。</remarks>
|
/// <remarks>此列表通常作为查询结果的一部分,例如通过角色名搜索用户时返回的数据。</remarks>
|
||||||
public List<UserProfile> Users { get; set; }
|
public List<UserModel> Users { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,6 @@ using System.IdentityModel.Tokens.Jwt;
|
|||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using AGSS.Models.Entities;
|
using AGSS.Models.Entities;
|
||||||
using AGSS.Models.Template;
|
using AGSS.Models.Template;
|
||||||
using AGSS.Services;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -5,6 +5,7 @@ namespace AGSS.Models.Entities;
|
|||||||
|
|
||||||
public class UserModel:IdentityUser<string>
|
public class UserModel:IdentityUser<string>
|
||||||
{
|
{
|
||||||
|
|
||||||
public string? Sex { get; set; }
|
public string? Sex { get; set; }
|
||||||
[MaxLength(100)]
|
[MaxLength(100)]
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
@ -4,7 +4,6 @@ using AGSS.DbSet;
|
|||||||
using AGSS.Models;
|
using AGSS.Models;
|
||||||
using AGSS.Models.Entities;
|
using AGSS.Models.Entities;
|
||||||
using AGSS.Models.Template;
|
using AGSS.Models.Template;
|
||||||
using AGSS.Services;
|
|
||||||
using AGSS.Utilities;
|
using AGSS.Utilities;
|
||||||
using asg_form;
|
using asg_form;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
@ -54,7 +53,7 @@ builder.Services.AddIdentityCore<UserModel>(options =>
|
|||||||
// builder.Services.AddScoped<UserService>();
|
// builder.Services.AddScoped<UserService>();
|
||||||
|
|
||||||
builder.Services.AddScoped<Jwt>();
|
builder.Services.AddScoped<Jwt>();
|
||||||
builder.Services.AddScoped<UserService>();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -76,7 +75,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|||||||
IssuerSigningKey = secKey
|
IssuerSigningKey = secKey
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.AddCookie("Identity.External").AddCookie("Identity.Application");
|
.AddCookie("Identity.External");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
using AGSS.Models;
|
using AGSS.Models;
|
||||||
using AGSS.Models.Entities;
|
using AGSS.Models.Entities;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace AGSS.Services;
|
|
||||||
|
|
||||||
public class UserService
|
public class UserService
|
||||||
{
|
{
|
||||||
@ -37,93 +34,4 @@ public class UserService
|
|||||||
MenuName = user.MenuName
|
MenuName = user.MenuName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<List<UserProfile>> GetUsersProfileInRoleAsync(string roleName)
|
|
||||||
{
|
|
||||||
var usersInRole = await _userManager.GetUsersInRoleAsync(roleName);
|
|
||||||
if (usersInRole == null || !usersInRole.Any())
|
|
||||||
{
|
|
||||||
throw new ArgumentException("No users found in the specified role");
|
|
||||||
}
|
|
||||||
|
|
||||||
var userProfiles = new List<UserProfile>();
|
|
||||||
foreach (var user in usersInRole)
|
|
||||||
{
|
|
||||||
userProfiles.Add(new UserProfile
|
|
||||||
{
|
|
||||||
Id = user.Id,
|
|
||||||
UserName = user.UserName,
|
|
||||||
Email = user.Email,
|
|
||||||
Sex = user.Sex,
|
|
||||||
Description = user.Description,
|
|
||||||
Config = user.Config,
|
|
||||||
JobCode = user.JobCode,
|
|
||||||
JobName = user.JobName,
|
|
||||||
Birthday = user.Birthday,
|
|
||||||
MenuCode = user.MenuCode,
|
|
||||||
MenuName = user.MenuName
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assuming you want to return a single UserProfile, you might need to adjust this logic
|
|
||||||
// For now, returning the first user's profile
|
|
||||||
return userProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<List<UserProfile>> GetUsersProfileByUserNameAsync(string userName)
|
|
||||||
{
|
|
||||||
var users = await _userManager.Users
|
|
||||||
.Where(u => u.UserName.Contains(userName))
|
|
||||||
.Select(u => new UserProfile
|
|
||||||
{
|
|
||||||
Id = u.Id,
|
|
||||||
UserName = u.UserName,
|
|
||||||
Email = u.Email,
|
|
||||||
Sex = u.Sex,
|
|
||||||
Description = u.Description,
|
|
||||||
Config = u.Config,
|
|
||||||
JobCode = u.JobCode,
|
|
||||||
JobName = u.JobName,
|
|
||||||
Birthday = u.Birthday,
|
|
||||||
MenuCode = u.MenuCode,
|
|
||||||
MenuName = u.MenuName
|
|
||||||
})
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
if (users == null || !users.Any())
|
|
||||||
{
|
|
||||||
throw new ArgumentException("No users found with the specified username");
|
|
||||||
}
|
|
||||||
|
|
||||||
return users;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<UserProfile>> GetUsersProfileAllAsync()
|
|
||||||
{
|
|
||||||
var users = await _userManager.Users
|
|
||||||
.Select(u => new UserProfile
|
|
||||||
{
|
|
||||||
Id = u.Id,
|
|
||||||
UserName = u.UserName,
|
|
||||||
Email = u.Email,
|
|
||||||
Sex = u.Sex,
|
|
||||||
Description = u.Description,
|
|
||||||
Config = u.Config,
|
|
||||||
JobCode = u.JobCode,
|
|
||||||
JobName = u.JobName,
|
|
||||||
Birthday = u.Birthday,
|
|
||||||
MenuCode = u.MenuCode,
|
|
||||||
MenuName = u.MenuName
|
|
||||||
})
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
if (users == null || !users.Any())
|
|
||||||
{
|
|
||||||
throw new ArgumentException("No users found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return users;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace AGSS.Utilities;
|
|
||||||
|
|
||||||
public static class LINQ
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 从给定的序列中分页获取元素。
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">序列中的元素类型。</typeparam>
|
|
||||||
/// <param name="source">要从中分页的源序列。</param>
|
|
||||||
/// <param name="pageIndex">请求的页码,从0开始。</param>
|
|
||||||
/// <param name="pageSize">每页包含的元素数量。</param>
|
|
||||||
/// <returns>返回指定页码和页大小对应的子序列。</returns>
|
|
||||||
/// <exception cref="ArgumentNullException">如果source为null。</exception>
|
|
||||||
/// <exception cref="ArgumentOutOfRangeException">如果pageIndex是负数或者pageSize是非正数。</exception>
|
|
||||||
public static IEnumerable<T> Paginate<T>(this IEnumerable<T> source, int pageIndex, int pageSize)
|
|
||||||
{
|
|
||||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
|
||||||
if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex), "Page index must be non-negative.");
|
|
||||||
if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize), "Page size must be positive.");
|
|
||||||
|
|
||||||
return source.Skip(pageIndex * pageSize).Take(pageSize);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user