mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	OTP认证二维码增加下载链接
This commit is contained in:
		@@ -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)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -64,8 +64,8 @@
 | 
			
		||||
    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
			
		||||
        <td>认证二维码</td>
 | 
			
		||||
        <td>
 | 
			
		||||
            <img :src="'/admins/otpQrcode?adminId=' + admin.id"/>
 | 
			
		||||
            <p class="comment">可以通过二维码快速添加OTP认证信息到认证App中。</p>
 | 
			
		||||
            <img alt="qrcode" :src="'./otpQrcode?adminId=' + admin.id"/>
 | 
			
		||||
            <p class="comment"><a :href="'./otpQrcode?adminId=' + admin.id + '&download=true'">[下载]</a>   可以通过二维码快速添加OTP认证信息到认证App中。</p>
 | 
			
		||||
        </td>
 | 
			
		||||
    </tr>
 | 
			
		||||
    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
			
		||||
 
 | 
			
		||||
@@ -106,8 +106,8 @@
 | 
			
		||||
    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
			
		||||
        <td>认证二维码</td>
 | 
			
		||||
        <td>
 | 
			
		||||
            <img :src="'/users/otpQrcode?userId=' + user.id"/>
 | 
			
		||||
            <p class="comment">可以通过二维码快速添加OTP认证信息到认证App中。</p>
 | 
			
		||||
            <img alt="qrcode" :src="'./otpQrcode?userId=' + user.id"/>
 | 
			
		||||
            <p class="comment"><a :href="'./otpQrcode?userId=' + user.id + '&download=true'">[下载]</a>   可以通过二维码快速添加OTP认证信息到认证App中。</p>
 | 
			
		||||
        </td>
 | 
			
		||||
    </tr>
 | 
			
		||||
    <tr v-if="otp != null && otp.isOn && moreOptionsVisible">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user