add post userbook
needed a refactor to check the id in db during dto validation
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user