From 74543b9533322aa50ce7c5623a03e91e719320b6 Mon Sep 17 00:00:00 2001 From: IZUMI-Zu <274620705z@gmail.com> Date: Mon, 23 Sep 2024 22:27:58 +0800 Subject: [PATCH] feat: improve QR code for casdoor-app (#3226) * feat: simplify login url for casdoor-app * feat: add token check * fix: improve logic --- web/src/UserEditPage.js | 7 +---- web/src/table/MfaAccountTable.js | 50 +++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index 669380b9..f7e0393a 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -1050,12 +1050,7 @@ class UserEditPage extends React.Component { diff --git a/web/src/table/MfaAccountTable.js b/web/src/table/MfaAccountTable.js index ec153cd1..db589b89 100644 --- a/web/src/table/MfaAccountTable.js +++ b/web/src/table/MfaAccountTable.js @@ -14,7 +14,7 @@ import React from "react"; import {DeleteOutlined, DownOutlined, UpOutlined} from "@ant-design/icons"; -import {Button, Col, Image, Input, Popover, QRCode, Row, Table, Tooltip} from "antd"; +import {Alert, Button, Col, Image, Input, Popover, QRCode, Row, Table, Tooltip} from "antd"; import * as Setting from "../Setting"; import i18next from "i18next"; @@ -23,7 +23,6 @@ class MfaAccountTable extends React.Component { super(props); this.state = { classes: props, - qrUrl: this.props.qrUrl, icon: this.props.icon, mfaAccounts: this.props.table !== null ? this.props.table.map((item, index) => { item.key = index; @@ -77,6 +76,42 @@ class MfaAccountTable extends React.Component { this.updateTable(table); } + getQrUrl() { + const {accessToken} = this.props; + let qrUrl = `casdoor-app://login?serverUrl=${window.location.origin}&accessToken=${accessToken}`; + let error = null; + + if (!accessToken) { + qrUrl = ""; + error = i18next.t("general:Access token is empty"); + } + + if (qrUrl.length >= 2000) { + qrUrl = ""; + error = i18next.t("general:QR code is too large"); + } + + return {qrUrl, error}; + } + + renderQrCode() { + const {qrUrl, error} = this.getQrUrl(); + + if (error) { + return ; + } else { + return ( + + ); + } + } + renderTable(table) { const columns = [ { @@ -159,14 +194,9 @@ class MfaAccountTable extends React.Component { title={() => (
{this.props.title}     - - - }> + +