diff options
author | crupest <crupest@outlook.com> | 2019-04-22 14:45:52 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-22 14:45:52 +0800 |
commit | 407f97db0be86aa071802b67bfdeadc7703528c9 (patch) | |
tree | 5dc7ed4618477fb695fc45d26984616ecd5fd74a /Timeline/Controllers | |
parent | e347b4a4092a24ff7106ffd3aca67d6ca7decca8 (diff) | |
download | timeline-407f97db0be86aa071802b67bfdeadc7703528c9.tar.gz timeline-407f97db0be86aa071802b67bfdeadc7703528c9.tar.bz2 timeline-407f97db0be86aa071802b67bfdeadc7703528c9.zip |
Move http models in to a new namespace. Revert last commit.
Diffstat (limited to 'Timeline/Controllers')
-rw-r--r-- | Timeline/Controllers/TokenController.cs | 2 | ||||
-rw-r--r-- | Timeline/Controllers/UserController.cs | 46 |
2 files changed, 14 insertions, 34 deletions
diff --git a/Timeline/Controllers/TokenController.cs b/Timeline/Controllers/TokenController.cs index 463fb83c..0be5fb2f 100644 --- a/Timeline/Controllers/TokenController.cs +++ b/Timeline/Controllers/TokenController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System.Threading.Tasks; -using Timeline.Entities; +using Timeline.Entities.Http; using Timeline.Services; namespace Timeline.Controllers diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index d2708eeb..59c7a48c 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; using Timeline.Entities; +using Timeline.Entities.Http; using Timeline.Services; namespace Timeline.Controllers @@ -48,50 +49,29 @@ namespace Timeline.Controllers } } - [HttpPatch("user/{username}"), Authorize] + [HttpPatch("user/{username}"), Authorize(Roles = "admin")] public async Task<IActionResult> Patch([FromBody] UserModifyRequest request, [FromRoute] string username) { - if (User.IsInRole("admin")) - { - var result = await _userService.PatchUser(username, request.Password, request.Roles); - switch (result) - { - case PatchUserResult.Success: - return Ok(); - case PatchUserResult.NotExists: - return NotFound(); - default: - throw new Exception("Unreachable code."); - } - } - else + var result = await _userService.PatchUser(username, request.Password, request.Roles); + switch (result) { - if (User.Identity.Name != username) - return StatusCode(403, new MessageResponse("Can't patch other user when you are not admin.")); - if (request.Roles != null) - return StatusCode(403, new MessageResponse("Can't patch roles when you are not admin.")); - - var result = await _userService.PatchUser(username, request.Password, null); - switch (result) - { - case PatchUserResult.Success: - return Ok(); - case PatchUserResult.NotExists: - return NotFound(new MessageResponse("This username no longer exists. Please update your token.")); - default: - throw new Exception("Unreachable code."); - } + case PatchUserResult.Success: + return Ok(); + case PatchUserResult.NotExists: + return NotFound(); + default: + throw new Exception("Unreachable code."); } } [HttpDelete("user/{username}"), Authorize(Roles = "admin")] - public async Task<ActionResult<UserDeleteResponse>> Delete([FromRoute] string username) + public async Task<IActionResult> Delete([FromRoute] string username) { var result = await _userService.DeleteUser(username); switch (result) { - case DeleteUserResult.Success: - return Ok(UserDeleteResponse.Success); + case DeleteUserResult.Deleted: + return Ok(UserDeleteResponse.Deleted); case DeleteUserResult.NotExists: return Ok(UserDeleteResponse.NotExists); default: |