-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathChangePassword.cs
More file actions
30 lines (26 loc) · 1.05 KB
/
ChangePassword.cs
File metadata and controls
30 lines (26 loc) · 1.05 KB
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
using Microsoft.AspNetCore.Mvc;
using OpenShock.API.Models.Requests;
using OpenShock.Common.Errors;
using OpenShock.Common.Utils;
namespace OpenShock.API.Controller.Account.Authenticated;
public sealed partial class AuthenticatedAccountController
{
/// <summary>
/// Change the password of the current user
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
[HttpPost("password")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> ChangePassword(ChangePasswordRequest data)
{
if (!HashingUtils.VerifyPassword(data.OldPassword, CurrentUser.PasswordHash).Verified)
{
return Problem(AccountError.PasswordChangeInvalidPassword);
}
var result = await _accountService.ChangePassword(CurrentUser.Id, data.NewPassword);
return result.Match(success => Ok(),
notFound => throw new Exception("Unexpected result, apparently our current user does not exist..."));
}
}