feat: fix the issue of jumping back to the login page after resetting password (#1288)

* fix: redirect to login page

* fix: front end router

* fix: front end router

* fix: signup page router

* fix: redirect to login page
This commit is contained in:
Chell
2022-11-13 05:16:49 +01:00
committed by GitHub
parent d542208eb8
commit 61c2fd5412
5 changed files with 17 additions and 14 deletions

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import React from "react"; import React from "react";
import {Link, useHistory} from "react-router-dom"; import {Link} from "react-router-dom";
import {Tag, Tooltip, message} from "antd"; import {Tag, Tooltip, message} from "antd";
import {QuestionCircleTwoTone} from "@ant-design/icons"; import {QuestionCircleTwoTone} from "@ant-design/icons";
import {isMobile as isMobileDevice} from "react-device-detect"; import {isMobile as isMobileDevice} from "react-device-detect";
@ -752,7 +752,7 @@ export function getLoginLink(application) {
} else if (authConfig.appName === application.name) { } else if (authConfig.appName === application.name) {
url = "/login"; url = "/login";
} else if (application.signinUrl === "") { } else if (application.signinUrl === "") {
url = path.join(application.homepageUrl, "login"); url = path.join(application.homepageUrl, "/login");
} else { } else {
url = application.signinUrl; url = application.signinUrl;
} }
@ -764,9 +764,8 @@ export function renderLoginLink(application, text) {
return renderLink(url, text, null); return renderLink(url, text, null);
} }
export function redirectToLoginPage(application) { export function redirectToLoginPage(application, history) {
const loginLink = getLoginLink(application); const loginLink = getLoginLink(application);
const history = useHistory();
history.push(loginLink); history.push(loginLink);
} }

View File

