diff --git a/api/v1/authentication.go b/api/v1/authentication.go index b7459eb..9747f4d 100644 --- a/api/v1/authentication.go +++ b/api/v1/authentication.go @@ -197,7 +197,7 @@ func (s *Server) signupAuth() http.HandlerFunc { w.WriteHeader(http.StatusUnauthorized) } - err = s.mailer.SendVerMail(&newUser, s.templates) + err = s.mailer.SendVerMail(&newUser, s.domain, s.templates) if err != nil { span.RecordError(err) span.SetStatus(codes.Error, err.Error()) @@ -389,7 +389,7 @@ func (s *Server) resendVer() http.HandlerFunc { } user.VerificationCode = utils.RandomString(6) user.ExpirationTime = time.Now().Add(time.Minute * 5) - err = s.mailer.SendVerMail(user, s.templates) + err = s.mailer.SendVerMail(user, s.domain, s.templates) if err != nil { span.RecordError(err) span.SetStatus(codes.Error, err.Error()) diff --git a/api/v1/mailservice.go b/api/v1/mailservice.go index 6b44025..9d110bc 100644 --- a/api/v1/mailservice.go +++ b/api/v1/mailservice.go @@ -7,6 +7,6 @@ import ( // interface for Mailerservice for Verification-Mail and Reset-PW-Mail type Mailerservice interface { - SendVerMail(*model.User, *templates.TemplateHandler) error + SendVerMail(*model.User, string, *templates.TemplateHandler) error SendPWMail(*model.User, *templates.TemplateHandler) error } diff --git a/internal/mailer/mailer.go b/internal/mailer/mailer.go index 9f37561..bb4671e 100644 --- a/internal/mailer/mailer.go +++ b/internal/mailer/mailer.go @@ -29,9 +29,20 @@ func NewMailer( } } -func (m *Mailer) SendVerMail(user *model.User, tmpl *templates.TemplateHandler) error { +type data struct { + User *model.User + Domain string +} + +func (m *Mailer) SendVerMail(user *model.User, domain string, tmpl *templates.TemplateHandler) error { var body bytes.Buffer - err := tmpl.TmplVerMail.Execute(&body, user) + + data := &data{ + User: user, + Domain: domain, + } + + err := tmpl.TmplVerMail.Execute(&body, data) if err != nil { return err } diff --git a/internal/templates/auth/verMail.html b/internal/templates/auth/verMail.html index acf0bf3..53017fd 100644 --- a/internal/templates/auth/verMail.html +++ b/internal/templates/auth/verMail.html @@ -12,9 +12,9 @@ - Hello {{ .Name }}, this is your verification code: {{ .VerificationCode }} - Please enter your code here: - Link to Verification-Website + Hello {{ .User.Name }}, this is your verification code: {{ + .User.VerificationCode }} Please enter your code here: + Link to Verification-Website diff --git a/testdata/user.json b/testdata/user.json index 2751d35..4648d04 100644 --- a/testdata/user.json +++ b/testdata/user.json @@ -87,6 +87,17 @@ "verificationstring": "I3CLM5", "expirationtime": "2024-02-04T18:19:16.594647087+01:00" }, + "4a1bbf5c-7a12-4eeb-a0e7-1313d6ba2e76": { + "id": "4a1bbf5c-7a12-4eeb-a0e7-1313d6ba2e76", + "email": "application@kndlive.de", + "name": "Peter Müller", + "password": "JDJhJDE0JHVJOGJqeUVSZE83Z25QellLWTg4M3UwRW9Va3BWSTBBbFdqa1NKUy5PWUt0WklCYlZVeHVh", + "entry": null, + "isadmin": false, + "isverified": false, + "verificationstring": "WInRYn", + "expirationtime": "2024-05-09T03:13:09.349586735+02:00" + }, "51ae2a29-8c8e-407c-8c64-072d24d5f24e": { "id": "51ae2a29-8c8e-407c-8c64-072d24d5f24e", "email": "mailer@officus.com", @@ -175,6 +186,17 @@ "verificationstring": "lcSNUT", "expirationtime": "2024-01-30T12:26:55.151347485+01:00" }, + "9764b678-9ac6-4b68-9270-60bc48fb3649": { + "id": "9764b678-9ac6-4b68-9270-60bc48fb3649", + "email": "application@kndlive.de", + "name": "Peter Müller", + "password": "JDJhJDE0JGd1QW9oQ2RoSG05c1NnVmh5U1FsZHUxRDNEMVU1Q0NzOFdPL1UwVWRYQjdhWUZxZXlUS1dh", + "entry": null, + "isadmin": false, + "isverified": false, + "verificationstring": "VCQgOC", + "expirationtime": "2024-05-09T03:11:45.279429377+02:00" + }, "9f9b6a88-a31c-40db-a7a5-c50d4d9966cb": { "id": "9f9b6a88-a31c-40db-a7a5-c50d4d9966cb", "email": "peter@parker.de", @@ -272,5 +294,16 @@ "isverified": false, "verificationstring": "JiclSR", "expirationtime": "2024-02-12T11:05:52.217033949+01:00" + }, + "e6a0d749-e40c-4763-b74c-8b4ae5c48eca": { + "id": "e6a0d749-e40c-4763-b74c-8b4ae5c48eca", + "email": "application@kndlive.de", + "name": "Peter Müller", + "password": "JDJhJDE0JE4ucDJnUC5nRWFLWGJmRTNsb0J6YmVjQlJBN2t1bWc1TWRJMG9NbXdmaGRXOUlzZTNBQ2FL", + "entry": null, + "isadmin": false, + "isverified": false, + "verificationstring": "E3cTtR", + "expirationtime": "2024-05-09T03:12:39.880170541+02:00" } } \ No newline at end of file