4 "golang.org/x/crypto/bcrypt"
10 Confirmed UserStatus = iota + 1
16 Email string `sql:",unique,notnull"`
17 PasswordHash string `sql:",notnull"`
23 func HashPassword(password string) (string, error) {
24 b, err := bcrypt.GenerateFromPassword([]byte(password), 10)
29 func ValidatePassword(password string, hash string) error {
30 return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
33 func InsertUser(user *User) error {
34 return DB.Insert(user)
37 func ConfirmUserByEmail(email string) error {
38 _, err := DB.Model(&User{}).Set("status=?", Confirmed).Where("email=?", email).Returning("*").Update()
43 func GetUserById(id int64) (*User, error) {
46 err := DB.Select(&user)
51 func GetUserByEmail(email string) (*User, error) {
54 err := DB.Model(&users).Where("email = ?", email).Select()
67 func SetOtpSecret(user *User, secret string, temporary bool) error {
68 user.OtpSecret = secret
69 user.IsOtpSetup = !temporary
71 return DB.Update(user)