fix: forget password and sign up router (#1227)

* fix: forget password and sign up router

* fix: link

* fix: jump logic

* fix: signup link

* fix: signup link

* fix: login and signup router

* remove comments

* fix: normal router

* fix: link abstraction

* rename jump component

* fix: session storage

* fix: store signin url

* fix: jumplink props

* fix: simplify link

* fix: path join

* fix: remove unused functions
This commit is contained in:
Chell 2022-10-22 17:17:50 +02:00 committed by GitHub
parent b0f572c51a
commit 304643736b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 38 deletions

View File

@ -70,6 +70,7 @@
"eslint-plugin-react": "^7.31.1",
"husky": "^4.3.8",
"lint-staged": "^13.0.3",
"path-browserify": "^1.0.1",
"stylelint": "^14.11.0",
"stylelint-config-recommended-less": "^1.0.4",
"stylelint-config-standard": "^28.0.0"

View File

@ -22,6 +22,8 @@ import copy from "copy-to-clipboard";
import {authConfig} from "./auth/Auth";
import {Helmet} from "react-helmet";
import * as Conf from "./Conf";
import {Link} from "react-router-dom";
import * as path from "path-browserify";
export const ServerUrl = "";
@ -752,49 +754,64 @@ export function goToLogin(ths, application) {
goToLinkSoft(ths, "/login");
} else {
if (application.signinUrl === "") {
goToLink(`${application.homepageUrl}/login`);
goToLink(path.join(application.homepageUrl, "login"));
} else {
goToLink(application.signinUrl);
}
}
}
export function goToSignup(ths, application) {
if (application === null) {
return;
function JumpLink({url, children, onClick}) {
if (url === null) {
return <Link style={{float: "right"}} onClick={onClick} to={""}>{children}</Link>;
}
if (!application.enablePassword && window.location.pathname.includes("/login/oauth/authorize")) {
const link = window.location.href.replace("/login/oauth/authorize", "/auto-signup/oauth/authorize");
goToLink(link);
return;
}
if (authConfig.appName === application.name) {
goToLinkSoft(ths, "/signup");
if (url.startsWith("/")) {
return <Link to={url} style={{float: "right"}} onClick={onClick}>{children}</Link>;
} else if (url.startsWith("http")) {
return <a href={url} target="_blank" rel="noopener noreferrer" style={{float: "right"}} onClick={onClick}>{children}</a>;
} else {
if (application.signupUrl === "") {
goToLinkSoft(ths, `/signup/${application.name}`);
} else {
goToLink(application.signupUrl);
}
return <Link style={{float: "right"}} onClick={onClick} to={""}>{children}</Link>;
}
}
export function goToForget(ths, application) {
function storeSigninUrl() {
sessionStorage.setItem("signinUrl", window.location.href);
}
export function renderSignupLink(application, text) {
let link;
if (application === null) {
return;
link = null;
} else if (!application.enablePassword && window.location.pathname.includes("/login/oauth/authorize")) {
link = window.location.href.replace("/login/oauth/authorize", "/auto-signup/oauth/authorize");
} else if (authConfig.appName === application.name) {
link = "/signup";
} else {
if (application.signupUrl === "") {
link = `/signup/${application.name}`;
} else {
link = application.signupUrl;
}
}
if (authConfig.appName === application.name) {
goToLinkSoft(ths, "/forget");
return <JumpLink url={link} onClick={storeSigninUrl}>{text}</JumpLink>;
}
export function renderForgetLink(application, text) {
let link;
if (application === null) {
link = null;
} else if (authConfig.appName === application.name) {
link = "/forget";
} else {
if (application.forgetUrl === "") {
goToLinkSoft(ths, `/forget/${application.name}`);
link = `/forget/${application.name}`;
} else {
goToLink(application.forgetUrl);
link = application.forgetUrl;
}
}
return <JumpLink url={link}>{text}</JumpLink>;
}
export function renderHelmet(application) {

View File

@ -405,11 +405,9 @@ class LoginPage extends React.Component {
{i18next.t("login:Auto sign in")}
</Checkbox>
</Form.Item>
<a style={{float: "right"}} onClick={() => {
Setting.goToForget(this, application);
}}>
{i18next.t("login:Forgot password?")}
</a>
{
Setting.renderForgetLink(application, i18next.t("login:Forgot password?"))
}
</Form.Item>
<Form.Item>
<Button
@ -485,12 +483,9 @@ class LoginPage extends React.Component {
!application.enableSignUp ? null : (
<>
{i18next.t("login:No account?")}&nbsp;
<a onClick={() => {
sessionStorage.setItem("signinUrl", window.location.href);
Setting.goToSignup(this, application);
}}>
{i18next.t("login:sign up now")}
</a>
{
Setting.renderSignupLink(application, i18next.t("login:sign up now"))
}
</>
)
}

View File

@ -7918,6 +7918,11 @@ pascal-case@^3.1.2:
no-case "^3.0.4"
tslib "^2.0.3"
path-browserify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd"
integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==
path-exists@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"