mirror of https://github.com/casbin/casnode.git
feat: optimize silent signin (#538)
This commit is contained in:
parent
0d3febe4e1
commit
d526c9ae00
|
@ -16,7 +16,7 @@ import React, {Component} from "react";
|
|||
import classNames from "classnames";
|
||||
import "./App.less";
|
||||
import "codemirror/lib/codemirror.css";
|
||||
import {BackTop} from "antd";
|
||||
import {BackTop, Spin} from "antd";
|
||||
import * as Setting from "./Setting";
|
||||
import {Route, Switch} from "react-router-dom";
|
||||
import TopicPage from "./TopicPage";
|
||||
|
@ -82,6 +82,8 @@ import FooterRenderBox from "./main/FooterRenderBox";
|
|||
class App extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
this.state = {
|
||||
classes: props,
|
||||
account: undefined,
|
||||
|
@ -90,6 +92,7 @@ class App extends Component {
|
|||
nodeBackgroundImage: "",
|
||||
nodeBackgroundColor: "",
|
||||
nodeBackgroundRepeat: "",
|
||||
silentSignin: params.get("silentSignin") === "1",
|
||||
};
|
||||
|
||||
Setting.initServerUrl();
|
||||
|
@ -588,10 +591,6 @@ class App extends Component {
|
|||
}
|
||||
|
||||
renderContent() {
|
||||
if (window.location.pathname === "/callback") {
|
||||
return <AuthCallback />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="content">
|
||||
<div id="Leftbar" />
|
||||
|
@ -609,12 +608,30 @@ class App extends Component {
|
|||
return <Embed account={this.state.account} refreshAccount={this.getAccount.bind(this)} />;
|
||||
}
|
||||
|
||||
if (window.location.pathname.startsWith("/callback")) {
|
||||
return <AuthCallback />;
|
||||
}
|
||||
|
||||
if (this.state.silentSignin) {
|
||||
if (this.state.account) {
|
||||
Setting.goToLink("/");
|
||||
return null;
|
||||
} else {
|
||||
return (
|
||||
<div style={{textAlign: "center"}}>
|
||||
<Spin size="large" tip={i18next.t("login:Signing in automatically...")} style={{paddingTop: "10%", paddingBottom: "10%"}}>
|
||||
<SilentSignin account={this.state.account} />
|
||||
</Spin>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<link type="text/css" rel="stylesheet" media="all" id="dark-mode" href={this.getThemeLink()} />
|
||||
<BackTop />
|
||||
<Header account={this.state.account} onSignout={this.onSignout.bind(this)} changeMenuStatus={this.changeMenuStatus.bind(this)} showMenu={this.state.showMenu} />
|
||||
<SilentSignin account={this.state.account} />
|
||||
<div
|
||||
id="Wrapper"
|
||||
style={{
|
||||
|
|
|
@ -126,6 +126,14 @@ export function showMessage(type, text) {
|
|||
}
|
||||
}
|
||||
|
||||
export function showMessageEx(type, text, duration, onClose) {
|
||||
if (type === "success") {
|
||||
message.success(text, duration, onClose);
|
||||
} else if (type === "error") {
|
||||
message.error(text, duration, onClose);
|
||||
}
|
||||
}
|
||||
|
||||
export function addRow(array, row) {
|
||||
return [...array, row];
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
import React from "react";
|
||||
import {withRouter} from "react-router-dom";
|
||||
import * as Setting from "./Setting";
|
||||
import i18next from "i18next";
|
||||
|
||||
class SilentSignin extends React.Component {
|
||||
constructor(props) {
|
||||
|
@ -33,8 +34,9 @@ class SilentSignin extends React.Component {
|
|||
}
|
||||
|
||||
if (message.type === "SilentSignin" && message.data === "success") {
|
||||
// Setting.showMessage("success", "hahaha");
|
||||
window.location.reload();
|
||||
Setting.showMessageEx("success", i18next.t("login:Logged in successfully"), 1, () => Setting.goToLink("/"));
|
||||
} else if (message.type === "SilentSignin" && message.data === "user-not-logged-in") {
|
||||
Setting.showMessageEx("error", i18next.t("login:Failed to log in"), 1, () => Setting.goToLink("/"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "Help",
|
||||
"Logged in successfully": "Logged in successfully",
|
||||
"Signing In Error": "Signing In Error",
|
||||
"Signing in...": "Signing in..."
|
||||
"Signing in...": "Signing in...",
|
||||
"Failed to log in": "Failed to log in",
|
||||
"Signing in automatically...": "Signing in automatically..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": "'s all created topics",
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "Help",
|
||||
"Logged in successfully": "Logged in successfully",
|
||||
"Signing In Error": "Signing In Error",
|
||||
"Signing in...": "Signing in..."
|
||||
"Signing in...": "Signing in...",
|
||||
"Failed to log in": "Failed to log in",
|
||||
"Signing in automatically...": "Signing in automatically..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": "'s all created topics",
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "Help",
|
||||
"Logged in successfully": "Logged in successfully",
|
||||
"Signing In Error": "Signing In Error",
|
||||
"Signing in...": "Signing in..."
|
||||
"Signing in...": "Signing in...",
|
||||
"Failed to log in": "Failed to log in",
|
||||
"Signing in automatically...": "Signing in automatically..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": "'s all created topics",
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "Help",
|
||||
"Logged in successfully": "Logged in successfully",
|
||||
"Signing In Error": "Signing In Error",
|
||||
"Signing in...": "Signing in..."
|
||||
"Signing in...": "Signing in...",
|
||||
"Failed to log in": "Failed to log in",
|
||||
"Signing in automatically...": "Signing in automatically..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": "'s all created topics",
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "Help",
|
||||
"Logged in successfully": "Logged in successfully",
|
||||
"Signing In Error": "Signing In Error",
|
||||
"Signing in...": "Signing in..."
|
||||
"Signing in...": "Signing in...",
|
||||
"Failed to log in": "Failed to log in",
|
||||
"Signing in automatically...": "Signing in automatically..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": "'s all created topics",
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "Help",
|
||||
"Logged in successfully": "Logged in successfully",
|
||||
"Signing In Error": "Signing In Error",
|
||||
"Signing in...": "Signing in..."
|
||||
"Signing in...": "Signing in...",
|
||||
"Failed to log in": "Failed to log in",
|
||||
"Signing in automatically...": "Signing in automatically..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": "'s all created topics",
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "Help",
|
||||
"Logged in successfully": "Logged in successfully",
|
||||
"Signing In Error": "Signing In Error",
|
||||
"Signing in...": "Signing in..."
|
||||
"Signing in...": "Signing in...",
|
||||
"Failed to log in": "Failed to log in",
|
||||
"Signing in automatically...": "Signing in automatically..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": "'s all created topics",
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "Help",
|
||||
"Logged in successfully": "Logged in successfully",
|
||||
"Signing In Error": "Signing In Error",
|
||||
"Signing in...": "Signing in..."
|
||||
"Signing in...": "Signing in...",
|
||||
"Failed to log in": "Failed to log in",
|
||||
"Signing in automatically...": "Signing in automatically..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": "'s all created topics",
|
||||
|
|
|
@ -230,7 +230,9 @@
|
|||
"Help": "帮助",
|
||||
"Logged in successfully": "登录成功",
|
||||
"Signing In Error": "登录时遇到错误",
|
||||
"Signing in...": "正在登录..."
|
||||
"Signing in...": "正在登录...",
|
||||
"Failed to log in": "登录失败",
|
||||
"Signing in automatically...": "正在自动登录..."
|
||||
},
|
||||
"member": {
|
||||
"'s all created topics": " 创建的主题",
|
||||
|
|
Loading…
Reference in New Issue