Add query to get token

Resolves #16
This commit is contained in:
Lakhan Samani
2021-07-15 17:32:55 +05:30
parent 1d6191cbcb
commit 699c49ade0
7 changed files with 123 additions and 42 deletions

View File

@@ -16,7 +16,7 @@ type Manager interface {
AddUser(user User) (User, error)
GetUsers() ([]User, error)
GetUserByEmail(email string) (User, error)
UpdateVerificationTime(verifiedAt int64, email string) error
UpdateVerificationTime(verifiedAt int64, id uint) error
AddVerification(verification Verification) (Verification, error)
GetVerificationByToken(token string) (Verification, error)
DeleteToken(email string) error

View File

@@ -24,8 +24,10 @@ type User struct {
func (user *User) BeforeSave(tx *gorm.DB) error {
// Modify current operation through tx.Statement, e.g:
if pw, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost); err == nil {
tx.Statement.SetColumn("Password", pw)
if user.Password != "" {
if pw, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost); err == nil {
tx.Statement.SetColumn("Password", string(pw))
}
}
return nil
@@ -63,8 +65,11 @@ func (mgr *manager) GetUserByEmail(email string) (User, error) {
return user, nil
}
func (mgr *manager) UpdateVerificationTime(verifiedAt int64, email string) error {
result := mgr.db.Model(&User{}).Where("email = ?", email).Update("email_verified_at", verifiedAt)
func (mgr *manager) UpdateVerificationTime(verifiedAt int64, id uint) error {
user := &User{
ID: id,
}
result := mgr.db.Model(&user).Where("id = ?", id).Update("email_verified_at", verifiedAt)
if result.Error != nil {
return result.Error