-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ba1cca0
commit 6d565c2
Showing
6 changed files
with
256 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,52 @@ | ||
package sendemail | ||
|
||
import ( | ||
"bytes" | ||
"embed" | ||
_ "embed" | ||
"html/template" | ||
|
||
"github.com/Masterminds/sprig/v3" | ||
) | ||
|
||
type EmailTemplateType string | ||
|
||
const ( | ||
PasswordResetTemplate EmailTemplateType = "reset-password.html" | ||
UserInviteTemplate EmailTemplateType = "invite-user.html" | ||
) | ||
|
||
const ( | ||
PasswordResetEmailSubject = "Deepfence - Reset Password" | ||
UserInviteEmailSubject = "Deepfence - Invitation to join %s" | ||
) | ||
|
||
var ( | ||
PasswordResetEmail = "Hello %s %s, \n\nPlease click here to reset your Deepfence ThreatMapper password: %s (Link valid for %d minutes)\n" | ||
//go:embed templates/*.html | ||
emailTemplatesContent embed.FS | ||
|
||
UserInviteEmail = "Hello, \n\nYou have been invited to join Deepfence ThreatMapper by %s %s (%s). \nPlease click here to register: %s\n" | ||
EmailTemplates = template.Must( | ||
template.New("").Funcs(sprig.FuncMap()).ParseFS(emailTemplatesContent, []string{"templates/*.html"}...)) | ||
) | ||
|
||
type PasswordReset struct { | ||
Project string | ||
Username string | ||
InviteLink string | ||
} | ||
|
||
type UserInvite struct { | ||
Project string | ||
Username string | ||
RequestedBy string | ||
InviteLink string | ||
} | ||
|
||
func RenderEmailTemplate(emailTemplateType EmailTemplateType, data interface{}) (string, error) { | ||
var rendered bytes.Buffer | ||
err := EmailTemplates.ExecuteTemplate(&rendered, string(emailTemplateType), data) | ||
if err != nil { | ||
return "", err | ||
} | ||
return rendered.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html lang="en"> | ||
<head data-id="__react-email-head"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<style> | ||
@font-face { | ||
font-family: 'Arial'; | ||
font-style: normal; | ||
font-weight: 400; | ||
mso-font-alt: 'Helvetica'; | ||
|
||
} | ||
|
||
* { | ||
font-family: 'Arial', Helvetica; | ||
} | ||
</style> | ||
</head> | ||
<div id="__react-email-preview" style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0"> | ||
Join Deepfence {{.Project}} | ||
<div> | ||
| ||
</div> | ||
</div> | ||
<body data-id="__react-email-body" style="background-color:rgb(255,255,255)"> | ||
<table align="center" width="100%" data-id="__react-email-container" role="presentation" cellSpacing="0" cellPadding="0" | ||
border="0" style="max-width:37.5em;margin-top:40px;margin-bottom:40px;padding:20px"> | ||
<tbody> | ||
<tr style="width:100%"> | ||
<td> | ||
<table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" | ||
role="presentation" style="margin-top:32px"> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<table align="center" width="100%" data-id="react-email-row" role="presentation" cellSpacing="0" | ||
cellPadding="0" border="0"> | ||
<tbody style="width:100%"> | ||
<tr style="width:100%"> | ||
<td align="right" data-id="__react-email-column" style="width:44%"><img | ||
data-id="react-email-img" alt="Deepfence Logo" | ||
src="https://deepfence-public.s3.amazonaws.com/deepfence-logo-58-38.png" | ||
style="display:block;outline:none;border:none;text-decoration:none"/></td> | ||
<td align="left" data-id="__react-email-column"><p data-id="react-email-text" | ||
style="font-size:22px;line-height:1;margin:16px 0;color:rgb(0,0,0);font-weight:400"> | ||
Deepfence</p></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<p data-id="react-email-text" | ||
style="font-size:14px;line-height:24px;margin:16px 0;color:rgb(0,0,0);font-weight:400">Hello | ||
{{.Username}},</p> | ||
<p data-id="react-email-text" | ||
style="font-size:14px;line-height:24px;margin:16px 0;color:rgb(0,0,0);font-weight:400">You have been | ||
invited to join Deepfence <strong>{{.Project}}</strong> by {{.RequestedBy}} (<a | ||
href="mailto:{{.RequestedByEmail}}" data-id="react-email-link" target="_blank" | ||
style="color:rgb(28,100,242);text-decoration:none;text-decoration-line:none">{{.RequestedByEmail}}</a>). | ||
</p> | ||
<table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" | ||
role="presentation" style="text-align:center;margin-top:24px;margin-bottom:24px"> | ||
<tbody> | ||
<tr> | ||
<td><a href="{{.InviteLink}}" data-id="react-email-button" target="_blank" | ||
style="line-height:16px;text-decoration:none;display:inline-block;max-width:100%;padding:0px 0px;background-color:rgb(12,167,255);padding-left:0.75rem;padding-right:0.75rem;padding-top:0.625rem;padding-bottom:0.625rem;font-size:11px;letter-spacing:0.1em;font-weight:800;color:rgb(255,255,255);border-radius:0.25rem;text-transform:uppercase"><span></span><span | ||
style="max-width:100%;display:inline-block;line-height:120%;mso-padding-alt:0px;mso-text-raise:0">Join the team</span><span></span></a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<p data-id="react-email-text" | ||
style="font-size:14px;line-height:24px;margin:0px;color:rgb(0,0,0);font-weight:400">or copy and paste | ||
this URL into your browser: </p><a href="{{.InviteLink}}" data-id="react-email-link" target="_blank" | ||
style="color:rgb(28,100,242);text-decoration:none;font-size:14px;line-height:24px;font-weight:400;text-decoration-line:none">{{.InviteLink}}</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |
82 changes: 82 additions & 0 deletions
82
deepfence_server/pkg/sendemail/templates/reset-password.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html lang="en"> | ||
<head data-id="__react-email-head"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<style> | ||
@font-face { | ||
font-family: 'Arial'; | ||
font-style: normal; | ||
font-weight: 400; | ||
mso-font-alt: 'Helvetica'; | ||
|
||
} | ||
|
||
* { | ||
font-family: 'Arial', Helvetica; | ||
} | ||
</style> | ||
</head> | ||
<div id="__react-email-preview" style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0"> | ||
Password reset - Deepfence {{.Project}} | ||
<div> | ||
| ||
</div> | ||
</div> | ||
<body data-id="__react-email-body" style="background-color:rgb(255,255,255)"> | ||
<table align="center" width="100%" data-id="__react-email-container" role="presentation" cellSpacing="0" cellPadding="0" | ||
border="0" | ||
style="max-width:37.5em;margin-top:40px;margin-bottom:40px;margin-left:auto;margin-right:auto;padding:20px"> | ||
<tbody> | ||
<tr style="width:100%"> | ||
<td> | ||
<table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" | ||
role="presentation" style="margin-top:32px"> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<table align="center" width="100%" data-id="react-email-row" role="presentation" cellSpacing="0" | ||
cellPadding="0" border="0"> | ||
<tbody style="width:100%"> | ||
<tr style="width:100%"> | ||
<td align="right" data-id="__react-email-column" style="width:44%"><img | ||
data-id="react-email-img" alt="Deepfence Logo" | ||
src="https://deepfence-public.s3.amazonaws.com/deepfence-logo-58-38.png" | ||
style="display:block;outline:none;border:none;text-decoration:none"/></td> | ||
<td align="left" data-id="__react-email-column"><p data-id="react-email-text" | ||
style="font-size:22px;line-height:1;margin:16px 0;color:rgb(0,0,0);font-weight:400"> | ||
Deepfence</p></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<p data-id="react-email-text" | ||
style="font-size:14px;line-height:24px;margin:16px 0;color:rgb(0,0,0);font-weight:400">Hello | ||
{{.Username}},</p> | ||
<p data-id="react-email-text" | ||
style="font-size:14px;line-height:24px;margin:16px 0;color:rgb(0,0,0);font-weight:400">If you wish to | ||
reset your Deepfence <strong>{{.Project}}</strong> password, click the button below:</p> | ||
<table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" | ||
role="presentation" style="text-align:center;margin-top:24px;margin-bottom:24px"> | ||
<tbody> | ||
<tr> | ||
<td><a href="{{.InviteLink}}" data-id="react-email-button" target="_blank" | ||
style="line-height:16px;text-decoration:none;display:inline-block;max-width:100%;padding:0px 0px;background-color:rgb(12,167,255);padding-left:0.75rem;padding-right:0.75rem;padding-top:0.625rem;padding-bottom:0.625rem;font-size:11px;letter-spacing:0.1em;font-weight:800;color:rgb(255,255,255);border-radius:0.25rem;text-transform:uppercase"><span></span><span | ||
style="max-width:100%;display:inline-block;line-height:120%;mso-padding-alt:0px;mso-text-raise:0">Reset password</span><span></span></a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<p data-id="react-email-text" | ||
style="font-size:14px;line-height:24px;margin:0px;color:rgb(0,0,0);font-weight:400">or copy and paste | ||
this URL into your browser: </p><a href="{{.InviteLink}}" data-id="react-email-link" target="_blank" | ||
style="color:rgb(28,100,242);text-decoration:none;font-size:14px;line-height:24px;font-weight:400;text-decoration-line:none">{{.InviteLink}}</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters