Skip to content

Commit

Permalink
修复 关闭otp时,发送邮件附件的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
bjdgyc committed Mar 29, 2024
1 parent 380a8cb commit 2648353
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
20 changes: 14 additions & 6 deletions server/admin/api_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type userAccountMailData struct {
PinCode string
OtpImg string
OtpImgBase64 string
DisableOtp bool
}

func userAccountMail(user *dbdata.User) error {
Expand Down Expand Up @@ -265,6 +266,7 @@ func userAccountMail(user *dbdata.User) error {
PinCode: user.PinCode,
OtpImg: fmt.Sprintf("https://%s/otp_qr?id=%d&jwt=%s", setting.LinkAddr, user.Id, tokenString),
OtpImgBase64: "data:image/png;base64," + otpData,
DisableOtp: user.DisableOtp,
}
w := bytes.NewBufferString("")
t, _ := template.New("auth_complete").Parse(htmlBody)
Expand All @@ -273,12 +275,18 @@ func userAccountMail(user *dbdata.User) error {
return err
}
// fmt.Println(w.String())
imgData, _ := userOtpQr(user.Id, false)
attach := &mail.File{
MimeType: "image/png",
Name: "userOtpQr.png",
Data: []byte(imgData),
Inline: true,

var attach *mail.File
if user.DisableOtp {
attach = nil
} else {
imgData, _ := userOtpQr(user.Id, false)
attach = &mail.File{
MimeType: "image/png",
Name: "userOtpQr.png",
Data: []byte(imgData),
Inline: true,
}
}

return SendMail(base.Cfg.Issuer, user.Email, w.String(), attach)
Expand Down
14 changes: 9 additions & 5 deletions server/dbdata/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,28 @@ func CheckErrNotFound(err error) bool {
return err == ErrNotFound
}

// base64 图片
// 用户动态码(请妥善保存):<br/>
// <img src="{{.OtpImgBase64}}"/><br/>
const accountMail = `<p>您好:</p>
<p>&nbsp;&nbsp;您的{{.Issuer}}账号已经审核开通。</p>
<p>
登陆地址: <b>{{.LinkAddr}}</b> <br/>
用户组: <b>{{.Group}}</b> <br/>
用户名: <b>{{.Username}}</b> <br/>
用户PIN码: <b>{{.PinCode}}</b> <br/>
{{if .DisableOtp}}
<!-- nothing -->
{{else}}
<!--
用户动态码(3天后失效):<br/>
<img src="{{.OtpImg}}"/><br/>
用户动态码(请妥善保存):<br/>
<img src="{{.OtpImgBase64}}"/><br/>
下面是兼容 gmail 的写法
-->
用户动态码(请妥善保存):<br/>
<img src="cid:userOtpQr.png" alt="userOtpQr" /><br/>
{{end}}
</p>
<div>
使用说明:
Expand Down

0 comments on commit 2648353

Please sign in to comment.