diff --git a/.env b/.env index 2b9075e..62434bc 100644 --- a/.env +++ b/.env @@ -18,9 +18,13 @@ REDIS_DB=2 # Keys PUBLIC_CURVE_KEY="-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAEbnIvjIMle4rqVol6K2XUqOxHy1KJoNoZdKJrRUPKL4=\n-----END PUBLIC KEY-----" + PRIVATE_CURVE_KEY="-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIKn0BKwF3vZvODgWAnUIwQhd8de5oZhY48gc23EWfrfs\n-----END PRIVATE KEY-----" + SIGN_SECRET="pena-auth-microservice-group" +SIGN_SECRET="secret" + # SMTP settings SMTP_API_URL="https://api.smtp.bz/v1/smtp/send" SMTP_HOST="connect.mailclient.bz" diff --git a/internal/controller/recovery/recovery_controller.go b/internal/controller/recovery/recovery_controller.go index 1c175a6..cd10b1d 100644 --- a/internal/controller/recovery/recovery_controller.go +++ b/internal/controller/recovery/recovery_controller.go @@ -1,7 +1,9 @@ package controller import ( + "codeword/internal/models" "codeword/internal/services" + "encoding/base64" "github.com/gofiber/fiber/v2" "go.uber.org/zap" "time" @@ -42,32 +44,32 @@ func (r *RecoveryController) HandleRecoveryRequest(c *fiber.Ctx) error { r.logger.Error("Failed to find user by email", zap.Error(err)) return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "User not found"}) } - key := "GSiyv5zBITGshqnvYLHKtXE3e4yZjKGvruOVFWuUuj9Nvaps28-Zt6RDq9n47eaNUlay1-nUVld61I3xoAAgCA==65a79d5d67734ab00b3c9463" - //key, err := r.service.GenerateKey() - //if err != nil { - // r.logger.Error("Failed to generate key", zap.Error(err)) - // return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Internal Server Error"}) - //} - //signUrl := redirectionURL + key - //sign := key + key, err := r.service.GenerateKey() + if err != nil { + r.logger.Error("Failed to generate key", zap.Error(err)) + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Internal Server Error"}) + } - //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"}) - //} + signUrl := redirectionURL + base64.URLEncoding.EncodeToString(key) + sign := base64.URLEncoding.EncodeToString(key) - //signWithID := sign + id // подпись с id записи + 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"}) + } - //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"}) - //} + 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"}) + } return c.Status(fiber.StatusOK).JSON(fiber.Map{ - "id": key, + "id": id, }) }