mirror of https://github.com/h44z/wg-portal.git
				
				
				
			use website title in mail templates (#448)
This commit is contained in:
		
							parent
							
								
									3a732fd3e5
								
							
						
					
					
						commit
						3aa94aa7ad
					
				|  | @ -71,7 +71,7 @@ func NewMailManager( | ||||||
| 	users UserDatabaseRepo, | 	users UserDatabaseRepo, | ||||||
| 	wg WireguardDatabaseRepo, | 	wg WireguardDatabaseRepo, | ||||||
| ) (*Manager, error) { | ) (*Manager, error) { | ||||||
| 	tplHandler, err := newTemplateHandler(cfg.Web.ExternalUrl) | 	tplHandler, err := newTemplateHandler(cfg.Web.ExternalUrl, cfg.Web.SiteTitle) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("failed to initialize template handler: %w", err) | 		return nil, fmt.Errorf("failed to initialize template handler: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -17,11 +17,12 @@ var TemplateFiles embed.FS | ||||||
| // TemplateHandler is a struct that holds the html and text templates.
 | // TemplateHandler is a struct that holds the html and text templates.
 | ||||||
| type TemplateHandler struct { | type TemplateHandler struct { | ||||||
| 	portalUrl     string | 	portalUrl     string | ||||||
|  | 	portalName    string | ||||||
| 	htmlTemplates *htmlTemplate.Template | 	htmlTemplates *htmlTemplate.Template | ||||||
| 	textTemplates *template.Template | 	textTemplates *template.Template | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func newTemplateHandler(portalUrl string) (*TemplateHandler, error) { | func newTemplateHandler(portalUrl, portalName string) (*TemplateHandler, error) { | ||||||
| 	htmlTemplateCache, err := htmlTemplate.New("Html").ParseFS(TemplateFiles, "tpl_files/*.gohtml") | 	htmlTemplateCache, err := htmlTemplate.New("Html").ParseFS(TemplateFiles, "tpl_files/*.gohtml") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("failed to parse html template files: %w", err) | 		return nil, fmt.Errorf("failed to parse html template files: %w", err) | ||||||
|  | @ -34,6 +35,7 @@ func newTemplateHandler(portalUrl string) (*TemplateHandler, error) { | ||||||
| 
 | 
 | ||||||
| 	handler := &TemplateHandler{ | 	handler := &TemplateHandler{ | ||||||
| 		portalUrl:     portalUrl, | 		portalUrl:     portalUrl, | ||||||
|  | 		portalName:    portalName, | ||||||
| 		htmlTemplates: htmlTemplateCache, | 		htmlTemplates: htmlTemplateCache, | ||||||
| 		textTemplates: txtTemplateCache, | 		textTemplates: txtTemplateCache, | ||||||
| 	} | 	} | ||||||
|  | @ -81,6 +83,7 @@ func (c TemplateHandler) GetConfigMailWithAttachment(user *domain.User, cfgName, | ||||||
| 		"ConfigFileName": cfgName, | 		"ConfigFileName": cfgName, | ||||||
| 		"QrcodePngName":  qrName, | 		"QrcodePngName":  qrName, | ||||||
| 		"PortalUrl":      c.portalUrl, | 		"PortalUrl":      c.portalUrl, | ||||||
|  | 		"PortalName":     c.portalName, | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, nil, fmt.Errorf("failed to execute template mail_with_attachment.gotpl: %w", err) | 		return nil, nil, fmt.Errorf("failed to execute template mail_with_attachment.gotpl: %w", err) | ||||||
|  | @ -91,6 +94,7 @@ func (c TemplateHandler) GetConfigMailWithAttachment(user *domain.User, cfgName, | ||||||
| 		"ConfigFileName": cfgName, | 		"ConfigFileName": cfgName, | ||||||
| 		"QrcodePngName":  qrName, | 		"QrcodePngName":  qrName, | ||||||
| 		"PortalUrl":      c.portalUrl, | 		"PortalUrl":      c.portalUrl, | ||||||
|  | 		"PortalName":     c.portalName, | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, nil, fmt.Errorf("failed to execute template mail_with_attachment.gohtml: %w", err) | 		return nil, nil, fmt.Errorf("failed to execute template mail_with_attachment.gohtml: %w", err) | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ | ||||||
|     <!--[if !mso]><!--> |     <!--[if !mso]><!--> | ||||||
|     <link href="https://fonts.googleapis.com/css?family=Muli:400,400i,700,700i" rel="stylesheet" /> |     <link href="https://fonts.googleapis.com/css?family=Muli:400,400i,700,700i" rel="stylesheet" /> | ||||||
|     <!--<![endif]--> |     <!--<![endif]--> | ||||||
|     <title>Email Template</title> |     <title>{{$.PortalName}}</title> | ||||||
|     <!--[if gte mso 9]> |     <!--[if gte mso 9]> | ||||||
|     <style type="text/css" media="all"> |     <style type="text/css" media="all"> | ||||||
|         sup { font-size: 100% !important; } |         sup { font-size: 100% !important; } | ||||||
|  | @ -167,10 +167,10 @@ | ||||||
|                                 <td class="p30-15 bbrr" style="padding: 50px 30px; border-radius:0px 0px 26px 26px;" bgcolor="#ffffff"> |                                 <td class="p30-15 bbrr" style="padding: 50px 30px; border-radius:0px 0px 26px 26px;" bgcolor="#ffffff"> | ||||||
|                                     <table width="100%" border="0" cellspacing="0" cellpadding="0"> |                                     <table width="100%" border="0" cellspacing="0" cellpadding="0"> | ||||||
|                                         <tr> |                                         <tr> | ||||||
|                                             <td class="text-footer1 pb10" style="color:#000000; font-family:'Muli', Arial,sans-serif; font-size:16px; line-height:20px; text-align:center; padding-bottom:10px;">This mail was generated using WireGuard Portal.</td> |                                             <td class="text-footer1 pb10" style="color:#000000; font-family:'Muli', Arial,sans-serif; font-size:16px; line-height:20px; text-align:center; padding-bottom:10px;">This mail was generated by {{$.PortalName}}.</td> | ||||||
|                                         </tr> |                                         </tr> | ||||||
|                                         <tr> |                                         <tr> | ||||||
|                                             <td class="text-footer2" style="color:#000000; font-family:'Muli', Arial,sans-serif; font-size:12px; line-height:26px; text-align:center;"><a href="{{$.PortalUrl}}" target="_blank" rel="noopener noreferrer" class="link" style="color:#000000; text-decoration:none;"><span class="link" style="color:#000000; text-decoration:none;">Visit WireGuard Portal</span></a></td> |                                             <td class="text-footer2" style="color:#000000; font-family:'Muli', Arial,sans-serif; font-size:12px; line-height:26px; text-align:center;"><a href="{{$.PortalUrl}}" target="_blank" rel="noopener noreferrer" class="link" style="color:#000000; text-decoration:none;"><span class="link" style="color:#000000; text-decoration:none;">Visit {{$.PortalName}}</span></a></td> | ||||||
|                                         </tr> |                                         </tr> | ||||||
|                                     </table> |                                     </table> | ||||||
|                                 </td> |                                 </td> | ||||||
|  |  | ||||||
|  | @ -20,5 +20,5 @@ You can download and install the WireGuard VPN client from: | ||||||
| https://www.wireguard.com/install/ | https://www.wireguard.com/install/ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| This mail was generated using WireGuard Portal. | This mail was generated by {{$.PortalName}}. | ||||||
| {{$.PortalUrl}} | {{$.PortalUrl}} | ||||||
|  | @ -19,7 +19,7 @@ | ||||||
|     <!--[if !mso]><!--> |     <!--[if !mso]><!--> | ||||||
|     <link href="https://fonts.googleapis.com/css?family=Muli:400,400i,700,700i" rel="stylesheet" /> |     <link href="https://fonts.googleapis.com/css?family=Muli:400,400i,700,700i" rel="stylesheet" /> | ||||||
|     <!--<![endif]--> |     <!--<![endif]--> | ||||||
|     <title>Email Template</title> |     <title>{{$.PortalName}}</title> | ||||||
|     <!--[if gte mso 9]> |     <!--[if gte mso 9]> | ||||||
|     <style type="text/css" media="all"> |     <style type="text/css" media="all"> | ||||||
|         sup { font-size: 100% !important; } |         sup { font-size: 100% !important; } | ||||||
|  | @ -167,10 +167,10 @@ | ||||||
|                                 <td class="p30-15 bbrr" style="padding: 50px 30px; border-radius:0px 0px 26px 26px;" bgcolor="#ffffff"> |                                 <td class="p30-15 bbrr" style="padding: 50px 30px; border-radius:0px 0px 26px 26px;" bgcolor="#ffffff"> | ||||||
|                                     <table width="100%" border="0" cellspacing="0" cellpadding="0"> |                                     <table width="100%" border="0" cellspacing="0" cellpadding="0"> | ||||||
|                                         <tr> |                                         <tr> | ||||||
|                                             <td class="text-footer1 pb10" style="color:#000000; font-family:'Muli', Arial,sans-serif; font-size:16px; line-height:20px; text-align:center; padding-bottom:10px;">This mail was generated using WireGuard Portal.</td> |                                             <td class="text-footer1 pb10" style="color:#000000; font-family:'Muli', Arial,sans-serif; font-size:16px; line-height:20px; text-align:center; padding-bottom:10px;">This mail was generated by {{$.PortalName}}.</td> | ||||||
|                                         </tr> |                                         </tr> | ||||||
|                                         <tr> |                                         <tr> | ||||||
|                                             <td class="text-footer2" style="color:#000000; font-family:'Muli', Arial,sans-serif; font-size:12px; line-height:26px; text-align:center;"><a href="{{$.PortalUrl}}" target="_blank" rel="noopener noreferrer" class="link" style="color:#000000; text-decoration:none;"><span class="link" style="color:#000000; text-decoration:none;">Visit WireGuard Portal</span></a></td> |                                             <td class="text-footer2" style="color:#000000; font-family:'Muli', Arial,sans-serif; font-size:12px; line-height:26px; text-align:center;"><a href="{{$.PortalUrl}}" target="_blank" rel="noopener noreferrer" class="link" style="color:#000000; text-decoration:none;"><span class="link" style="color:#000000; text-decoration:none;">Visit {{$.PortalName}}</span></a></td> | ||||||
|                                         </tr> |                                         </tr> | ||||||
|                                     </table> |                                     </table> | ||||||
|                                 </td> |                                 </td> | ||||||
|  |  | ||||||
|  | @ -20,5 +20,5 @@ You can download and install the WireGuard VPN client from: | ||||||
| https://www.wireguard.com/install/ | https://www.wireguard.com/install/ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| This mail was generated using WireGuard Portal. | This mail was generated by {{$.PortalName}}. | ||||||
| {{$.PortalUrl}} | {{$.PortalUrl}} | ||||||
		Loading…
	
		Reference in New Issue