modified: serv_nginx/api_bb/internal/handlers/auth.go
add logger into updateProfile function
This commit is contained in:
@@ -37,7 +37,7 @@ func (h *AuthHandler) Routes() chi.Router {
|
|||||||
r.Options("/login", h.handleOptions)
|
r.Options("/login", h.handleOptions)
|
||||||
r.Options("/logout", h.handleOptions)
|
r.Options("/logout", h.handleOptions)
|
||||||
r.Options("/profile", h.handleOptions)
|
r.Options("/profile", h.handleOptions)
|
||||||
r.Options("/editProfile", h.handleOptions)
|
r.Options("/editProfile", h.handleOptions)
|
||||||
|
|
||||||
r.Post("/register", h.Register)
|
r.Post("/register", h.Register)
|
||||||
r.Post("/login", h.Login)
|
r.Post("/login", h.Login)
|
||||||
@@ -97,10 +97,10 @@ func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.RespondWithError(w, http.StatusBadRequest, "Failed to read request body: "+err.Error())
|
utils.RespondWithError(w, http.StatusBadRequest, "Failed to read request body: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Восстанавливаем тело для дальнейшего использования
|
// Восстанавливаем тело для дальнейшего использования
|
||||||
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
|
|
||||||
fmt.Printf("Raw request body: %s\n", string(bodyBytes))
|
fmt.Printf("Raw request body: %s\n", string(bodyBytes))
|
||||||
|
|
||||||
var req RegisterRequest
|
var req RegisterRequest
|
||||||
@@ -133,7 +133,7 @@ func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.RespondWithError(w, http.StatusBadRequest, "Password must be at least 6 characters")
|
utils.RespondWithError(w, http.StatusBadRequest, "Password must be at least 6 characters")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user := &models.User{
|
user := &models.User{
|
||||||
Email: req.Email,
|
Email: req.Email,
|
||||||
Password: req.Password,
|
Password: req.Password,
|
||||||
@@ -147,7 +147,7 @@ func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.authService.Register(user); err != nil {
|
if err := h.authService.Register(user); err != nil {
|
||||||
fmt.Printf("Auth service error: %v\n", err)
|
fmt.Printf("Auth service error: %v\n", err)
|
||||||
utils.RespondWithError(w, http.StatusBadRequest, err.Error())
|
utils.RespondWithError(w, http.StatusBadRequest, err.Error())
|
||||||
@@ -265,10 +265,22 @@ type UpdateProfileRequest struct {
|
|||||||
|
|
||||||
func (h *AuthHandler) UpdateProfile(w http.ResponseWriter, r *http.Request) {
|
func (h *AuthHandler) UpdateProfile(w http.ResponseWriter, r *http.Request) {
|
||||||
// Устанавливаем CORS заголовки
|
// Устанавливаем CORS заголовки
|
||||||
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
|
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
|
||||||
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "PUT, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Methods", "PUT, OPTIONS")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
|
|
||||||
|
// Логируем тело запроса для отладки
|
||||||
|
bodyBytes, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
utils.RespondWithError(w, http.StatusBadRequest, "Failed to read request body: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Восстанавливаем тело для дальнейшего использования
|
||||||
|
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
|
|
||||||
|
fmt.Printf("Raw request body: %s\n", string(bodyBytes))
|
||||||
|
|
||||||
// Получаем пользователя из контекста
|
// Получаем пользователя из контекста
|
||||||
currentUser, ok := middleware.GetUserFromContext(r.Context())
|
currentUser, ok := middleware.GetUserFromContext(r.Context())
|
||||||
|
|||||||
Reference in New Issue
Block a user