new user expiration with user date format and never option
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
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"`
|
||||
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 string `gorm:"column:expiration" json:"expiration,omitempty"`
|
||||
Settings Settings `gorm:"type:json" json:"settings"`
|
||||
}
|
||||
|
||||
func (u *User) IsValid() bool {
|
||||
@@ -17,15 +19,10 @@ func (u *User) IsValid() bool {
|
||||
}
|
||||
|
||||
func (u *User) ExpirationIsValid() bool {
|
||||
if u.Expiration == nil {
|
||||
if u.Expiration == "" || u.Expiration == "never" {
|
||||
return true
|
||||
}
|
||||
return time.Now().Before(*u.Expiration)
|
||||
}
|
||||
|
||||
func (u *User) GetExpiration() string {
|
||||
if u.Expiration == nil {
|
||||
return ""
|
||||
}
|
||||
return u.Expiration.Format(time.RFC3339)
|
||||
loc := time.Now().Location()
|
||||
parsedTime, _ := time.ParseInLocation("2006-01-02 15:04:05", u.Expiration, loc)
|
||||
return parsedTime.After(time.Now())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user