Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/models/users/delete.go
akuma06 205daea027 Finally services are nearly empty 👍
Moved api services. All validations are now in validator util and all upload functions are in upload util
2017-07-01 23:09:35 +02:00

22 lignes
Pas d'EOL
576 o
Go

package users
// DeleteUser deletes a user.
func DeleteUser(currentUser *models.User, id string) (int, error) {
var user models.User
if db.ORM.First(&user, id).RecordNotFound() {
return http.StatusNotFound, errors.New("user_not_found")
}
if user.ID == 0 {
return http.StatusInternalServerError, errors.New("permission_delete_error")
}
err := db.ORM.Delete(&user).Error
if err != nil {
return http.StatusInternalServerError, errors.New("user_not_deleted")
}
if user.CurrentUserIdentical(currentUser, user.ID) {
ClearCookie(c)
}
return http.StatusOK, nil
}