diff --git a/internal/web/actions/default/admins/otpQrcode.go b/internal/web/actions/default/admins/otpQrcode.go index 07ae9de7..2688ae16 100644 --- a/internal/web/actions/default/admins/otpQrcode.go +++ b/internal/web/actions/default/admins/otpQrcode.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" + "github.com/iwind/TeaGo/types" "github.com/skip2/go-qrcode" "github.com/xlzd/gotp" ) @@ -20,7 +21,8 @@ func (this *OtpQrcodeAction) Init() { } func (this *OtpQrcodeAction) RunGet(params struct { - AdminId int64 + AdminId int64 + Download bool }) { loginResp, err := this.RPC().LoginRPC().FindEnabledLogin(this.AdminContext(), &pb.FindEnabledLoginRequest{ AdminId: params.AdminId, @@ -63,12 +65,17 @@ func (this *OtpQrcodeAction) RunGet(params struct { } var url = gotp.NewDefaultTOTP(secret).ProvisioningUri(admin.Username, uiConfig.AdminSystemName) - data, err := qrcode.Encode(otputils.FixIssuer(url), qrcode.Medium, 256) if err != nil { this.ErrorPage(err) return } + + if params.Download { + var filename = "OTP-ADMIN-" + admin.Username + ".png" + this.AddHeader("Content-Disposition", "attachment; filename=\""+filename+"\";") + } this.AddHeader("Content-Type", "image/png") + this.AddHeader("Content-Length", types.String(len(data))) _, _ = this.Write(data) } diff --git a/internal/web/actions/default/users/otpQrcode.go b/internal/web/actions/default/users/otpQrcode.go index 45e3ecb4..f4c9c18b 100644 --- a/internal/web/actions/default/users/otpQrcode.go +++ b/internal/web/actions/default/users/otpQrcode.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" + "github.com/iwind/TeaGo/types" "github.com/skip2/go-qrcode" "github.com/xlzd/gotp" ) @@ -20,7 +21,8 @@ func (this *OtpQrcodeAction) Init() { } func (this *OtpQrcodeAction) RunGet(params struct { - UserId int64 + UserId int64 + Download bool }) { loginResp, err := this.RPC().LoginRPC().FindEnabledLogin(this.AdminContext(), &pb.FindEnabledLoginRequest{ UserId: params.UserId, @@ -71,6 +73,11 @@ func (this *OtpQrcodeAction) RunGet(params struct { this.ErrorPage(err) return } + if params.Download { + var filename = "OTP-USER-" + user.Username + ".png" + this.AddHeader("Content-Disposition", "attachment; filename=\""+filename+"\";") + } this.AddHeader("Content-Type", "image/png") + this.AddHeader("Content-Length", types.String(len(data))) _, _ = this.Write(data) } diff --git a/web/views/@default/admins/admin.html b/web/views/@default/admins/admin.html index de044263..cdb696e0 100644 --- a/web/views/@default/admins/admin.html +++ b/web/views/@default/admins/admin.html @@ -64,8 +64,8 @@
可以通过二维码快速添加OTP认证信息到认证App中。
+[下载] 可以通过二维码快速添加OTP认证信息到认证App中。
可以通过二维码快速添加OTP认证信息到认证App中。
+[下载] 可以通过二维码快速添加OTP认证信息到认证App中。