diff --git a/go.mod b/go.mod index 42558b1..f470538 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gitea.tecamino.com/paadi/access-handler go 1.24.5 require ( - gitea.tecamino.com/paadi/dbHandler v1.0.4 + gitea.tecamino.com/paadi/dbHandler v1.0.7 gitea.tecamino.com/paadi/tecamino-logger v0.2.1 github.com/gin-gonic/gin v1.11.0 github.com/go-playground/assert/v2 v2.2.0 diff --git a/go.sum b/go.sum index 5ad7dce..e5e7905 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -gitea.tecamino.com/paadi/dbHandler v1.0.4 h1:ctnaec0GDdtw3gRQdUISVDYLJ9x+vt50VW41OemfhD4= -gitea.tecamino.com/paadi/dbHandler v1.0.4/go.mod h1:y/xn/POJg1DO++67uKvnO23lJQgh+XFQq7HZCS9Getw= +gitea.tecamino.com/paadi/dbHandler v1.0.7 h1:777QiVuv6CNsRT/dVtiiQd3NIOQcw7PoYo3Anz4ll+M= +gitea.tecamino.com/paadi/dbHandler v1.0.7/go.mod h1:y/xn/POJg1DO++67uKvnO23lJQgh+XFQq7HZCS9Getw= gitea.tecamino.com/paadi/tecamino-logger v0.2.1 h1:sQTBKYPdzn9mmWX2JXZBtGBvNQH7cuXIwsl4TD0aMgE= gitea.tecamino.com/paadi/tecamino-logger v0.2.1/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM= github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ= diff --git a/handlers/role.go b/handlers/role.go index 5ec9c4e..81e9e3b 100644 --- a/handlers/role.go +++ b/handlers/role.go @@ -17,7 +17,7 @@ func (aH *AccessHandler) AddDefaultRole() (err error) { role := "admin" // Check if a role with this name already exists - if err := aH.dbHandler.Exists(&models.Role{}, "role", role, false); err == nil { + if aH.dbHandler.Exists(&models.Role{}, "role", role, false) { // Found a role → skip creation aH.logger.Debug("AddDefaultRole", "role "+role+" exists already") return nil @@ -52,7 +52,7 @@ func (aH *AccessHandler) AddRole(c *gin.Context) { } // Check if a role with this name already exists - if err := aH.dbHandler.Exists(&models.Role{}, "role", role.Role, false); err == nil { + if aH.dbHandler.Exists(&models.Role{}, "role", role.Role, false) { aH.logger.Error("AddRole", fmt.Sprintf("role with name %s already exists", role.Role)) c.JSON(http.StatusBadRequest, models.NewJsonMessageResponse(fmt.Sprintf("role with name %s already exists", role.Role))) } diff --git a/handlers/user.go b/handlers/user.go index d30c678..c62c33b 100644 --- a/handlers/user.go +++ b/handlers/user.go @@ -21,7 +21,7 @@ func (aH *AccessHandler) AddDefaultUser() (err error) { email := "zuercher@tecamino.ch" // Check if a user with this email already exists - if err := aH.dbHandler.Exists(&models.User{}, "email", email, false); err == nil { + if aH.dbHandler.Exists(&models.User{}, "email", email, false) { aH.logger.Debug("AddDefaultUser", "user email "+email+" exists already") // Found a user → skip create return nil @@ -59,7 +59,7 @@ func (aH *AccessHandler) AddUser(c *gin.Context) { } // Check if a user with this email already exists - if err := aH.dbHandler.Exists(&models.User{}, "email", user.Email, false); err == nil { + if aH.dbHandler.Exists(&models.User{}, "email", user.Email, false) { // Found a user → skip create aH.logger.Error("AddUser", "user with email "+user.Email+" already exists") c.JSON(http.StatusBadRequest, models.NewJsonMessageResponse(fmt.Sprintf("user with email %s already exists", user.Email))) diff --git a/models/user.go b/models/user.go index 3539e9f..a748991 100644 --- a/models/user.go +++ b/models/user.go @@ -1,12 +1,15 @@ package models +import "time" + type User struct { - Id uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"column:user_name" json:"user"` - Email string `gorm:"column:email" json:"email"` - Role string `gorm:"column:role" json:"role,omitempty"` - Password string `gorm:"column:password" json:"password"` - Settings Settings `gorm:"type:json" json:"settings,omitempty"` + Id uint `gorm:"primaryKey" json:"id"` + Name string `gorm:"column:user_name" json:"user"` + Email string `gorm:"column:email" json:"email"` + Role string `gorm:"column:role" json:"role,omitempty"` + Password string `gorm:"column:password" json:"password"` + Expiration *time.Time `gorm:"column:expiration" json:"expiration,omitempty"` + Settings Settings `gorm:"type:json" json:"settings"` } func (u *User) IsValid() bool {