Documentation
¶
Index ¶
- Variables
- type Login
- type Service
- type ServiceImpl
- func (s *ServiceImpl) DeleteUser(ctx context.Context, id uint) error
- func (s *ServiceImpl) GetByID(ctx context.Context, id string) (*User, error)
- func (s *ServiceImpl) GetUserByEmail(ctx context.Context, email string) (*User, error)
- func (s *ServiceImpl) GetUserByID(ctx context.Context, id uint) (*User, error)
- func (s *ServiceImpl) GetUserIDFromToken(token string) (string, error)
- func (s *ServiceImpl) IsTokenBlacklisted(token string) bool
- func (s *ServiceImpl) ListUsers(ctx context.Context) ([]User, error)
- func (s *ServiceImpl) Login(ctx context.Context, login *Login) (*TokenPair, error)
- func (s *ServiceImpl) Logout(ctx context.Context, token string) error
- func (s *ServiceImpl) RefreshToken(ctx context.Context, refreshToken string) (*TokenPair, error)
- func (s *ServiceImpl) SignUp(ctx context.Context, signup *Signup) (*User, error)
- func (s *ServiceImpl) UpdateUser(ctx context.Context, user *User) error
- func (s *ServiceImpl) ValidateToken(tokenString string) (*jwt.Token, error)
- type Signup
- type Store
- type TokenPair
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUserNotFound indicates that a user was not found ErrUserNotFound = errors.New("user not found") // ErrEmailAlreadyExists indicates that a user with the given email already exists ErrEmailAlreadyExists = errors.New("email already exists") // ErrInvalidCredentials indicates that the provided credentials are invalid ErrInvalidCredentials = errors.New("invalid credentials") // ErrInvalidToken indicates that the provided token is invalid ErrInvalidToken = errors.New("invalid token") // ErrTokenBlacklisted indicates that the token has been blacklisted ErrTokenBlacklisted = errors.New("token is blacklisted") // ErrInvalidUserIDClaim indicates that the user_id claim type is invalid ErrInvalidUserIDClaim = errors.New("invalid user_id claim type") // ErrInvalidUserID indicates that the user_id claim type is invalid ErrInvalidUserID = errors.New("invalid user_id claim type") // ErrUserExists indicates that a user with the given email already exists ErrUserExists = errors.New("user already exists") )
Functions ¶
This section is empty.
Types ¶
type Login ¶
type Login struct {
Email string `json:"email" validate:"required,email"`
Password string `json:"password" validate:"required"`
}
Login represents the user login request
type Service ¶
type Service interface {
SignUp(ctx context.Context, signup *Signup) (*User, error)
Login(ctx context.Context, login *Login) (*TokenPair, error)
Logout(ctx context.Context, token string) error
RefreshToken(ctx context.Context, refreshToken string) (*TokenPair, error)
GetUserByID(ctx context.Context, id uint) (*User, error)
GetUserByEmail(ctx context.Context, email string) (*User, error)
UpdateUser(ctx context.Context, user *User) error
DeleteUser(ctx context.Context, id uint) error
ListUsers(ctx context.Context) ([]User, error)
ValidateToken(token string) (*jwt.Token, error)
IsTokenBlacklisted(token string) bool
GetUserIDFromToken(token string) (string, error)
GetByID(ctx context.Context, id string) (*User, error)
}
Service defines the user service interface
type ServiceImpl ¶
type ServiceImpl struct {
// contains filtered or unexported fields
}
ServiceImpl implements the Service interface
func (*ServiceImpl) DeleteUser ¶
func (s *ServiceImpl) DeleteUser(ctx context.Context, id uint) error
DeleteUser removes a user by ID
func (*ServiceImpl) GetUserByEmail ¶
GetUserByEmail retrieves a user by email
func (*ServiceImpl) GetUserByID ¶
GetUserByID retrieves a user by ID
func (*ServiceImpl) GetUserIDFromToken ¶
func (s *ServiceImpl) GetUserIDFromToken(token string) (string, error)
GetUserIDFromToken retrieves the user ID from a token
func (*ServiceImpl) IsTokenBlacklisted ¶
func (s *ServiceImpl) IsTokenBlacklisted(token string) bool
IsTokenBlacklisted checks if a token is in the blacklist
func (*ServiceImpl) ListUsers ¶
func (s *ServiceImpl) ListUsers(ctx context.Context) ([]User, error)
ListUsers returns all users
func (*ServiceImpl) Logout ¶
func (s *ServiceImpl) Logout(ctx context.Context, token string) error
Logout adds a token to the blacklist
func (*ServiceImpl) RefreshToken ¶
RefreshToken generates a new token pair using a refresh token
func (*ServiceImpl) UpdateUser ¶
func (s *ServiceImpl) UpdateUser(ctx context.Context, user *User) error
UpdateUser updates an existing user
func (*ServiceImpl) ValidateToken ¶
func (s *ServiceImpl) ValidateToken(tokenString string) (*jwt.Token, error)
ValidateToken validates a JWT token
type Signup ¶
type Signup struct {
Email string `json:"email" validate:"required,email"`
Password string `json:"password" validate:"required,min=8"`
FirstName string `json:"first_name" validate:"required"`
LastName string `json:"last_name" validate:"required"`
}
Signup represents the user signup request
type Store ¶
type Store interface {
Create(ctx context.Context, user *User) error
GetByID(ctx context.Context, id uint) (*User, error)
GetByEmail(ctx context.Context, email string) (*User, error)
Update(ctx context.Context, user *User) error
Delete(ctx context.Context, id uint) error
List(ctx context.Context) ([]User, error)
}
Store defines the interface for user data operations
type TokenPair ¶
type TokenPair struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}
TokenPair represents an access and refresh token pair
type User ¶
type User struct {
ID uint `json:"id" db:"id"`
Email string `json:"email" db:"email"`
HashedPassword string `json:"-" db:"hashed_password"`
FirstName string `json:"first_name" db:"first_name"`
LastName string `json:"last_name" db:"last_name"`
Role string `json:"role" db:"role"`
Active bool `json:"active" db:"active"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
User represents a user in the system
func (*User) CheckPassword ¶
CheckPassword verifies if the provided password matches the user's hashed password
func (*User) SetPassword ¶
SetPassword hashes and sets the user's password