diff --git a/auth/auth.go b/auth/auth.go index 796c6bc..4e32030 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -94,18 +94,7 @@ func Verify(c *gin.Context, email string) error { cache := utils.GetCacheFromContext(c) code := generateCode(c, cache, email) - provider := channel.SystemInstance.GetMail() - - type Temp struct { - Code string `json:"code"` - } - - return provider.RenderMail( - "code.html", - Temp{Code: code}, - email, - "Chat Nio | OTP Verification", - ) + return channel.SystemInstance.SendVerifyMail(email, code) } func SignUp(c *gin.Context, form RegisterForm) (string, error) { diff --git a/channel/system.go b/channel/system.go index 9379769..1c104db 100644 --- a/channel/system.go +++ b/channel/system.go @@ -2,7 +2,9 @@ package channel import ( "chat/utils" + "fmt" "github.com/spf13/viper" + "strings" ) type ApiInfo struct { @@ -83,6 +85,21 @@ func (c *SystemConfig) GetMail() *utils.SmtpPoster { ) } +func (c *SystemConfig) SendVerifyMail(email string, code string) error { + type Temp struct { + Title string `json:"title"` + Logo string `json:"logo"` + Code string `json:"code"` + } + + return c.GetMail().RenderMail( + "code.html", + Temp{Title: c.GetAppName(), Logo: c.GetAppLogo(), Code: code}, + email, + fmt.Sprintf("%s | OTP Verification", c.GetAppName()), + ) +} + func (c *SystemConfig) GetSearchEndpoint() string { if len(c.Search.Endpoint) == 0 { return "https://duckduckgo-api.vercel.app" @@ -98,3 +115,21 @@ func (c *SystemConfig) GetSearchQuery() int { return c.Search.Query } + +func (c *SystemConfig) GetAppName() string { + title := strings.TrimSpace(c.General.Title) + if len(title) == 0 { + return "Chat Nio" + } + + return title +} + +func (c *SystemConfig) GetAppLogo() string { + logo := strings.TrimSpace(c.General.Logo) + if len(logo) == 0 { + return "https://chatnio.net/favicon.ico" + } + + return logo +} diff --git a/utils/templates/code.html b/utils/templates/code.html index b0d9dde..85eeb1a 100644 --- a/utils/templates/code.html +++ b/utils/templates/code.html @@ -38,7 +38,7 @@
-

Chat Nio

+

{{.Title}}

Your One-Time Password is {{.Code}}

The code will expire in 10 minutes.
@@ -46,7 +46,7 @@

- © Chat Nio + © {{.Title}}
\ No newline at end of file