From b683e813fe5cbd88a64507f28c0ef593f93ee1fe Mon Sep 17 00:00:00 2001 From: GotPPay Date: Fri, 1 Jun 2018 15:01:37 +0200 Subject: [PATCH] add confirmation email on complete --- .../router/passwordresetroute/controller.go | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/server/router/passwordresetroute/controller.go b/server/router/passwordresetroute/controller.go index ebaaebb..70ea908 100644 --- a/server/router/passwordresetroute/controller.go +++ b/server/router/passwordresetroute/controller.go @@ -16,12 +16,14 @@ import ( ) const ( - tokenExpirationTime = 90 // in minutes - randomStringLength = 15 - baseURL = "http://localhost:5000" - passwordResetEmailSubject = "Reset Your Password" - passwordResetEmailMainBody = "To reset your password click here or copy the following link and paste it into your browser: \n\n " + baseURL + "/#/reset-password/" - passwordResetEmailFooter = "\nThis link expires in 90 minutes" + tokenExpirationTime = 90 // in minutes + randomStringLength = 15 + baseURL = "http://localhost:5000" + passwordResetEmailSubject = "Reset Your Password" + passwordResetEmailMainBody = "To reset your password click here or copy the following link and paste it into your browser: \n\n " + baseURL + "/#/reset-password/" + passwordResetEmailFooter = "\nThis link expires in 90 minutes" + passwordResetCompleteEmailSubject = "Your Password Has been Reset" + passwordResetCompleteEmailBody = "Your password has been reset. To login click here or copy the following link and paste it into your browser: \n\n" + baseURL + "/#/login" ) var ( @@ -88,7 +90,7 @@ func (c *controller) handleResetRequest(ctx echo.Context) error { notification := viewmodel.Notification{ Type: applicationservice.NotificationTypeEmail, From: c.cfg.Email.Sender, - To: "test.test.no@yandex.com", + To: *user.Email, Subject: passwordResetEmailSubject, Message: passwordResetEmailMainBody + token + passwordResetEmailFooter, } @@ -129,11 +131,26 @@ func (c *controller) handleResetComplete(ctx echo.Context) error { fmt.Println(fullUserData) //write new password in database + //TODO if err := c.svc.PasswordReset.SetTokenUsed(userToken); err != nil { routeutils.ResponseAPIPasswordResetFailed(ctx, "Reset failed") } + //Send email with reset link + notification := viewmodel.Notification{ + Type: applicationservice.NotificationTypeEmail, + From: c.cfg.Email.Sender, + To: *user.Email, + Subject: passwordResetCompleteEmailSubject, + Message: passwordResetCompleteEmailBody, + } + + notification, err = c.svc.Notification.SendNotificationWithoutWritingToDatabase(notification) + if err != nil { + return routeutils.HandleAPIError(ctx, err) + } + return routeutils.ResponseAPIOK(ctx, nil) }