mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package models
|
|
|
|
type User struct {
|
|
ID string `json:"id" gorm:"primary_key"`
|
|
ApiKey string `json:"api_key" gorm:"unique"`
|
|
Password string `json:"-"`
|
|
CreatedAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"`
|
|
LastLoggedInAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"`
|
|
ShareDataMaxDays int `json:"-" gorm:"default:0"`
|
|
ShareEditors bool `json:"-" gorm:"default:false; type:bool"`
|
|
ShareLanguages bool `json:"-" gorm:"default:false; type:bool"`
|
|
ShareProjects bool `json:"-" gorm:"default:false; type:bool"`
|
|
ShareOSs bool `json:"-" gorm:"default:false; type:bool; column:share_oss"`
|
|
ShareMachines bool `json:"-" gorm:"default:false; type:bool"`
|
|
WakatimeApiKey string `json:"-"`
|
|
}
|
|
|
|
type Login struct {
|
|
Username string `schema:"username"`
|
|
Password string `schema:"password"`
|
|
}
|
|
|
|
type Signup struct {
|
|
Username string `schema:"username"`
|
|
Password string `schema:"password"`
|
|
PasswordRepeat string `schema:"password_repeat"`
|
|
}
|
|
|
|
type CredentialsReset struct {
|
|
PasswordOld string `schema:"password_old"`
|
|
PasswordNew string `schema:"password_new"`
|
|
PasswordRepeat string `schema:"password_repeat"`
|
|
}
|
|
|
|
type TimeByUser struct {
|
|
User string
|
|
Time CustomTime
|
|
}
|
|
|
|
func (c *CredentialsReset) IsValid() bool {
|
|
return validatePassword(c.PasswordNew) &&
|
|
c.PasswordNew == c.PasswordRepeat
|
|
}
|
|
|
|
func (s *Signup) IsValid() bool {
|
|
return validateUsername(s.Username) &&
|
|
validatePassword(s.Password) &&
|
|
s.Password == s.PasswordRepeat
|
|
}
|
|
|
|
func validateUsername(username string) bool {
|
|
return len(username) >= 1 && username != "current"
|
|
}
|
|
|
|
func validatePassword(password string) bool {
|
|
return len(password) >= 6
|
|
}
|