blob: 1604bc6773dbe8ada735bac7fd87080f9280dc76 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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."));
}
}
}
}
|