// ActivateUser allows to activate a user by its id
ActivateUser allows to activate a user by its id
// ActivateUser allows to activate a user by its id
func (db *Postgres) ActivateUser(activationKey string, email string) error {
	var user models.User
	fmt.Println("Trying to find user:", email, "with activationKey:", activationKey)
	if err := db.Where("email = ?", email).First(&user).Error; err != nil {
		return helpers.NewError(http.StatusNotFound, "user_not_found", "could not find the user", err)
	}
	if user.Key != activationKey {
		return helpers.NewError(http.StatusBadRequest, "invalid_validation_code", "the provided activation code is invalid", nil)
	}
	if err := db.Model(&user).Update("active", true).Error; err != nil {
		return helpers.NewError(http.StatusInternalServerError, "update_user_failed", "could not update the user", err)
	}
	fmt.Println("Final user:", user)
	return nil
}
func ( db * Postgres ) ActivateUser ( activationKey string , email string ) error { var user models . User fmt . Println ( " " , email , " " , activationKey ) if err := db . Where ( " " , email ) . First ( & user ) . Error ; err != nil { return helpers . NewError ( http . StatusNotFound , " " , " " , err ) } if user . Key != activationKey { return helpers . NewError ( http . StatusBadRequest , " " , " " , nil ) } if err := db . Model ( & user ) . Update ( " " , true ) . Error ; err != nil { return helpers . NewError ( http . StatusInternalServerError , " " , " " , err ) } fmt . Println ( " " , user ) return nil }
ActivateUser allows to activate a user by its id
ActivateUser allows to activate a user by its id