change fetch users
This commit is contained in:
parent
1e813d5815
commit
67e410f8a7
@ -1,7 +1,9 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"codeword/internal/models"
|
||||||
"codeword/internal/services"
|
"codeword/internal/services"
|
||||||
|
"encoding/base64"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"time"
|
"time"
|
||||||
@ -40,39 +42,35 @@ func (r *RecoveryController) HandleRecoveryRequest(c *fiber.Ctx) error {
|
|||||||
user, err := r.service.FindUserByEmail(c.Context(), email)
|
user, err := r.service.FindUserByEmail(c.Context(), email)
|
||||||
if err != nil || user == nil {
|
if err != nil || user == nil {
|
||||||
r.logger.Error("Failed to find user by email", zap.Error(err))
|
r.logger.Error("Failed to find user by email", zap.Error(err))
|
||||||
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "User not found FindUserByEmail"})
|
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "User not found"})
|
||||||
|
}
|
||||||
|
key := []byte("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 + 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"})
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := r.service.GenerateKey()
|
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 {
|
if err != nil {
|
||||||
r.logger.Error("Failed to generate key", zap.Error(err))
|
r.logger.Error("Failed to send recovery email", zap.Error(err))
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Internal Server Error"})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
"id": key,
|
"id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
//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 пользователя от фронта для поиска в бд
|
// todo тут скорее всего помимо подписи будет передаваться еще что-то, например email пользователя от фронта для поиска в бд
|
||||||
|
@ -21,13 +21,9 @@ type Encrypt struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(deps *EncryptDeps) *Encrypt {
|
func New(deps *EncryptDeps) *Encrypt {
|
||||||
publicKey := "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAEbnIvjIMle4rqVol6K2XUqOxHy1KJoNoZdKJrRUPKL4=\n-----END PUBLIC KEY-----"
|
|
||||||
privateKey := "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIKn0BKwF3vZvODgWAnUIwQhd8de5oZhY48gc23EWfrfs\n-----END PRIVATE KEY-----"
|
|
||||||
return &Encrypt{
|
return &Encrypt{
|
||||||
//publicKey: deps.PublicKey,
|
publicKey: deps.PublicKey,
|
||||||
//privateKey: deps.PrivateKey,
|
privateKey: deps.PrivateKey,
|
||||||
publicKey: publicKey,
|
|
||||||
privateKey: privateKey,
|
|
||||||
signSecret: deps.SignSecret,
|
signSecret: deps.SignSecret,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user