@ -23,6 +23,7 @@ import {CountDownInput} from "../common/CountDownInput";
import * as UserBackend from "../backend/UserBackend"; import * as UserBackend from "../backend/UserBackend";
import {CheckCircleOutlined, KeyOutlined, LockOutlined, SolutionOutlined, UserOutlined} from "@ant-design/icons"; import {CheckCircleOutlined, KeyOutlined, LockOutlined, SolutionOutlined, UserOutlined} from "@ant-design/icons";
import CustomGithubCorner from "../CustomGithubCorner"; import CustomGithubCorner from "../CustomGithubCorner";
import {withRouter} from "react-router-dom";
const {Step} = Steps; const {Step} = Steps;
const {Option} = Select; const {Option} = Select;
@ -166,7 +167,7 @@ class ForgetPage extends React.Component {
values.userOwner = this.state.application?.organizationObj.name; values.userOwner = this.state.application?.organizationObj.name;
UserBackend.setPassword(values.userOwner, values.username, "", values?.newPassword).then(res => { UserBackend.setPassword(values.userOwner, values.username, "", values?.newPassword).then(res => {
if (res.status === "ok") { if (res.status === "ok") {
Setting.redirectToLoginPage(this.state.application); Setting.redirectToLoginPage(this.state.application, this.props.history);
} else { } else {
Setting.showMessage("error", i18next.t(`signup:${res.msg}`)); Setting.showMessage("error", i18next.t(`signup:${res.msg}`));
} }
@ -550,4 +551,4 @@ class ForgetPage extends React.Component {
} }
} }
export default ForgetPage; export default withRouter(ForgetPage);

View File

@ -30,6 +30,7 @@ import {CountDownInput} from "../common/CountDownInput";
import SelectLanguageBox from "../SelectLanguageBox"; import SelectLanguageBox from "../SelectLanguageBox";
import {withTranslation} from "react-i18next"; import {withTranslation} from "react-i18next";
import {CaptchaModal} from "../common/CaptchaModal"; import {CaptchaModal} from "../common/CaptchaModal";
import {withRouter} from "react-router-dom";
const {TabPane} = Tabs; const {TabPane} = Tabs;
@ -339,7 +340,7 @@ class LoginPage extends React.Component {
title="Sign Up Error" title="Sign Up Error"
subTitle={"The application does not allow to sign up new account"} subTitle={"The application does not allow to sign up new account"}
extra={[ extra={[
<Button type="primary" key="signin" onClick={() => Setting.redirectToLoginPage(application)}> <Button type="primary" key="signin" onClick={() => Setting.redirectToLoginPage(application, this.props.history)}>
{ {
i18next.t("login:Sign In") i18next.t("login:Sign In")
} }
@ -816,4 +817,4 @@ class LoginPage extends React.Component {
} }
} }
export default withTranslation()(LoginPage); export default withTranslation()(withRouter(LoginPage));

View File

@ -22,6 +22,7 @@ import i18next from "i18next";
import AffiliationSelect from "../common/AffiliationSelect"; import AffiliationSelect from "../common/AffiliationSelect";
import OAuthWidget from "../common/OAuthWidget"; import OAuthWidget from "../common/OAuthWidget";
import SelectRegionBox from "../SelectRegionBox"; import SelectRegionBox from "../SelectRegionBox";
import {withRouter} from "react-router-dom";
class PromptPage extends React.Component { class PromptPage extends React.Component {
constructor(props) { constructor(props) {
@ -190,7 +191,7 @@ class PromptPage extends React.Component {
if (redirectUrl !== "" && redirectUrl !== null) { if (redirectUrl !== "" && redirectUrl !== null) {
Setting.goToLink(redirectUrl); Setting.goToLink(redirectUrl);
} else { } else {
Setting.redirectToLoginPage(this.getApplicationObj()); Setting.redirectToLoginPage(this.getApplicationObj(), this.props.history);
} }
} else { } else {
Setting.showMessage("error", `Failed to log out: ${res.msg}`); Setting.showMessage("error", `Failed to log out: ${res.msg}`);
@ -234,7 +235,7 @@ class PromptPage extends React.Component {
title="Sign Up Error" title="Sign Up Error"
subTitle={"You are unexpected to see this prompt page"} subTitle={"You are unexpected to see this prompt page"}
extra={[ extra={[
<Button type="primary" key="signin" onClick={() => Setting.redirectToLoginPage(application)}> <Button type="primary" key="signin" onClick={() => Setting.redirectToLoginPage(application, this.props.history)}>
{ {
i18next.t("login:Sign In") i18next.t("login:Sign In")
} }
@ -272,4 +273,4 @@ class PromptPage extends React.Component {
} }
} }
export default PromptPage; export default withRouter(PromptPage);

View File

@ -26,6 +26,7 @@ import {CountDownInput} from "../common/CountDownInput";
import SelectRegionBox from "../SelectRegionBox"; import SelectRegionBox from "../SelectRegionBox";
import CustomGithubCorner from "../CustomGithubCorner"; import CustomGithubCorner from "../CustomGithubCorner";
import SelectLanguageBox from "../SelectLanguageBox"; import SelectLanguageBox from "../SelectLanguageBox";
import {withRouter} from "react-router-dom";
const formItemLayout = { const formItemLayout = {
labelCol: { labelCol: {
@ -541,7 +542,7 @@ class SignupPage extends React.Component {
title="Sign Up Error" title="Sign Up Error"
subTitle={"The application does not allow to sign up new account"} subTitle={"The application does not allow to sign up new account"}
extra={[ extra={[
<Button type="primary" key="signin" onClick={() => Setting.redirectToLoginPage(application)}> <Button type="primary" key="signin" onClick={() => Setting.redirectToLoginPage(application, this.props.history)}>
{ {
i18next.t("login:Sign In") i18next.t("login:Sign In")
} }
@ -600,7 +601,7 @@ class SignupPage extends React.Component {
if (linkInStorage !== null && linkInStorage !== "") { if (linkInStorage !== null && linkInStorage !== "") {
Setting.goToLink(linkInStorage); Setting.goToLink(linkInStorage);
} else { } else {
Setting.redirectToLoginPage(application); Setting.redirectToLoginPage(application, this.props.history);
} }
}}> }}>
{i18next.t("signup:sign in now")} {i18next.t("signup:sign in now")}
@ -660,4 +661,4 @@ class SignupPage extends React.Component {
} }
} }
export default SignupPage; export default withRouter(SignupPage);