mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
Improve login failure handling.
This commit is contained in:
@ -164,7 +164,7 @@ func (c *ApiController) Login() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
resp = &Response{Status: "error", Msg: "need sign up"}
|
resp = &Response{Status: "error", Msg: fmt.Sprintf("the account for provider: %s and username: %s does not exist, please register an account first", provider.Type, userInfo.Username)}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
|
@ -134,7 +134,7 @@ class App extends Component {
|
|||||||
|
|
||||||
Setting.showMessage("success", `Successfully logged out, redirected to homepage`);
|
Setting.showMessage("success", `Successfully logged out, redirected to homepage`);
|
||||||
|
|
||||||
Setting.goToLink("/");
|
Setting.goToLinkSoft(this, "/");
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", `Failed to log out: ${res.msg}`);
|
Setting.showMessage("error", `Failed to log out: ${res.msg}`);
|
||||||
}
|
}
|
||||||
@ -292,7 +292,11 @@ class App extends Component {
|
|||||||
<div>
|
<div>
|
||||||
<Header style={{ padding: '0', marginBottom: '3px'}}>
|
<Header style={{ padding: '0', marginBottom: '3px'}}>
|
||||||
{
|
{
|
||||||
Setting.isMobile() ? null : <a className="logo" href={"/"} />
|
Setting.isMobile() ? null : (
|
||||||
|
<Link to={"/"}>
|
||||||
|
<div className="logo" />
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
<Menu
|
<Menu
|
||||||
// theme="dark"
|
// theme="dark"
|
||||||
|
@ -241,7 +241,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
{i18next.t("general:Providers")}:
|
{i18next.t("general:Providers")}:
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<Select mode="tags" style={{width: '100%'}}
|
<Select virtual={false} mode="tags" style={{width: '100%'}}
|
||||||
value={this.state.application.providers}
|
value={this.state.application.providers}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
this.updateApplicationField('providers', value);
|
this.updateApplicationField('providers', value);
|
||||||
|
@ -51,6 +51,10 @@ export function goToLink(link) {
|
|||||||
window.location.href = link;
|
window.location.href = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function goToLinkSoft(ths, link) {
|
||||||
|
ths.props.history.push(link);
|
||||||
|
}
|
||||||
|
|
||||||
export function showMessage(type, text) {
|
export function showMessage(type, text) {
|
||||||
if (type === "") {
|
if (type === "") {
|
||||||
return;
|
return;
|
||||||
|
@ -18,6 +18,7 @@ import {withRouter} from "react-router-dom";
|
|||||||
import * as AuthBackend from "./AuthBackend";
|
import * as AuthBackend from "./AuthBackend";
|
||||||
import * as Util from "./Util";
|
import * as Util from "./Util";
|
||||||
import {authConfig} from "./Auth";
|
import {authConfig} from "./Auth";
|
||||||
|
import * as Setting from "../Setting";
|
||||||
|
|
||||||
class AuthCallback extends React.Component {
|
class AuthCallback extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -75,22 +76,18 @@ class AuthCallback extends React.Component {
|
|||||||
const responseType = this.getResponseType();
|
const responseType = this.getResponseType();
|
||||||
if (responseType === "login") {
|
if (responseType === "login") {
|
||||||
Util.showMessage("success", `Logged in successfully`);
|
Util.showMessage("success", `Logged in successfully`);
|
||||||
Util.goToLink("/");
|
Setting.goToLinkSoft(this, "/");
|
||||||
} else if (responseType === "code") {
|
} else if (responseType === "code") {
|
||||||
const code = res.data;
|
const code = res.data;
|
||||||
Util.goToLink(`${oAuthParams.redirectUri}?code=${code}&state=${oAuthParams.state}`);
|
Setting.goToLink(`${oAuthParams.redirectUri}?code=${code}&state=${oAuthParams.state}`);
|
||||||
// Util.showMessage("success", `Authorization code: ${res.data}`);
|
// Util.showMessage("success", `Authorization code: ${res.data}`);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (res.msg === "need sign up") {
|
|
||||||
Util.goToLink("/register");
|
|
||||||
} else {
|
} else {
|
||||||
// Util.showMessage("error", `Log in failed:${res.msg}`);
|
// Util.showMessage("error", `Log in failed:${res.msg}`);
|
||||||
this.setState({
|
this.setState({
|
||||||
msg: res.msg,
|
msg: res.msg,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +98,7 @@ class AuthCallback extends React.Component {
|
|||||||
(this.state.msg === null) ? (
|
(this.state.msg === null) ? (
|
||||||
<Spin size="large" tip="Signing in..." style={{paddingTop: "10%"}} />
|
<Spin size="large" tip="Signing in..." style={{paddingTop: "10%"}} />
|
||||||
) : (
|
) : (
|
||||||
Util.renderMessageLarge(this.state.msg)
|
Util.renderMessageLarge(this, this.state.msg)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,6 +19,7 @@ import {LockOutlined, UserOutlined} from "@ant-design/icons";
|
|||||||
import * as AuthBackend from "./AuthBackend";
|
import * as AuthBackend from "./AuthBackend";
|
||||||
import * as Provider from "./Provider";
|
import * as Provider from "./Provider";
|
||||||
import * as Util from "./Util";
|
import * as Util from "./Util";
|
||||||
|
import * as Setting from "../Setting";
|
||||||
|
|
||||||
class LoginPage extends React.Component {
|
class LoginPage extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -90,10 +91,10 @@ class LoginPage extends React.Component {
|
|||||||
const responseType = this.state.type;
|
const responseType = this.state.type;
|
||||||
if (responseType === "login") {
|
if (responseType === "login") {
|
||||||
Util.showMessage("success", `Logged in successfully`);
|
Util.showMessage("success", `Logged in successfully`);
|
||||||
Util.goToLink("/");
|
Setting.goToLink("/");
|
||||||
} else if (responseType === "code") {
|
} else if (responseType === "code") {
|
||||||
const code = res.data;
|
const code = res.data;
|
||||||
Util.goToLink(`${oAuthParams.redirectUri}?code=${code}&state=${oAuthParams.state}`);
|
Setting.goToLink(`${oAuthParams.redirectUri}?code=${code}&state=${oAuthParams.state}`);
|
||||||
// Util.showMessage("success", `Authorization code: ${res.data}`);
|
// Util.showMessage("success", `Authorization code: ${res.data}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -208,7 +209,7 @@ class LoginPage extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const application = this.getApplicationObj();
|
const application = this.getApplicationObj();
|
||||||
if (application === null) {
|
if (application === null) {
|
||||||
return Util.renderMessageLarge(this.state.msg);
|
return Util.renderMessageLarge(this, this.state.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -16,10 +16,6 @@ import React from "react";
|
|||||||
import {Alert, Button, message, Result} from "antd";
|
import {Alert, Button, message, Result} from "antd";
|
||||||
import * as Setting from "../Setting";
|
import * as Setting from "../Setting";
|
||||||
|
|
||||||
export function goToLink(link) {
|
|
||||||
window.location.href = link;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function showMessage(type, text) {
|
export function showMessage(type, text) {
|
||||||
if (type === "success") {
|
if (type === "success") {
|
||||||
message.success(text);
|
message.success(text);
|
||||||
@ -50,7 +46,7 @@ export function renderMessage(msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderMessageLarge(msg) {
|
export function renderMessageLarge(ths, msg) {
|
||||||
if (msg !== null) {
|
if (msg !== null) {
|
||||||
return (
|
return (
|
||||||
<div style={{display: "inline"}}>
|
<div style={{display: "inline"}}>
|
||||||
@ -59,11 +55,11 @@ export function renderMessageLarge(msg) {
|
|||||||
title="Login Error"
|
title="Login Error"
|
||||||
subTitle={msg}
|
subTitle={msg}
|
||||||
extra={[
|
extra={[
|
||||||
<Button key="home" onClick={() => Setting.goToLink("/")}>
|
<Button key="home" onClick={() => Setting.goToLinkSoft(ths, "/")}>
|
||||||
Home
|
Home
|
||||||
</Button>,
|
</Button>,
|
||||||
<Button type="primary" key="help" onClick={() => Setting.goToLink("/help")}>
|
<Button type="primary" key="register" onClick={() => Setting.goToLinkSoft(ths, "/register")}>
|
||||||
Help
|
Register
|
||||||
</Button>,
|
</Button>,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import {Card, Col, Row} from "antd";
|
import {Card, Col, Row} from "antd";
|
||||||
import * as Setting from "../Setting";
|
import * as Setting from "../Setting";
|
||||||
|
import {withRouter} from "react-router-dom";
|
||||||
|
|
||||||
const { Meta } = Card;
|
const { Meta } = Card;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ class SingleCard extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card.Grid style={gridStyle} onClick={() => Setting.goToLink(link)}>
|
<Card.Grid style={gridStyle} onClick={() => Setting.goToLinkSoft(this, link)}>
|
||||||
<img src={logo} alt="logo" height={60} style={{marginBottom: '20px'}}/>
|
<img src={logo} alt="logo" height={60} style={{marginBottom: '20px'}}/>
|
||||||
<Meta
|
<Meta
|
||||||
title={title}
|
title={title}
|
||||||
@ -52,7 +53,7 @@ class SingleCard extends React.Component {
|
|||||||
cover={
|
cover={
|
||||||
<img alt="logo" src={logo} width={"100%"} height={"100%"} />
|
<img alt="logo" src={logo} width={"100%"} height={"100%"} />
|
||||||
}
|
}
|
||||||
onClick={() => Setting.goToLink(link)}
|
onClick={() => Setting.goToLinkSoft(this, link)}
|
||||||
style={isSingle ? {width: "320px"} : null}
|
style={isSingle ? {width: "320px"} : null}
|
||||||
>
|
>
|
||||||
<Meta title={title} description={desc} />
|
<Meta title={title} description={desc} />
|
||||||
@ -73,4 +74,4 @@ class SingleCard extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SingleCard;
|
export default withRouter(SingleCard);
|
||||||
|
Reference in New Issue
Block a user