diff options
author | crupest <crupest@outlook.com> | 2022-04-25 19:27:44 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-04-25 19:27:44 +0800 |
commit | f2ead327344fdacdf3fb1e761b4fb8ec89330f1e (patch) | |
tree | c04e46a1517191440a72932f4314bd1f64503fab /BackEnd/Timeline/Controllers | |
parent | 60ec53aa2ad9687f5d8661322fb3e1e03e291eba (diff) | |
download | timeline-f2ead327344fdacdf3fb1e761b4fb8ec89330f1e.tar.gz timeline-f2ead327344fdacdf3fb1e761b4fb8ec89330f1e.tar.bz2 timeline-f2ead327344fdacdf3fb1e761b4fb8ec89330f1e.zip |
...
Diffstat (limited to 'BackEnd/Timeline/Controllers')
-rw-r--r-- | BackEnd/Timeline/Controllers/V2/SelfController.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Controllers/V2/SelfController.cs b/BackEnd/Timeline/Controllers/V2/SelfController.cs new file mode 100644 index 00000000..1604bc67 --- /dev/null +++ b/BackEnd/Timeline/Controllers/V2/SelfController.cs @@ -0,0 +1,40 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Timeline.Models.Http; +using Timeline.Services.User; + +namespace Timeline.Controllers.V2 +{ + [ApiController] + [Route("v2/self")] + public class SelfController : V2ControllerBase + { + private readonly IUserService _userService; + + public SelfController(IUserService userService) + { + _userService = userService; + } + + [HttpPost("changepassword")] + [Authorize] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] + public async Task<ActionResult> ChangePasswordAsync([FromBody] HttpChangePasswordRequest body) + { + try + { + await _userService.ChangePassword(GetAuthUserId(), body.OldPassword, body.NewPassword); + return NoContent(); + } + catch (BadPasswordException) + { + return UnprocessableEntity(new ErrorResponse(ErrorResponse.InvalidRequest, "Old password is wrong.")); + } + } + } +} + |