change fetch users

This commit is contained in:
Pavel 2024-01-18 18:08:47 +03:00
parent bf6cdb69a7
commit 1e813d5815
2 changed files with 23 additions and 22 deletions

@ -1,9 +1,7 @@
package controller
import (
"codeword/internal/models"
"codeword/internal/services"
"encoding/base64"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
"time"
@ -51,26 +49,30 @@ func (r *RecoveryController) HandleRecoveryRequest(c *fiber.Ctx) error {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
}
signUrl := redirectionURL + base64.URLEncoding.EncodeToString(key)
sign := base64.URLEncoding.EncodeToString(key)
id, err := r.service.StoreRecoveryRecord(c.Context(), models.StoreRecDeps{UserID: user.ID.Hex(), Email: user.Email, Key: sign, Url: signUrl})
if err != nil {
r.logger.Error("Failed to store recovery record", zap.Error(err))
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Internal Server Error StoreRecoveryRecord"})
}
signWithID := sign + id // подпись с id записи
err = r.service.RecoveryEmailTask(c.Context(), models.RecEmailDeps{UserID: user.ID.Hex(), Email: email, SignWithID: signWithID, ID: id})
if err != nil {
r.logger.Error("Failed to send recovery email", zap.Error(err))
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Internal Server Error RecoveryEmailTask"})
}
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"id": id,
"id": key,
})
//signUrl := redirectionURL + base64.URLEncoding.EncodeToString(key)
//sign := base64.URLEncoding.EncodeToString(key)
//
//id, err := r.service.StoreRecoveryRecord(c.Context(), models.StoreRecDeps{UserID: user.ID.Hex(), Email: user.Email, Key: sign, Url: signUrl})
//if err != nil {
// r.logger.Error("Failed to store recovery record", zap.Error(err))
// return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Internal Server Error StoreRecoveryRecord"})
//}
//
//signWithID := sign + id // подпись с id записи
//
//err = r.service.RecoveryEmailTask(c.Context(), models.RecEmailDeps{UserID: user.ID.Hex(), Email: email, SignWithID: signWithID, ID: id})
//if err != nil {
// r.logger.Error("Failed to send recovery email", zap.Error(err))
// return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Internal Server Error RecoveryEmailTask"})
//}
//
//return c.Status(fiber.StatusOK).JSON(fiber.Map{
// "id": id,
//})
}
// todo тут скорее всего помимо подписи будет передаваться еще что-то, например email пользователя от фронта для поиска в бд

@ -68,8 +68,7 @@ func (receiver *Encrypt) SignCommonSecret() (signature []byte, err error) {
block, _ := pem.Decode([]byte(receiver.privateKey))
if block == nil {
//return []byte{}, fmt.Errorf("failed decode private key %s on <SignCommonSecret> of <EncryptService>: %w", receiver.privateKey, err)
return []byte{}, errors.New(receiver.privateKey)
return []byte{}, fmt.Errorf("failed decode private key %s on <SignCommonSecret> of <EncryptService>: %w", receiver.privateKey, err)
}
rawPrivateKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)