diff --git a/internal/controller/recovery/recovery_controller.go b/internal/controller/recovery/recovery_controller.go index 84d2312..8db3fd2 100644 --- a/internal/controller/recovery/recovery_controller.go +++ b/internal/controller/recovery/recovery_controller.go @@ -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 пользователя от фронта для поиска в бд diff --git a/internal/utils/encrypt/encrypt_util.go b/internal/utils/encrypt/encrypt_util.go index 67d13f6..cf5a040 100644 --- a/internal/utils/encrypt/encrypt_util.go +++ b/internal/utils/encrypt/encrypt_util.go @@ -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 of : %w", receiver.privateKey, err) - return []byte{}, errors.New(receiver.privateKey) + return []byte{}, fmt.Errorf("failed decode private key %s on of : %w", receiver.privateKey, err) } rawPrivateKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)