2019-05-06 01:40:41 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
type User struct {
|
2020-11-06 19:20:26 +03:00
|
|
|
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"`
|
|
|
|
LastLoggedInAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP"`
|
|
|
|
BadgesEnabled bool `json:"-" gorm:"default:false; type:bool"`
|
2019-05-06 01:40:41 +03:00
|
|
|
}
|
2020-05-24 14:41:19 +03:00
|
|
|
|
|
|
|
type Login struct {
|
2020-05-24 17:34:32 +03:00
|
|
|
Username string `schema:"username"`
|
|
|
|
Password string `schema:"password"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Signup struct {
|
|
|
|
Username string `schema:"username"`
|
|
|
|
Password string `schema:"password"`
|
|
|
|
PasswordRepeat string `schema:"password_repeat"`
|
2020-05-24 14:41:19 +03:00
|
|
|
}
|
2020-05-24 22:42:15 +03:00
|
|
|
|
2020-06-07 20:28:32 +03:00
|
|
|
type CredentialsReset struct {
|
|
|
|
PasswordOld string `schema:"password_old"`
|
|
|
|
PasswordNew string `schema:"password_new"`
|
|
|
|
PasswordRepeat string `schema:"password_repeat"`
|
|
|
|
}
|
|
|
|
|
2020-11-07 14:01:35 +03:00
|
|
|
type TimeByUser struct {
|
|
|
|
User string
|
|
|
|
Time CustomTime
|
|
|
|
}
|
|
|
|
|
2020-06-07 20:28:32 +03:00
|
|
|
func (c *CredentialsReset) IsValid() bool {
|
|
|
|
return validatePassword(c.PasswordNew) &&
|
|
|
|
c.PasswordNew == c.PasswordRepeat
|
|
|
|
}
|
|
|
|
|
2020-05-24 22:42:15 +03:00
|
|
|
func (s *Signup) IsValid() bool {
|
2020-06-07 20:28:32 +03:00
|
|
|
return validateUsername(s.Username) &&
|
|
|
|
validatePassword(s.Password) &&
|
2020-05-24 22:42:15 +03:00
|
|
|
s.Password == s.PasswordRepeat
|
|
|
|
}
|
2020-06-07 20:28:32 +03:00
|
|
|
|
|
|
|
func validateUsername(username string) bool {
|
2021-01-12 13:05:07 +03:00
|
|
|
return len(username) >= 1 && username != "current"
|
2020-06-07 20:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func validatePassword(password string) bool {
|
|
|
|
return len(password) >= 6
|
|
|
|
}
|