add post userbook

needed a refactor to check the id in db during dto validation
This commit is contained in:
2025-10-17 01:13:35 +02:00
parent 7dcca84b7d
commit 9404013592
11 changed files with 157 additions and 30 deletions

View File

@@ -19,13 +19,13 @@ func PostLoginHandler(ac appcontext.AppContext) {
var user dto.UserLogin
err := ac.C.ShouldBindJSON(&user)
if err != nil {
myvalidator.ManageBindingError(ac, err)
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
return
}
if !isUserAndPasswordOk(ac.Db, user.Username, user.Password) {
ac.C.JSON(http.StatusInternalServerError,
gin.H{"error": i18nresource.GetTranslatedMessage(ac, "InvalidCredentials")})
ac.C.JSON(http.StatusUnauthorized,
gin.H{"error": i18nresource.GetTranslatedMessage(&ac, "InvalidCredentials")})
return
}
@@ -36,7 +36,7 @@ func PostLoginHandler(ac appcontext.AppContext) {
gin.H{"error": fmt.Errorf("Error when generating JWT token: %w", err)})
return
}
ac.C.JSON(200, gin.H{"message": i18nresource.GetTranslatedMessage(ac, "AuthenticationSuccess"), "token": jwtToken})
ac.C.JSON(http.StatusOK, gin.H{"message": i18nresource.GetTranslatedMessage(&ac, "AuthenticationSuccess"), "token": jwtToken})
}
func isUserAndPasswordOk(db *gorm.DB, username string, password string) bool {