Fix prompt redirect logic and db sync bug.

This commit is contained in:
Yang Luo
2021-06-20 13:27:26 +08:00
parent d3a8ab8347
commit a43db3e55a
8 changed files with 126 additions and 7 deletions

View File

@ -178,6 +178,12 @@ class App extends Component {
});
}
onUpdateAccount(account) {
this.setState({
account: account
});
}
handleRightDropdownClick(e) {
if (e.key === '201') {
this.props.history.push(`/account`);
@ -422,7 +428,7 @@ class App extends Component {
return (
<Switch>
<Route exact path="/signup" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...props} />)}/>
<Route exact path="/signup/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...props} />)}/>
<Route exact path="/signup/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...props} onUpdateAccount={(account) => {this.onUpdateAccount(account)}} />)}/>
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage {...props} />)}/>
<Route exact path="/signup/oauth/authorize" render={(props) => <LoginPage type={"code"} mode={"signup"} {...props} />}/>
<Route exact path="/login/oauth/authorize" render={(props) => <LoginPage type={"code"} mode={"signin"} {...props} />}/>
@ -430,7 +436,7 @@ class App extends Component {
<Route exact path="/forget" render={(props) => this.renderHomeIfLoggedIn(<SelfForgetPage {...props} />)}/>
<Route exact path="/forget/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<ForgetPage {...props} />)}/>
<Route exact path="/prompt" render={(props) => this.renderLoginIfNotLoggedIn(<PromptPage account={this.state.account} {...props} />)}/>
<Route exact path="/prompt/:applicationName" render={(props) => this.renderLoginIfNotLoggedIn(<PromptPage account={this.state.account} {...props} />)}/>
<Route exact path="/prompt/:applicationName" render={(props) => this.renderLoginIfNotLoggedIn(<PromptPage account={this.state.account} onUpdateAccount={(account) => {this.onUpdateAccount(account)}} {...props} />)}/>
</Switch>
)
}

View File

@ -16,10 +16,11 @@ import React from "react";
import {Link} from "react-router-dom";
import {Button, Col, Result, Row} from "antd";
import * as ApplicationBackend from "../backend/ApplicationBackend";
import * as UserBackend from "../backend/UserBackend";
import * as AuthBackend from "./AuthBackend";
import * as Setting from "../Setting";
import i18next from "i18next";
import AffiliationSelect from "../common/AffiliationSelect";
import * as UserBackend from "../backend/UserBackend";
import OAuthWidget from "../common/OAuthWidget";
class PromptPage extends React.Component {
@ -160,6 +161,23 @@ class PromptPage extends React.Component {
return true;
}
onUpdateAccount(account) {
this.props.onUpdateAccount(account);
}
logout() {
AuthBackend.logout()
.then((res) => {
if (res.status === 'ok') {
this.onUpdateAccount(null);
Setting.goToLogin(this, this.getApplicationObj());
} else {
Setting.showMessage("error", `Failed to log out: ${res.msg}`);
}
});
}
submitUserEdit(isFinal) {
let user = Setting.deepCopy(this.state.user);
UserBackend.updateUser(this.state.user.owner, this.state.user.name, user)
@ -168,7 +186,7 @@ class PromptPage extends React.Component {
if (isFinal) {
Setting.showMessage("success", `Successfully saved`);
Setting.goToLogin(this, this.getApplicationObj());
this.logout();
}
} else {
if (isFinal) {

View File

@ -113,13 +113,31 @@ class SignupPage extends React.Component {
}
}
onUpdateAccount(account) {
this.props.onUpdateAccount(account);
}
onFinish(values) {
const application = this.getApplicationObj();
values.phonePrefix = application.organizationObj.phonePrefix;
AuthBackend.signup(values)
.then((res) => {
if (res.status === 'ok') {
Setting.goToLinkSoft(this, this.getResultPath(application));
AuthBackend.getAccount("")
.then((res) => {
let account = null;
if (res.status === "ok") {
account = res.data;
account.organization = res.data2;
this.onUpdateAccount(account);
Setting.goToLinkSoft(this, this.getResultPath(application));
} else {
if (res.msg !== "Please sign in first") {
Setting.showMessage("error", `Failed to sign in: ${res.msg}`);
}
}
});
} else {
Setting.showMessage("error", i18next.t(`signup:${res.msg}`));
}