mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 10:45:47 +08:00
feat: improve QR code for casdoor-app (#3226)
* feat: simplify login url for casdoor-app * feat: add token check * fix: improve logic
This commit is contained in:
parent
110dc04179
commit
74543b9533
@ -1050,12 +1050,7 @@ class UserEditPage extends React.Component {
|
|||||||
<MfaAccountTable
|
<MfaAccountTable
|
||||||
title={i18next.t("user:MFA accounts")}
|
title={i18next.t("user:MFA accounts")}
|
||||||
table={this.state.user.mfaAccounts}
|
table={this.state.user.mfaAccounts}
|
||||||
qrUrl={
|
accessToken={this.props.account?.accessToken}
|
||||||
"casdoor-app://login/into?serverUrl=" + window.location.origin +
|
|
||||||
"&clientId=" + this.state.application.clientId +
|
|
||||||
"&organizationName=" + this.state.organizationName +
|
|
||||||
"&appName=" + this.state.user.signupApplication
|
|
||||||
}
|
|
||||||
icon={this.state.user.avatar}
|
icon={this.state.user.avatar}
|
||||||
onUpdateTable={(table) => {this.updateUserField("mfaAccounts", table);}}
|
onUpdateTable={(table) => {this.updateUserField("mfaAccounts", table);}}
|
||||||
/>
|
/>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import {DeleteOutlined, DownOutlined, UpOutlined} from "@ant-design/icons";
|
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 * as Setting from "../Setting";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
@ -23,7 +23,6 @@ class MfaAccountTable extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
classes: props,
|
classes: props,
|
||||||
qrUrl: this.props.qrUrl,
|
|
||||||
icon: this.props.icon,
|
icon: this.props.icon,
|
||||||
mfaAccounts: this.props.table !== null ? this.props.table.map((item, index) => {
|
mfaAccounts: this.props.table !== null ? this.props.table.map((item, index) => {
|
||||||
item.key = index;
|
item.key = index;
|
||||||
@ -77,6 +76,42 @@ class MfaAccountTable extends React.Component {
|
|||||||
this.updateTable(table);
|
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 <Alert message={error} type="error" showIcon />;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<QRCode
|
||||||
|
value={qrUrl}
|
||||||
|
icon={this.state.icon}
|
||||||
|
errorLevel="M"
|
||||||
|
size={230}
|
||||||
|
bordered={false}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderTable(table) {
|
renderTable(table) {
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
@ -159,14 +194,9 @@ class MfaAccountTable extends React.Component {
|
|||||||
title={() => (
|
title={() => (
|
||||||
<div>
|
<div>
|
||||||
{this.props.title}
|
{this.props.title}
|
||||||
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{i18next.t("general:Add")}</Button>
|
<Button style={{marginRight: "10px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{i18next.t("general:Add")}</Button>
|
||||||
<Popover trigger="focus" content={
|
<Popover trigger="focus" overlayInnerStyle={{padding: 0}}
|
||||||
<QRCode
|
content={this.renderQrCode()}>
|
||||||
value={this.state.qrUrl}
|
|
||||||
icon={this.state.icon}
|
|
||||||
bordered={false}
|
|
||||||
/>
|
|
||||||
}>
|
|
||||||
<Button style={{marginLeft: "5px"}} type="primary" size="small">{i18next.t("general:QR Code")}</Button>
|
<Button style={{marginLeft: "5px"}} type="primary" size="small">{i18next.t("general:QR Code")}</Button>
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user