From 26483533a904e39baca6680672ec6c65536135af Mon Sep 17 00:00:00 2001 From: bjdgyc <bjdgyc@163.com> Date: Fri, 29 Mar 2024 10:04:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=85=B3=E9=97=ADotp?= =?UTF-8?q?=E6=97=B6,=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/admin/api_user.go | 20 ++++++++++++++------ server/dbdata/db.go | 14 +++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/server/admin/api_user.go b/server/admin/api_user.go index c38214c..bad7d38 100644 --- a/server/admin/api_user.go +++ b/server/admin/api_user.go @@ -214,6 +214,7 @@ type userAccountMailData struct { PinCode string OtpImg string OtpImgBase64 string + DisableOtp bool } func userAccountMail(user *dbdata.User) error { @@ -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) @@ -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) diff --git a/server/dbdata/db.go b/server/dbdata/db.go index 7d643a3..c59d661 100644 --- a/server/dbdata/db.go +++ b/server/dbdata/db.go @@ -174,6 +174,9 @@ func CheckErrNotFound(err error) bool { return err == ErrNotFound } +// base64 图片 +// 用户动态码(请妥善保存):<br/> +// <img src="{{.OtpImgBase64}}"/><br/> const accountMail = `<p>您好:</p> <p> 您的{{.Issuer}}账号已经审核开通。</p> <p> @@ -181,17 +184,18 @@ const accountMail = `<p>您好:</p> 用户组: <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> 使用说明: