32 lines
832 B
Go
32 lines
832 B
Go
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"`
|
|
Expiration *time.Time `gorm:"column:expiration" json:"expiration,omitempty"`
|
|
Settings Settings `gorm:"type:json" json:"settings"`
|
|
}
|
|
|
|
func (u *User) IsValid() bool {
|
|
return u.Name != ""
|
|
}
|
|
|
|
func (u *User) ExpirationIsValid() bool {
|
|
if u.Expiration == nil {
|
|
return true
|
|
}
|
|
return time.Now().Before(*u.Expiration)
|
|
}
|
|
|
|
func (u *User) GetExpiration() string {
|
|
if u.Expiration == nil {
|
|
return ""
|
|
}
|
|
return u.Expiration.Format(time.RFC3339)
|
|
}
|