Skip to content

Commit

Permalink
1添加功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lurudong committed Jun 24, 2021
1 parent 8a730f8 commit c38374f
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/Destiny.Core.Flow.API/Controllers/AssetController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

namespace Destiny.Core.Flow.API.Controllers
{
[Description("资产控制器")]

/// <summary>
/// 资产管理
/// </summary>
[Description("资产管理")]

public class AssetController : CrudAdminControllerBase<IAssetService, Guid, Asset, AssetInputDto, AssetOutputDto, AssetPageListDto>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public async Task<AjaxResult> LoginAsync([FromBody] LoginDto loginDto)
/// <returns></returns>
[HttpPost]
[Description("更改密码")]
[NoAuthorityVerification]
public async Task<AjaxResult> ChangePassword([FromBody] ChangePassInputDto dto)
{

Expand Down
12 changes: 12 additions & 0 deletions src/Destiny.Core.Flow.API/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ public async Task<AjaxResult> GetUsersAsync()
{

return (await _userService.GetUsersAsync()).ToAjaxResult();
}

/// <summary>
/// 异步重置密码
/// </summary>
/// <param name="userId">用户ID</param>
/// <returns></returns>
[HttpGet]
[Description("异步重置密码")]
public Task<AjaxResult> ResetPasswordAsync(Guid userId)
{
return _userService.ResetPasswordAsync(userId).ToAjaxResult();
}
}
}
12 changes: 12 additions & 0 deletions src/Destiny.Core.Flow.API/Destiny.Core.Flow.API.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Destiny.Core.Flow.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{

services.AddApplication<AppWebModule>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ public abstract class CrudAdminControllerBase<ICrudService, TPrimaryKey, TEntity
where ICrudService : ICrudServiceAsync<TPrimaryKey, TEntity, IInputDto, IIOutputDto, IPagedListDto>
{



protected CrudAdminControllerBase(ICrudService crudServiceAsync) : base(crudServiceAsync)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="sub-main-w3">
<form asp-route="Login">
<h2>
欢迎使用DestinyCore系统
欢迎使用星睿系统
</h2>
<input type="hidden" asp-for="ReturnUrl" />
<div class="form-style-agile">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@*<partial name="_Nav" />*@
@RenderBody()
<div class="footer">
<a>版权所有 DestinyCore</a>
<a>版权所有 星睿开发团队</a>
</div>

@*<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>*@
Expand Down
7 changes: 7 additions & 0 deletions src/Destiny.Core.Flow.IServices/Users/IUserServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,12 @@ public interface IUserServices : IScopedDependency
/// </summary>
/// <returns></returns>
Task<OperationResponse<IEnumerable<SelectListItem>>> GetUsersToSelectListItemAsync();

/// <summary>
/// 重置密码
/// </summary>
/// <param name="userId">用户ID</param>
/// <returns></returns>
Task<OperationResponse> ResetPasswordAsync(Guid userId);
}
}
36 changes: 30 additions & 6 deletions src/Destiny.Core.Flow.Services/Users/UserServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public async Task<OperationResponse> DeleteAsync(Guid id)
if (user.NormalizedUserName == "ADMIN")
{
return OperationResponse.Error("此用户为系统超级管理员,无法删除");
}
// IList<string> existRoleNames = await _userManager.GetRolesAsync(user);
}

// IList<string> existRoleNames = await _userManager.GetRolesAsync(user);
return await _unitOfWork.UseTranAsync(async () =>
{
var result = await _userManager.DeleteAsync(user);
Expand Down Expand Up @@ -152,8 +152,8 @@ public async Task<OperationResponse> UpdateAsync(UserUpdateInputDto dto)
var user = await _userManager.FindByIdAsync(dto.Id.ToString());
user = dto.MapTo(user);
var result = await _userManager.UpdateAsync(user);
return result.ToOperationResponse("保存用户成功");
return result.ToOperationResponse("保存用户成功");

}

/// <summary>
Expand Down Expand Up @@ -228,6 +228,30 @@ public async Task<OperationResponse<IEnumerable<SelectListItem>>> GetUsersToSele
Selected = false,
}).ToListAsync();
return new OperationResponse<IEnumerable<SelectListItem>>("得到数据成功", users, OperationResponseType.Success);
}
}

/// <summary>
/// 重置密码
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<OperationResponse> ResetPasswordAsync(Guid userId)
{
userId.NotEmpty(nameof(userId));
//是否超级用户
var isSuperUser = _principal.Identity.GetUserName("name")?.Equals("Admin", StringComparison.OrdinalIgnoreCase);
if (isSuperUser == false)
{
return OperationResponse.Error("不是超过用户无法重置密码");
}
var password = "123456";
var user = await _userManager.FindByIdAsync(userId.AsTo<string>());
//重置此用户令牌
var token = await _userManager.GeneratePasswordResetTokenAsync(user);
//更新密码 123456 系统默认超级密码
var result = await _userManager.ResetPasswordAsync(user, token, password);
return result.ToOperationResponse($"重置密码成功,密码为【{password}】");

}
}
}
15 changes: 14 additions & 1 deletion src/Destiny.Core.Flow.Shared/CrudServiceAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public CrudServiceAsync(IServiceProvider serviceProvider, IRepository<IEntity, T

public virtual async Task<OperationResponse> CreateAsync(IInputDto inputDto)
{
inputDto.NotNull(nameof(inputDto));


inputDto.NotNull(nameof(inputDto));
return await this.Repository.InsertAsync(inputDto,this.CreateCheckAsync);
}

Expand Down Expand Up @@ -101,9 +102,21 @@ protected virtual Task UpdateCheckAsync(IInputDto inputDto, IEntity entity)
public virtual Task<IPagedResult<IPagedListDto>> GetPageAsync(PageRequest request)
{
request.NotNull(nameof(request));
request = GetPageRequest(request);
return this.Entities.ToPageAsync<IEntity,IPagedListDto>(request);
}

/// <summary>
/// 得到分页请求
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
protected virtual PageRequest GetPageRequest(PageRequest request)
{

return request;
}

/// <summary>
/// 异步根据键加载数据
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Destiny.Core.AspNetMvc.Test.Controller
{
public class User_TestController_Tests : AspNetMvcTestBase
{


//主题+期望结果+参数
//被测试方法全名_期望的结果_给予的条件
[Fact]
public async Task Should_Trigger_User_TestController_CreateAsync()
{
Expand Down

0 comments on commit c38374f

Please sign in to comment.