mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	OTP认证二维码增加下载链接
This commit is contained in:
		@@ -7,6 +7,7 @@ import (
 | 
				
			|||||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
						"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
				
			||||||
	"github.com/iwind/TeaGo/maps"
 | 
						"github.com/iwind/TeaGo/maps"
 | 
				
			||||||
 | 
						"github.com/iwind/TeaGo/types"
 | 
				
			||||||
	"github.com/skip2/go-qrcode"
 | 
						"github.com/skip2/go-qrcode"
 | 
				
			||||||
	"github.com/xlzd/gotp"
 | 
						"github.com/xlzd/gotp"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -21,6 +22,7 @@ func (this *OtpQrcodeAction) Init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (this *OtpQrcodeAction) RunGet(params struct {
 | 
					func (this *OtpQrcodeAction) RunGet(params struct {
 | 
				
			||||||
	AdminId  int64
 | 
						AdminId  int64
 | 
				
			||||||
 | 
						Download bool
 | 
				
			||||||
}) {
 | 
					}) {
 | 
				
			||||||
	loginResp, err := this.RPC().LoginRPC().FindEnabledLogin(this.AdminContext(), &pb.FindEnabledLoginRequest{
 | 
						loginResp, err := this.RPC().LoginRPC().FindEnabledLogin(this.AdminContext(), &pb.FindEnabledLoginRequest{
 | 
				
			||||||
		AdminId: params.AdminId,
 | 
							AdminId: params.AdminId,
 | 
				
			||||||
@@ -63,12 +65,17 @@ func (this *OtpQrcodeAction) RunGet(params struct {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	var url = gotp.NewDefaultTOTP(secret).ProvisioningUri(admin.Username, uiConfig.AdminSystemName)
 | 
						var url = gotp.NewDefaultTOTP(secret).ProvisioningUri(admin.Username, uiConfig.AdminSystemName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
	data, err := qrcode.Encode(otputils.FixIssuer(url), qrcode.Medium, 256)
 | 
						data, err := qrcode.Encode(otputils.FixIssuer(url), qrcode.Medium, 256)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		this.ErrorPage(err)
 | 
							this.ErrorPage(err)
 | 
				
			||||||
		return
 | 
							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-Type", "image/png")
 | 
				
			||||||
 | 
						this.AddHeader("Content-Length", types.String(len(data)))
 | 
				
			||||||
	_, _ = this.Write(data)
 | 
						_, _ = this.Write(data)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import (
 | 
				
			|||||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
						"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
				
			||||||
	"github.com/iwind/TeaGo/maps"
 | 
						"github.com/iwind/TeaGo/maps"
 | 
				
			||||||
 | 
						"github.com/iwind/TeaGo/types"
 | 
				
			||||||
	"github.com/skip2/go-qrcode"
 | 
						"github.com/skip2/go-qrcode"
 | 
				
			||||||
	"github.com/xlzd/gotp"
 | 
						"github.com/xlzd/gotp"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -21,6 +22,7 @@ func (this *OtpQrcodeAction) Init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (this *OtpQrcodeAction) RunGet(params struct {
 | 
					func (this *OtpQrcodeAction) RunGet(params struct {
 | 
				
			||||||
	UserId   int64
 | 
						UserId   int64
 | 
				
			||||||
 | 
						Download bool
 | 
				
			||||||
}) {
 | 
					}) {
 | 
				
			||||||
	loginResp, err := this.RPC().LoginRPC().FindEnabledLogin(this.AdminContext(), &pb.FindEnabledLoginRequest{
 | 
						loginResp, err := this.RPC().LoginRPC().FindEnabledLogin(this.AdminContext(), &pb.FindEnabledLoginRequest{
 | 
				
			||||||
		UserId: params.UserId,
 | 
							UserId: params.UserId,
 | 
				
			||||||
@@ -71,6 +73,11 @@ func (this *OtpQrcodeAction) RunGet(params struct {
 | 
				
			|||||||
		this.ErrorPage(err)
 | 
							this.ErrorPage(err)
 | 
				
			||||||
		return
 | 
							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-Type", "image/png")
 | 
				
			||||||
 | 
						this.AddHeader("Content-Length", types.String(len(data)))
 | 
				
			||||||
	_, _ = this.Write(data)
 | 
						_, _ = this.Write(data)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,8 +64,8 @@
 | 
				
			|||||||
    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
					    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
				
			||||||
        <td>认证二维码</td>
 | 
					        <td>认证二维码</td>
 | 
				
			||||||
        <td>
 | 
					        <td>
 | 
				
			||||||
            <img :src="'/admins/otpQrcode?adminId=' + admin.id"/>
 | 
					            <img alt="qrcode" :src="'./otpQrcode?adminId=' + admin.id"/>
 | 
				
			||||||
            <p class="comment">可以通过二维码快速添加OTP认证信息到认证App中。</p>
 | 
					            <p class="comment"><a :href="'./otpQrcode?adminId=' + admin.id + '&download=true'">[下载]</a>   可以通过二维码快速添加OTP认证信息到认证App中。</p>
 | 
				
			||||||
        </td>
 | 
					        </td>
 | 
				
			||||||
    </tr>
 | 
					    </tr>
 | 
				
			||||||
    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
					    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,8 +106,8 @@
 | 
				
			|||||||
    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
					    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
				
			||||||
        <td>认证二维码</td>
 | 
					        <td>认证二维码</td>
 | 
				
			||||||
        <td>
 | 
					        <td>
 | 
				
			||||||
            <img :src="'/users/otpQrcode?userId=' + user.id"/>
 | 
					            <img alt="qrcode" :src="'./otpQrcode?userId=' + user.id"/>
 | 
				
			||||||
            <p class="comment">可以通过二维码快速添加OTP认证信息到认证App中。</p>
 | 
					            <p class="comment"><a :href="'./otpQrcode?userId=' + user.id + '&download=true'">[下载]</a>   可以通过二维码快速添加OTP认证信息到认证App中。</p>
 | 
				
			||||||
        </td>
 | 
					        </td>
 | 
				
			||||||
    </tr>
 | 
					    </tr>
 | 
				
			||||||
    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
					    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user