1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

feat: password resets (resolve #133)

This commit is contained in:
Ferdinand Mütsch
2021-04-05 22:57:57 +02:00
parent e6e134678a
commit 6ad33e3c3b
17 changed files with 335 additions and 19 deletions

View File

@ -30,6 +30,7 @@ type User struct {
IsAdmin bool `json:"-" gorm:"default:false; type:bool"`
HasData bool `json:"-" gorm:"default:false; type:bool"`
WakatimeApiKey string `json:"-"`
ResetToken string `json:"-"`
}
type Login struct {
@ -44,6 +45,16 @@ type Signup struct {
PasswordRepeat string `schema:"password_repeat"`
}
type SetPasswordRequest struct {
Password string `schema:"password"`
PasswordRepeat string `schema:"password_repeat"`
Token string `schema:"token"`
}
type ResetPasswordRequest struct {
Email string `schema:"email"`
}
type CredentialsReset struct {
PasswordOld string `schema:"password_old"`
PasswordNew string `schema:"password_new"`
@ -69,6 +80,11 @@ func (c *CredentialsReset) IsValid() bool {
c.PasswordNew == c.PasswordRepeat
}
func (c *SetPasswordRequest) IsValid() bool {
return ValidatePassword(c.Password) &&
c.Password == c.PasswordRepeat
}
func (s *Signup) IsValid() bool {
return ValidateUsername(s.Username) &&
ValidateEmail(s.Email) &&