d45c5841dc
modified: main_dc/yalarba/api_yal/go.sum modified: main_dc/yalarba/api_yal/internal/domain/auth/dto.go modified: main_dc/yalarba/api_yal/internal/domain/auth/handler.go modified: main_dc/yalarba/api_yal/internal/domain/auth/router.go modified: main_dc/yalarba/api_yal/internal/domain/auth/servcie.go new file: main_dc/yalarba/api_yal/internal/middleware/auth.go deleted: main_dc/yalarba/api_yal/internal/middleware/authMiddleware.go modified: main_dc/yalarba/api_yal/internal/router/router.go set auth domain, not tested
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package auth
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// RegisterRequest - запрос на регистрацию
|
|
type RegisterRequest struct {
|
|
Email string `json:"email" validate:"required,email"`
|
|
Password string `json:"password" validate:"required,min=6"`
|
|
FirstName string `json:"first_name" validate:"required"`
|
|
LastName string `json:"last_name" validate:"required"`
|
|
}
|
|
|
|
// LoginRequest - запрос на вход
|
|
type LoginRequest struct {
|
|
Email string `json:"email" validate:"required,email"`
|
|
Password string `json:"password" validate:"required"`
|
|
}
|
|
|
|
// AuthResponse структура ответа при успешной аутентификации
|
|
type AuthResponse struct {
|
|
Token string `json:"token"`
|
|
RefreshToken string `json:"refresh_token,omitempty"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
User UserInfo `json:"user"`
|
|
}
|
|
|
|
// ResetPasswordRequest - запрос на сброс пароля
|
|
type ResetPasswordRequest struct {
|
|
Email string `json:"email" validate:"required,email"`
|
|
}
|
|
|
|
// RefreshTokenRequest - запрос на обновление токена
|
|
type RefreshTokenRequest struct {
|
|
RefreshToken string `json:"refresh_token" validate:"required"`
|
|
}
|
|
|
|
// ChangePasswordRequest - запрос на смену пароля
|
|
type ChangePasswordRequest struct {
|
|
OldPassword string `json:"old_password" validate:"required"`
|
|
NewPassword string `json:"new_password" validate:"required,min=6"`
|
|
}
|
|
|
|
// UserInfo информация о пользователе для ответа
|
|
type UserInfo struct {
|
|
ID uint `json:"id"`
|
|
Email string `json:"email"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
FullName string `json:"full_name"`
|
|
Role string `json:"role"`
|
|
}
|
|
|
|
var (
|
|
ErrUserNotFound = errors.New("user not found")
|
|
ErrInvalidPassword = errors.New("invalid password")
|
|
ErrUserAlreadyExists = errors.New("user with this email already exists")
|
|
)
|