8 files changed,
58 insertions(+),
3 deletions(-)
Author:
Olexandr Smirnov
ss2316544@gmail.com
Committed by:
Olexandr Smirnov
olexsmir@gmail.com
Committed at:
2025-08-11 16:02:18 +0300
Authored at:
2025-08-10 15:17:29 +0300
Change ID:
olptkzqmvvnlnxupnypszlwlkrxpwrks
Parent:
aebfa02
jump to
M
internal/events/mailermq/mailermq.go
··· 12 12 const sendTopic = "mailer.send" 13 13 14 14 type Mailer interface { 15 + // SendVerificationEmail sends an email with a verification token to the user. 15 16 SendVerificationEmail(ctx context.Context, input SendVerificationEmailRequest) error 17 + 18 + // SendPasswordResetEmail sends an email with a password reset token to the user. 16 19 SendPasswordResetEmail(ctx context.Context, input SendPasswordResetEmailRequest) error 17 20 } 18 21
M
internal/service/usersrv/usersrv.go
··· 22 22 ) 23 23 24 24 type UserServicer interface { 25 + // SignUp creates a new user and sends verification email. 25 26 SignUp(ctx context.Context, inp dtos.SignUp) (uuid.UUID, error) 27 + 28 + // SignIn authenticates a user and returns access and refresh tokens. 26 29 SignIn(ctx context.Context, inp dtos.SignIn) (dtos.Tokens, error) 30 + 31 + // RefreshTokens refreshes the access and refresh tokens using the provided refresh token. 27 32 RefreshTokens(ctx context.Context, refreshToken string) (dtos.Tokens, error) 33 + 34 + // Logout logs out a user by deleting the session associated with the provided refresh token. 28 35 Logout(ctx context.Context, userID uuid.UUID, refreshToken string) error 36 + 37 + // LogoutAll logs out a user by deleting all sessions associated with the user ID. 29 38 LogoutAll(ctx context.Context, userID uuid.UUID) error 39 + 40 + // GetUserInfo retrieves user information by user ID. 30 41 GetUserInfo(ctx context.Context, userID uuid.UUID) (dtos.UserInfo, error) 31 42 43 + // ChangePassword changes the user's password. 32 44 ChangePassword(ctx context.Context, userID uuid.UUID, inp dtos.ChangeUserPassword) error 45 + 46 + // RequestPasswordReset initiates a password reset process by sending a reset email. 33 47 RequestPasswordReset(ctx context.Context, inp dtos.RequestResetPassword) error 48 + 49 + // ResetPassword resets the user's password using the provided reset token. 34 50 ResetPassword(ctx context.Context, inp dtos.ResetPassword) error 35 51 52 + // GetOAuthURL retrieves the OAuth URL for the specified provider. 36 53 GetOAuthURL(providerName string) (dtos.OAuthRedirect, error) 54 + 55 + // HandleOAuthLogin handles the OAuth login process by exchanging the code for tokens. 37 56 HandleOAuthLogin(ctx context.Context, providerName, code string) (dtos.Tokens, error) 38 57 58 + // Verify verifies the user's email using the provided verification key. 39 59 Verify(ctx context.Context, verificationKey string) error 60 + 61 + // ResendVerificationEmail resends the verification email to the user. 40 62 ResendVerificationEmail(ctx context.Context, inp dtos.ResendVerificationEmail) error 41 63 64 + // ParseJWTToken parses the JWT token and returns the payload. 42 65 ParseJWTToken(token string) (jwtutil.Payload, error) 43 66 67 + // CheckIfUserExists checks if a user exists by user ID. 44 68 CheckIfUserExists(ctx context.Context, userID uuid.UUID) (bool, error) 69 + 70 + // CheckIfUserIsActivated checks if a user is activated by user ID. 45 71 CheckIfUserIsActivated(ctx context.Context, userID uuid.UUID) (bool, error) 46 72 } 47 73
M
internal/store/psql/passwordtokrepo/passwordtokrepo.go
··· 13 13 ) 14 14 15 15 type PasswordResetTokenStorer interface { 16 + // Create a new password reset token. 16 17 Create(ctx context.Context, input models.ResetPasswordToken) error 17 18 19 + // GetUserIDByTokenAndMarkAsUsed gets the token, and marks it as used. 20 + // 21 + // In case the token is not found, returns [model.ErrResetPasswordTokenNotFound] 22 + // If token if used, or expired, returns [model.ErrResetPasswordTokenAlreadyUsed], 23 + // or [models.ErrResetPasswordTokenExpired]. 18 24 GetUserIDByTokenAndMarkAsUsed( 19 25 ctx context.Context, 20 26 token string,
M
internal/store/psql/sessionrepo/sessionrepo.go
··· 13 13 ) 14 14 15 15 type SessionStorer interface { 16 + // Set creates new session associated with user. 16 17 Set(ctx context.Context, usedID uuid.UUID, refreshToken string, expiresAt time.Time) error 18 + 19 + // GetUserIDByRefreshToken returns user ID associated with the refresh token. 17 20 GetUserIDByRefreshToken(ctx context.Context, refreshToken string) (uuid.UUID, error) 21 + 22 + // Update updates refresh token with newer. 18 23 Update(ctx context.Context, userID uuid.UUID, refreshToken string, newRefreshToken string) error 24 + 25 + // Delete deletes session by user ID and their refresh token. 19 26 Delete(ctx context.Context, userID uuid.UUID, refreshToken string) error 27 + 28 + // DeleteAllByUserID deletes all sessions associated with user. 20 29 DeleteAllByUserID(ctx context.Context, userID uuid.UUID) error 21 30 } 22 31
M
internal/store/psql/userepo/userepo.go
··· 12 12 ) 13 13 14 14 type UserStorer interface { 15 + // Create creates a new user. 15 16 Create(ctx context.Context, inp models.User) (uuid.UUID, error) 16 17 17 18 // GetByEmail returns user by email and password 18 - // the password should be hashed 19 + // the password should be hashed. 19 20 GetByEmail(ctx context.Context, email string) (models.User, error) 20 - GetUserIDByEmail(ctx context.Context, email string) (uuid.UUID, error) 21 + 22 + // GetByID returns user by id. 23 + // If user not found, returns [models.ErrUserNotFound]. 21 24 GetByID(ctx context.Context, userID uuid.UUID) (models.User, error) 22 25 26 + // GetUserIDByEmail returns user id that is associated with their email. 27 + // If user not found, returns [models.ErrUserNotFound]. 28 + GetUserIDByEmail(ctx context.Context, email string) (uuid.UUID, error) 29 + 30 + // MakrUserAsActivated marks user as activated by their id 23 31 MarkUserAsActivated(ctx context.Context, id uuid.UUID) error 24 32 25 33 // ChangePassword changes user password from oldPassword to newPassword
M
internal/transport/http/middlewares.go
··· 11 11 func (t *Transport) corsMiddleware() gin.HandlerFunc { 12 12 return cors.New(cors.Config{ 13 13 AllowOrigins: t.corsAllowedOrigins, 14 - AllowMethods: []string{"GET", "POST", "PUT", "DELETE"}, 14 + AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"}, 15 15 AllowHeaders: []string{"Authorization", "Content-Type"}, 16 16 AllowCredentials: true, 17 17 MaxAge: t.corsMaxAge,