Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
Implemented ability to reset a user's password.
Joseph Milazzo8220709b4c0f
diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.csindex 78b7f23b7..71a8fcb69 100644--- a/API/Controllers/AccountController.cs+++ b/API/Controllers/AccountController.cs@@ -4,8 +4,10 @@ using System.Threading.Tasks;using API.Constants;using API.DTOs;using API.Entities;+using API.Extensions;using API.Interfaces;using AutoMapper;+using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Identity;using Microsoft.AspNetCore.Mvc;using Microsoft.EntityFrameworkCore;@@ -36,6 +38,21 @@ namespace API.Controllers_mapper = mapper;}+ [Authorize(Policy = "RequireAdminRole")]+ [HttpPost("reset-password")]+ public async Task<ActionResult> UpdatePassword(ResetPasswordDto resetPasswordDto)+ {+ _logger.LogInformation($"{User.GetUsername()} is changing {resetPasswordDto.UserName}'s password.");+ var user = await _userManager.Users.SingleAsync(x => x.UserName == resetPasswordDto.UserName);+ var result = await _userManager.RemovePasswordAsync(user);+ if (!result.Succeeded) return BadRequest("Unable to update password");++ result = await _userManager.AddPasswordAsync(user, resetPasswordDto.Password);+ if (!result.Succeeded) return BadRequest("Unable to update password");++ return Ok($"{resetPasswordDto.UserName}'s Password has been reset.");+ }+[HttpPost("register")]public async Task<ActionResult<UserDto>> Register(RegisterDto registerDto){diff --git a/API/DTOs/ResetPasswordDto.cs b/API/DTOs/ResetPasswordDto.csnew file mode 100644index 000000000..f486f4349--- /dev/null+++ b/API/DTOs/ResetPasswordDto.cs@@ -0,0 +1,13 @@+using System.ComponentModel.DataAnnotations;++namespace API.DTOs+{+ public class ResetPasswordDto+ {+ [Required]+ public string UserName { get; init; }+ [Required]+ [StringLength(8, MinimumLength = 4)]+ public string Password { get; init; }+ }+}\ No newline at end of filediff --git a/API/Middleware/ExceptionMiddleware.cs b/API/Middleware/ExceptionMiddleware.csindex 413fbdb16..5c168cf3d 100644--- a/API/Middleware/ExceptionMiddleware.cs+++ b/API/Middleware/ExceptionMiddleware.cs@@ -25,7 +25,6 @@ namespace API.Middlewarepublic async Task InvokeAsync(HttpContext context){- _logger.LogError("The middleware called");try{await _next(context); // downstream middlewares or http calldiff --git a/API/Startup.cs b/API/Startup.csindex aaa2dae49..1aee5cecc 100644--- a/API/Startup.cs+++ b/API/Startup.cs@@ -42,10 +42,8 @@ namespace API{app.UseSwagger();app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));+ app.UseHangfireDashboard();}--- app.UseHangfireDashboard();app.UseHttpsRedirection();