auth

package
v0.0.0-...-d6e0c60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTokens

func GenerateTokens(userID string, role string) (accessToken string, refreshToken string, err error)

func SessionMiddleware

func SessionMiddleware(sessionManager *SessionManager) func(next http.Handler) http.Handler

Types

type Repository

type Repository struct {
	pb.UnimplementedAuthServer
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(db *pgxpool.Pool, redis *redis.Client, sessionManager *SessionManager) *Repository

NewRepository creates a new AuthService

func (*Repository) ChangeEmail

func (*Repository) ChangePassword

func (*Repository) DeleteUser

func (*Repository) GetAllUsers

func (r *Repository) GetAllUsers(ctx context.Context) (*pb.GetAllUsersResponse, error)

func (*Repository) GetUserByID

func (*Repository) InsertUser

func (*Repository) Login

func (r *Repository) Login(ctx context.Context, req *pb.LoginRequest) (*pb.LoginResponse, error)

func (*Repository) Logout

func (r *Repository) Logout(ctx context.Context, req *pb.NilReq) (*pb.NilRes, error)

func (*Repository) RefreshToken

func (r *Repository) RefreshToken(ctx context.Context, req *pb.RefreshTokenRequest) (*pb.TokenResponse, error)

func (*Repository) Register

func (r *Repository) Register(ctx context.Context, req *pb.RegisterRequest) (*pb.RegisterResponse, error)

func (*Repository) UpdateUser

type Service

type Service struct {
	pb.UnimplementedAuthServer

	SessionManager *SessionManager
	// contains filtered or unexported fields
}

func NewService

func NewService(ctx context.Context, repo domain.AuthRepository,
	db *pgxpool.Pool,
	redis *redis.Client,
	sessionManager *SessionManager) *Service

func (*Service) ChangeEmail

func (s *Service) ChangeEmail(ctx context.Context, req *pb.ChangeEmailRequest) (*pb.ChangeEmailResponse, error)

func (*Service) ChangePassword

func (s *Service) ChangePassword(ctx context.Context, req *pb.ChangePasswordRequest) (*pb.ChangePasswordResponse, error)

func (*Service) DeleteUser

func (s *Service) DeleteUser(ctx context.Context, req *pb.DeleteUserRequest) (*pb.DeleteUserResponse, error)

func (*Service) GetAllUsers

func (*Service) GetUserByID

func (s *Service) GetUserByID(ctx context.Context, req *pb.GetUserByIDRequest) (*pb.GetUserByIDResponse, error)

func (*Service) InsertUser

func (s *Service) InsertUser(ctx context.Context, req *pb.InsertUserRequest) (*pb.InsertUserResponse, error)

func (*Service) Login

func (s *Service) Login(ctx context.Context, req *pb.LoginRequest) (*pb.LoginResponse, error)

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, req *pb.NilReq) (*pb.NilRes, error)

func (*Service) Register

func (s *Service) Register(ctx context.Context, req *pb.RegisterRequest) (*pb.RegisterResponse, error)

func (*Service) UpdateUser

func (s *Service) UpdateUser(ctx context.Context, req *pb.UpdateUserRequest) (*pb.UpdateUserResponse, error)

type SessionManager

type SessionManager struct {
	PgPool *pgxpool.Pool
	Redis  *redis.Client
}

func NewSessionManager

func NewSessionManager(pgpool *pgxpool.Pool, redis *redis.Client) *SessionManager

func (*SessionManager) GetSession

func (s *SessionManager) GetSession(session string) (*UserSession, error)

func (*SessionManager) SignIn

func (s *SessionManager) SignIn(ctx context.Context, email, password string) (string, error)

func (*SessionManager) SignOut

func (s *SessionManager) SignOut(sessionId string) error

type SessionManagerKey

type SessionManagerKey struct{}

type User

type User struct {
	ID       string
	Username string
	Email    string
	Password string
}

type UserSession

type UserSession struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Role     string `json:"role"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL