Added reset password route
This commit is contained in:
42
database/user/user.go
Normal file
42
database/user/user.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
"gitlab.com/pactual1/backend/models"
|
||||
"gitlab.com/pactual1/backend/shared"
|
||||
)
|
||||
|
||||
func SaveResetTokenToDB(userID uint, resetToken string) error {
|
||||
// Calculate the expiry date (one month from now)
|
||||
expiryDate := time.Now().AddDate(0, 1, 0).Format(time.RFC3339)
|
||||
|
||||
// Create a new PasswordTokens instance
|
||||
passwordToken := models.PasswordTokens{
|
||||
UserID: userID,
|
||||
Token: resetToken,
|
||||
ExpiryDate: expiryDate,
|
||||
}
|
||||
|
||||
// Save the password token to the database
|
||||
if err := shared.GetDb().Create(&passwordToken).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetUserByEmail(email string) (*models.User, error) {
|
||||
var user models.User
|
||||
|
||||
// Query the database for a user with the specified email
|
||||
if err := shared.GetDb().Where("email = ?", email).First(&user).Error; err != nil {
|
||||
if gorm.IsRecordNotFoundError(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user, nil
|
||||
}
|
||||
Reference in New Issue
Block a user