Skip to content

Commit

Permalink
update email form render
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Jan 3, 2024
1 parent 4efd0e8 commit 11a4f3d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
13 changes: 1 addition & 12 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 35 additions & 0 deletions channel/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package channel

import (
"chat/utils"
"fmt"
"github.com/spf13/viper"
"strings"
)

type ApiInfo struct {
Expand Down Expand Up @@ -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"
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions utils/templates/code.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
</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>
<span>If it is not operated by yourself, please ignore it.</span><br>
</div>
<br>
<div class="column">
<a href="">&copy; Chat Nio</a>
<a href="">&copy; {{.Title}}</a>
</div>
</div>
</body>

0 comments on commit 11a4f3d

Please sign in to comment.