From 302150aa6e00981d69165ee1de4fa00f0d8f88ae Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Mon, 31 Oct 2022 16:50:38 +0800 Subject: [PATCH] update user change email --- internal/service/user_service.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/service/user_service.go b/internal/service/user_service.go index 071bbe88..10befdab 100644 --- a/internal/service/user_service.go +++ b/internal/service/user_service.go @@ -492,7 +492,7 @@ func (us *UserService) encryptPassword(ctx context.Context, Pass string) (string // UserChangeEmailSendCode user change email verification func (us *UserService) UserChangeEmailSendCode(ctx context.Context, req *schema.UserChangeEmailSendCodeReq) error { - _, exist, err := us.userRepo.GetByUserID(ctx, req.UserID) + userInfo, exist, err := us.userRepo.GetByUserID(ctx, req.UserID) if err != nil { return err } @@ -513,10 +513,15 @@ func (us *UserService) UserChangeEmailSendCode(ctx context.Context, req *schema. UserID: req.UserID, } code := uuid.NewString() + var title, body string verifyEmailUrl := fmt.Sprintf("%s/users/confirm-new-email?code=%s", us.serviceConfig.WebHost, code) - title, body, err := us.emailService.ChangeEmailTemplate(ctx, verifyEmailUrl) - if err != nil { - return err + if userInfo.MailStatus == entity.EmailStatusToBeVerified { + title, body, err = us.emailService.RegisterTemplate(ctx, verifyEmailUrl) + } else { + title, body, err = us.emailService.ChangeEmailTemplate(ctx, verifyEmailUrl) + if err != nil { + return err + } } log.Infof("send email confirmation %s", verifyEmailUrl)