Skip to content

Commit

Permalink
fix: mailer-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
led0nk committed May 9, 2024
1 parent c3e783c commit 2f5ca59
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/v1/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion api/v1/mailservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 13 additions & 2 deletions internal/mailer/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions internal/templates/auth/verMail.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</head>

<body class="bg-slate-300">
Hello {{ .Name }}, this is your verification code: {{ .VerificationCode }}
Please enter your code here:
<a href="http://127.0.0.1:8080/user/verify">Link to Verification-Website</a>
Hello {{ .User.Name }}, this is your verification code: {{
.User.VerificationCode }} Please enter your code here:
<a href="{{ .Domain }}/user/verify">Link to Verification-Website</a>
</body>

</html>
33 changes: 33 additions & 0 deletions testdata/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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": "[email protected]",
Expand Down Expand Up @@ -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": "[email protected]",
"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": "[email protected]",
Expand Down Expand Up @@ -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": "[email protected]",
"name": "Peter Müller",
"password": "JDJhJDE0JE4ucDJnUC5nRWFLWGJmRTNsb0J6YmVjQlJBN2t1bWc1TWRJMG9NbXdmaGRXOUlzZTNBQ2FL",
"entry": null,
"isadmin": false,
"isverified": false,
"verificationstring": "E3cTtR",
"expirationtime": "2024-05-09T03:12:39.880170541+02:00"
}
}

0 comments on commit 2f5ca59

Please sign in to comment.