Semaphore/db/User.go

43 lines
1.2 KiB
Go
Raw Normal View History

package db
2016-01-05 00:32:53 +01:00
import (
"time"
)
2022-10-30 18:18:23 +01:00
// User is the model for an entity which has access to the API
2016-01-05 00:32:53 +01:00
type User struct {
ID int `db:"id" json:"id"`
Created time.Time `db:"created" json:"created"`
Username string `db:"username" json:"username" binding:"required"`
Name string `db:"name" json:"name" binding:"required"`
Email string `db:"email" json:"email" binding:"required"`
Password string `db:"password" json:"-"` // password hash
Admin bool `db:"admin" json:"admin"`
External bool `db:"external" json:"external"`
Alert bool `db:"alert" json:"alert"`
}
type UserWithProjectRole struct {
Role ProjectUserRole `db:"role" json:"role"`
User
2016-01-05 00:32:53 +01:00
}
// UserWithPwd extends User structure with field for unhashed password received from JSON.
type UserWithPwd struct {
2021-12-18 14:16:34 +01:00
Pwd string `db:"-" json:"password"` // unhashed password from JSON
User
}
2021-10-12 13:37:51 +02:00
2021-12-18 14:16:34 +01:00
func ValidateUser(user User) error {
2022-10-30 18:18:23 +01:00
if user.Username == "" {
return &ValidationError{Message: "Username cannot be empty"}
}
if user.Email == "" {
return &ValidationError{Message: "Email cannot be empty"}
}
if user.Name == "" {
return &ValidationError{Message: "Name cannot be empty"}
}
2021-10-12 13:37:51 +02:00
return nil
}