aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers/UserController.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-04-30 17:53:40 +0800
committercrupest <crupest@outlook.com>2021-04-30 17:53:40 +0800
commite536121d97610af09d6bf4a51a875b0f7d50f702 (patch)
tree4f6e2f0ddae0920cc1ef3213dc36953a95bb2fc8 /BackEnd/Timeline/Controllers/UserController.cs
parent9f81ec1d4a54239ae9456923115f4a1e379d9e71 (diff)
downloadtimeline-e536121d97610af09d6bf4a51a875b0f7d50f702.tar.gz
timeline-e536121d97610af09d6bf4a51a875b0f7d50f702.tar.bz2
timeline-e536121d97610af09d6bf4a51a875b0f7d50f702.zip
refactor: ...
Diffstat (limited to 'BackEnd/Timeline/Controllers/UserController.cs')
-rw-r--r--BackEnd/Timeline/Controllers/UserController.cs17
1 files changed, 7 insertions, 10 deletions
diff --git a/BackEnd/Timeline/Controllers/UserController.cs b/BackEnd/Timeline/Controllers/UserController.cs
index bdf9c0b7..ec732caa 100644
--- a/BackEnd/Timeline/Controllers/UserController.cs
+++ b/BackEnd/Timeline/Controllers/UserController.cs
@@ -102,16 +102,13 @@ namespace Timeline.Controllers
else
{
if (User.Identity!.Name != username)
- return StatusCode(StatusCodes.Status403Forbidden,
- ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.Common_Forbid_NotSelf));
+ return this.ForbidWithMessage(Resource.MessageForbidNotAdministratorOrOwner);
if (body.Username != null)
- return StatusCode(StatusCodes.Status403Forbidden,
- ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.UserController_Patch_Forbid_Username));
+ return this.ForbidWithMessage(Resource.MessageForbidNotAdministrator);
if (body.Password != null)
- return StatusCode(StatusCodes.Status403Forbidden,
- ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.UserController_Patch_Forbid_Password));
+ return this.ForbidWithMessage(Resource.MessageForbidNotAdministrator);
var user = await _userService.ModifyUserAsync(this.GetUserId(), _mapper.AutoMapperMap<ModifyUserParams>(body));
return await _mapper.MapAsync<HttpUser>(user, Url, User);
@@ -140,7 +137,7 @@ namespace Timeline.Controllers
}
catch (InvalidOperationOnRootUserException)
{
- return BadRequest(ErrorResponse.UserController.Delete_RootUser());
+ return this.BadRequestWithCommonResponse(ErrorCodes.UserController.InvalidOperationOnRootUser, Resource.MessageInvalidOperationOnRootUser);
}
}
@@ -160,7 +157,7 @@ namespace Timeline.Controllers
}
catch (BadPasswordException)
{
- return BadRequest(ErrorResponse.UserController.ChangePassword_BadOldPassword());
+ return this.BadRequestWithCommonResponse(ErrorCodes.UserController.ChangePasswordBadOldPassword, Resource.MessageOldPasswordWrong);
}
// User can't be non-existent or the token is bad.
}
@@ -181,7 +178,7 @@ namespace Timeline.Controllers
}
catch (InvalidOperationOnRootUserException)
{
- return BadRequest(ErrorResponse.UserController.ChangePermission_RootUser());
+ return this.BadRequestWithCommonResponse(ErrorCodes.UserController.InvalidOperationOnRootUser, Resource.MessageInvalidOperationOnRootUser);
}
}
@@ -201,7 +198,7 @@ namespace Timeline.Controllers
}
catch (InvalidOperationOnRootUserException)
{
- return BadRequest(ErrorResponse.UserController.ChangePermission_RootUser());
+ return this.BadRequestWithCommonResponse(ErrorCodes.UserController.InvalidOperationOnRootUser, Resource.MessageInvalidOperationOnRootUser);
}
}
}