From 58edbb6661c8f7d147f438716b286aa84c6bcb14 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 22 Apr 2019 15:47:52 +0800 Subject: Add change password api. --- Timeline/Controllers/UserController.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Timeline/Controllers/UserController.cs') diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index 59c7a48c..552bfb2f 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -78,5 +78,22 @@ namespace Timeline.Controllers throw new Exception("Uncreachable code."); } } + + [HttpPost("userop/changepassword"), Authorize] + public async Task ChangePassword([FromBody] ChangePasswordRequest request) + { + var result = await _userService.ChangePassword(User.Identity.Name, request.OldPassword, request.NewPassword); + switch (result) + { + case ChangePasswordResult.Success: + return Ok(ChangePasswordResponse.Success); + case ChangePasswordResult.BadOldPassword: + return Ok(ChangePasswordResponse.BadOldPassword); + case ChangePasswordResult.NotExists: + return Ok(ChangePasswordResponse.NotExists); + default: + throw new Exception("Uncreachable code."); + } + } } } -- cgit v1.2.3