Added reset password route

This commit is contained in:
Nedim
2023-10-30 19:21:43 +01:00
parent 75692d7b20
commit 72ccd5e71c
16 changed files with 531 additions and 33 deletions

42
database/user/user.go Normal file
View 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
}