Finish the delete feature.

This commit is contained in:
lishuang
2020-06-21 00:04:11 +08:00
parent 601c60fca7
commit 3fb1d874d5
14 changed files with 212 additions and 4 deletions

View File

@ -50,6 +50,7 @@ func (this *UserController) RegisterRoutes() map[string]func(writer http.Respons
routeMap["/api/user/page"] = this.Wrap(this.Page, USER_ROLE_ADMINISTRATOR)
routeMap["/api/user/toggle/status"] = this.Wrap(this.ToggleStatus, USER_ROLE_ADMINISTRATOR)
routeMap["/api/user/transfiguration"] = this.Wrap(this.Transfiguration, USER_ROLE_ADMINISTRATOR)
routeMap["/api/user/delete"] = this.Wrap(this.Delete, USER_ROLE_ADMINISTRATOR)
return routeMap
}
@ -392,7 +393,7 @@ func (this *UserController) ToggleStatus(writer http.ResponseWriter, request *ht
currentUser := this.userDao.CheckByUuid(uuid)
user := this.checkUser(request)
if uuid == user.Uuid {
panic(result.UNAUTHORIZED)
panic(result.BadRequest("You cannot disable yourself."))
}
if currentUser.Status == USER_STATUS_OK {
@ -431,6 +432,24 @@ func (this *UserController) Transfiguration(writer http.ResponseWriter, request
return this.Success(session.Uuid)
}
func (this *UserController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid")
currentUser := this.userDao.CheckByUuid(uuid)
user := this.checkUser(request)
if currentUser.Status != USER_STATUS_DISABLED {
panic(result.BadRequest("Only disabled user can be deleted."))
}
if currentUser.Uuid == user.Uuid {
panic(result.BadRequest("You cannot delete yourself."))
}
this.userService.DeleteUser(request, currentUser)
return this.Success("OK")
}
func (this *UserController) ChangePassword(writer http.ResponseWriter, request *http.Request) *result.WebResult {
oldPassword := request.FormValue("oldPassword")