Skip to content

Commit

Permalink
- fix send mail verify API
Browse files Browse the repository at this point in the history
  • Loading branch information
le-xuan-quynh committed May 4, 2022
1 parent 33f2ada commit 6247d09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/authorization/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,6 @@ func MakeGetVerifyMailCodeEndpoint(svc authorization.Service) endpoint.Endpoint
if err != nil {
return nil, err
}
return "successfully mailed verification code. Please check your email.", nil
return "Email has been successfully verified", nil
}
}
14 changes: 10 additions & 4 deletions pkg/authorization/users-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s *userService) VerifyMail(ctx context.Context, request *VerifyMailRequest
return "Email has been successfully verified.", nil
}
// Get limit data
limitData, err := s.repo.GetLimitData(ctx, user.ID, database.LimitTypeLogin)
limitData, err := s.repo.GetLimitData(ctx, user.ID, database.LimitTypeSendVerifyMail)
if err != nil {
s.logger.Error("Empty row get limit data", "error", err)
}
Expand All @@ -142,7 +142,7 @@ func (s *userService) VerifyMail(ctx context.Context, request *VerifyMailRequest
return cusErr.Error(), cusErr
}
// Update limit data
err = s.repo.InsertOrUpdateLimitData(ctx, limitData, database.LimitTypeLogin)
err = s.repo.InsertOrUpdateLimitData(ctx, limitData, database.LimitTypeSendVerifyMail)
if err != nil {
s.logger.Error("Cannot insert or update limit data", "error", err)
cusErr := utils.NewErrorResponse(utils.InternalServerError)
Expand Down Expand Up @@ -181,8 +181,8 @@ func (s *userService) VerifyMail(ctx context.Context, request *VerifyMailRequest
return cusErr.Error(), cusErr
}
// Reset limit data
limitData.NumOfLogin = 0
err = s.repo.InsertOrUpdateLimitData(ctx, limitData, database.LimitTypeLogin)
limitData.NumOfSendMailVerify = 0
err = s.repo.InsertOrUpdateLimitData(ctx, limitData, database.LimitTypeSendVerifyMail)
if err != nil {
s.logger.Error("Cannot reset number of login", "error", err)
cusErr := utils.NewErrorResponse(utils.InternalServerError)
Expand Down Expand Up @@ -315,6 +315,7 @@ func (s *userService) Logout(ctx context.Context, request *LogoutRequest) error
user.TokenHash = utils.GenerateRandomString(15)
// Generate refreshToken
refreshToken, err := s.auth.GenerateRefreshToken(user)

if err != nil {
s.logger.Error("Error generating refreshToken", "error", err)
cusErr := utils.NewErrorResponse(utils.InternalServerError)
Expand Down Expand Up @@ -847,6 +848,11 @@ func (s *userService) GetVerifyMailCode(ctx context.Context) error {
cusErr := utils.NewErrorResponse(utils.Forbidden)
return cusErr
}
// Check if user is verified
if user.Verified {
s.logger.Error("Email has been successfully verified")
return nil
}
// Get limit data
limitData, err := s.repo.GetLimitData(ctx, user.ID, database.LimitTypeSendVerifyMail)
if err != nil {
Expand Down

0 comments on commit 6247d09

Please sign in to comment.