add middleware for api

This commit is contained in:
Adrian Zürcher
2025-10-24 16:29:37 +02:00
parent 14994edcad
commit 8285cf0384
4 changed files with 170 additions and 10 deletions

9
api.go
View File

@@ -34,13 +34,6 @@ func (aH *AccessHandlerAPI) AddUser(c *gin.Context) {
return
}
hash, err := utils.HashPassword(user.Password)
if err != nil {
aH.logger.Error("AddUser", err)
c.JSON(http.StatusInternalServerError, nil)
return
}
if !utils.IsValidEmail(user.Email) {
aH.logger.Error("AddUser", "not valid email address")
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(errors.New("not valid email address")))
@@ -48,7 +41,7 @@ func (aH *AccessHandlerAPI) AddUser(c *gin.Context) {
}
// Hash the provided password before saving
hash, err = utils.HashPassword(user.Password)
hash, err := utils.HashPassword(user.Password)
if err != nil {
aH.logger.Error("AddUser", err)
c.JSON(http.StatusInternalServerError, nil)