diff --git a/controller/v1/user.go b/controller/v1/user.go index 054a67b4..6575248a 100644 --- a/controller/v1/user.go +++ b/controller/v1/user.go @@ -339,6 +339,14 @@ func (uc *UserController) LoginUser(c echo.Context) error { response, _ := json.Marshal(loginObject) return httpresponse.CreateBadResponseWithJson(&c, http.StatusUnauthorized, response) } + if !userData.Enabled { + loginObject := model.UserTokenBadResponse{} + loginObject.StatusCode = http.StatusUnauthorized + loginObject.Message = webmessages.Unauthorized + loginObject.Error = webmessages.Unauthorized + response, _ := json.Marshal(loginObject) + return httpresponse.CreateBadResponseWithJson(&c, http.StatusUnauthorized, response) + } loginObject := model.UserTokenSuccessfulResponse{} loginObject.Token = token diff --git a/data/service/user.go b/data/service/user.go index da7df98e..3763acf8 100644 --- a/data/service/user.go +++ b/data/service/user.go @@ -161,14 +161,14 @@ func (us *UserService) UpdateUser(user *model.TableUser, UserName string, isAdmi } if !isAdmin { err := us.Session.Debug().Table("users").Model(&model.TableUser{}).Where(sqlWhere).Update(model.TableUser{Email: user.Email, FirstName: user.FirstName, - LastName: user.LastName, Department: user.Department, Hash: user.Hash, CreatedAt: user.CreatedAt}).Error + LastName: user.LastName, Department: user.Department, Hash: user.Hash, CreatedAt: user.CreatedAt, Enabled: user.Enabled}).Error if err != nil { return err } } else { err := us.Session.Debug().Table("users").Model(&model.TableUser{}).Where(sqlWhere).Update(model.TableUser{UserName: user.UserName, PartId: user.PartId, Email: user.Email, FirstName: user.FirstName, LastName: user.LastName, Department: user.Department, UserGroup: user.UserGroup, - Hash: user.Hash, CreatedAt: user.CreatedAt}).Error + Hash: user.Hash, CreatedAt: user.CreatedAt, Enabled: user.Enabled}).Error if err != nil { return err } diff --git a/model/user.go b/model/user.go index 07c481e6..c641b640 100644 --- a/model/user.go +++ b/model/user.go @@ -25,6 +25,9 @@ type TableUser struct { Password string `gorm:"-" json:"password"` // required: true + Enabled bool `gorm:"column:enabled;type:bool;default:true" json:"enabled"` + // required: true + FirstName string `gorm:"column:firstname;type:varchar(50);not null" json:"firstname" validate:"required"` // required: true LastName string `gorm:"column:lastname;type:varchar(50);not null" json:"lastname"` diff --git a/swagger.json b/swagger.json index e32caad9..93153876 100644 --- a/swagger.json +++ b/swagger.json @@ -6172,6 +6172,11 @@ "x-go-name": "Partid", "example": 10 }, + "enabled": { + "type": "boolean", + "x-go-name": "Enabled", + "example": true + }, "usergroup": { "type": "string", "x-go-name": "Usergroup",