修复 关闭otp时,发送邮件附件的问题

This commit is contained in:
bjdgyc 2024-03-29 10:04:15 +08:00
parent 380a8cb3fb
commit 26483533a9
2 changed files with 23 additions and 11 deletions

View File

@ -214,6 +214,7 @@ type userAccountMailData struct {
PinCode string PinCode string
OtpImg string OtpImg string
OtpImgBase64 string OtpImgBase64 string
DisableOtp bool
} }
func userAccountMail(user *dbdata.User) error { func userAccountMail(user *dbdata.User) error {
@ -265,6 +266,7 @@ func userAccountMail(user *dbdata.User) error {
PinCode: user.PinCode, PinCode: user.PinCode,
OtpImg: fmt.Sprintf("https://%s/otp_qr?id=%d&jwt=%s", setting.LinkAddr, user.Id, tokenString), OtpImg: fmt.Sprintf("https://%s/otp_qr?id=%d&jwt=%s", setting.LinkAddr, user.Id, tokenString),
OtpImgBase64: "data:image/png;base64," + otpData, OtpImgBase64: "data:image/png;base64," + otpData,
DisableOtp: user.DisableOtp,
} }
w := bytes.NewBufferString("") w := bytes.NewBufferString("")
t, _ := template.New("auth_complete").Parse(htmlBody) t, _ := template.New("auth_complete").Parse(htmlBody)
@ -273,12 +275,18 @@ func userAccountMail(user *dbdata.User) error {
return err return err
} }
// fmt.Println(w.String()) // fmt.Println(w.String())
imgData, _ := userOtpQr(user.Id, false)
attach := &mail.File{ var attach *mail.File
MimeType: "image/png", if user.DisableOtp {
Name: "userOtpQr.png", attach = nil
Data: []byte(imgData), } else {
Inline: true, 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) return SendMail(base.Cfg.Issuer, user.Email, w.String(), attach)

View File

@ -174,6 +174,9 @@ func CheckErrNotFound(err error) bool {
return err == ErrNotFound return err == ErrNotFound
} }
// base64 图片
// 用户动态码(请妥善保存):<br/>
// <img src="{{.OtpImgBase64}}"/><br/>
const accountMail = `<p>您好:</p> const accountMail = `<p>您好:</p>
<p>&nbsp;&nbsp;您的{{.Issuer}}账号已经审核开通</p> <p>&nbsp;&nbsp;您的{{.Issuer}}账号已经审核开通</p>
<p> <p>
@ -181,17 +184,18 @@ const accountMail = `<p>您好:</p>
用户组: <b>{{.Group}}</b> <br/> 用户组: <b>{{.Group}}</b> <br/>
用户名: <b>{{.Username}}</b> <br/> 用户名: <b>{{.Username}}</b> <br/>
用户PIN码: <b>{{.PinCode}}</b> <br/> 用户PIN码: <b>{{.PinCode}}</b> <br/>
{{if .DisableOtp}}
<!-- nothing -->
{{else}}
<!-- <!--
用户动态码(3天后失效):<br/> 用户动态码(3天后失效):<br/>
<img src="{{.OtpImg}}"/><br/> <img src="{{.OtpImg}}"/><br/>
用户动态码(请妥善保存):<br/>
<img src="{{.OtpImgBase64}}"/><br/>
下面是兼容 gmail 的写法
--> -->
用户动态码(请妥善保存):<br/> 用户动态码(请妥善保存):<br/>
<img src="cid:userOtpQr.png" alt="userOtpQr" /><br/> <img src="cid:userOtpQr.png" alt="userOtpQr" /><br/>
{{end}}
</p> </p>
<div> <div>
使用说明: 使用说明: