mirror of https://github.com/statping/statping.git
parent
889661f175
commit
ec6c9f6702
@ -1,9 +1,28 @@
|
||||
package users
|
||||
|
||||
import "github.com/statping/statping/utils"
|
||||
import (
|
||||
"github.com/statping/statping/types/errors"
|
||||
"github.com/statping/statping/utils"
|
||||
)
|
||||
|
||||
func (u *User) Validate() error {
|
||||
if u.Username == "" {
|
||||
return errors.New("username is empty")
|
||||
} else if u.Password == "" {
|
||||
return errors.New("password is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *User) BeforeCreate() error {
|
||||
if err := u.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
u.Password = utils.HashPassword(u.Password)
|
||||
u.ApiKey = utils.NewSHA256Hash()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *User) BeforeUpdate() error {
|
||||
return u.Validate()
|
||||
}
|
||||
|
Loading…
Reference in new issue