update email form render

This commit is contained in:
Zhang Minghan 2024-01-03 13:35:40 +08:00
parent 4efd0e8928
commit 11a4f3dd2f
3 changed files with 38 additions and 14 deletions

View File

@ -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) {

View File

@ -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
}

View File

@ -38,7 +38,7 @@
</style>
<body>
<div class="main">
<div class="column"><img src="https://chatnio.net/favicon.ico" alt=""><h1>Chat Nio</h1></div>
<div class="column"><img src="{{.Logo}}" alt=""><h1>{{.Title}}</h1></div>
<div class="column"><p>Your One-Time Password is <strong class="code">{{.Code}}</strong></p></div>
<div class="column" style="color:gray">
<span>The code will expire in <strong>10 minutes</strong>.</span><br>
@ -46,7 +46,7 @@
</div>
<br>
<div class="column">
<a href="">&copy; Chat Nio</a>
<a href="">&copy; {{.Title}}</a>
</div>
</div>
</body>