2022-02-13 23:39:27 +08:00
|
|
|
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
2021-02-13 13:30:51 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
import React from "react";
|
2022-07-12 20:06:01 +08:00
|
|
|
import {Button, Checkbox, Col, Form, Input, Result, Row, Spin, Tabs} from "antd";
|
2021-02-13 12:15:19 +08:00
|
|
|
import {LockOutlined, UserOutlined} from "@ant-design/icons";
|
2022-07-12 20:06:01 +08:00
|
|
|
import * as UserWebauthnBackend from "../backend/UserWebauthnBackend";
|
2023-02-18 23:39:32 +08:00
|
|
|
import * as Conf from "../Conf";
|
2021-02-14 15:40:57 +08:00
|
|
|
import * as AuthBackend from "./AuthBackend";
|
2022-09-10 20:41:45 +08:00
|
|
|
import * as OrganizationBackend from "../backend/OrganizationBackend";
|
2021-04-19 01:14:41 +08:00
|
|
|
import * as ApplicationBackend from "../backend/ApplicationBackend";
|
2021-02-14 16:59:08 +08:00
|
|
|
import * as Provider from "./Provider";
|
2022-08-05 18:59:56 +08:00
|
|
|
import * as ProviderButton from "./ProviderButton";
|
2021-02-14 15:40:57 +08:00
|
|
|
import * as Util from "./Util";
|
2021-03-26 21:58:19 +08:00
|
|
|
import * as Setting from "../Setting";
|
2023-03-26 18:44:47 +08:00
|
|
|
import * as AgreementModal from "../common/modal/AgreementModal";
|
2021-10-09 21:15:57 +08:00
|
|
|
import SelfLoginButton from "./SelfLoginButton";
|
2021-04-27 22:03:22 +08:00
|
|
|
import i18next from "i18next";
|
2023-03-26 18:44:47 +08:00
|
|
|
import CustomGithubCorner from "../common/CustomGithubCorner";
|
2023-02-12 18:56:56 +08:00
|
|
|
import {SendCodeInput} from "../common/SendCodeInput";
|
2023-03-26 18:44:47 +08:00
|
|
|
import LanguageSelect from "../common/select/LanguageSelect";
|
|
|
|
import {CaptchaModal} from "../common/modal/CaptchaModal";
|
2023-04-22 16:16:25 +08:00
|
|
|
import {CaptchaRule} from "../common/modal/CaptchaModal";
|
2022-12-13 22:32:45 +08:00
|
|
|
import RedirectForm from "../common/RedirectForm";
|
2021-02-13 12:15:19 +08:00
|
|
|
|
2021-03-26 21:56:51 +08:00
|
|
|
class LoginPage extends React.Component {
|
2021-02-13 12:15:19 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
classes: props,
|
2021-03-20 11:34:04 +08:00
|
|
|
type: props.type,
|
2023-03-24 23:17:54 +08:00
|
|
|
applicationName: props.applicationName ?? (props.match?.params?.applicationName ?? null),
|
|
|
|
owner: props.owner ?? (props.match?.params?.owner ?? null),
|
|
|
|
mode: props.mode ?? (props.match?.params?.mode ?? null), // "signup" or "signin"
|
2021-03-20 11:34:04 +08:00
|
|
|
msg: null,
|
2021-11-28 21:10:21 +08:00
|
|
|
username: null,
|
2022-03-18 20:12:29 +08:00
|
|
|
validEmailOrPhone: false,
|
|
|
|
validEmail: false,
|
2022-08-06 23:54:56 +08:00
|
|
|
loginMethod: "password",
|
2023-04-22 16:16:25 +08:00
|
|
|
enableCaptchaModal: CaptchaRule.Never,
|
2022-10-28 13:38:14 +08:00
|
|
|
openCaptchaModal: false,
|
|
|
|
verifyCaptcha: undefined,
|
2022-12-13 22:32:45 +08:00
|
|
|
samlResponse: "",
|
|
|
|
relayState: "",
|
|
|
|
redirectUrl: "",
|
2023-01-19 11:39:24 +01:00
|
|
|
isTermsOfUseVisible: false,
|
|
|
|
termsOfUseContent: "",
|
2021-02-13 12:15:19 +08:00
|
|
|
};
|
2022-07-12 20:06:01 +08:00
|
|
|
|
2022-04-04 00:09:04 +08:00
|
|
|
if (this.state.type === "cas" && props.match?.params.casApplicationName !== undefined) {
|
2023-03-24 23:17:54 +08:00
|
|
|
this.state.owner = props.match?.params?.owner;
|
|
|
|
this.state.applicationName = props.match?.params?.casApplicationName;
|
2022-04-04 00:09:04 +08:00
|
|
|
}
|
2023-01-19 11:39:24 +01:00
|
|
|
|
|
|
|
this.form = React.createRef();
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
2022-12-22 23:39:02 +08:00
|
|
|
componentDidMount() {
|
2023-03-24 23:17:54 +08:00
|
|
|
if (this.getApplicationObj() === undefined) {
|
|
|
|
if (this.state.type === "login" || this.state.type === "cas" || this.state.type === "saml") {
|
2022-12-22 23:39:02 +08:00
|
|
|
this.getApplication();
|
|
|
|
} else if (this.state.type === "code") {
|
|
|
|
this.getApplicationLogin();
|
|
|
|
} else {
|
|
|
|
Setting.showMessage("error", `Unknown authentication type: ${this.state.type}`);
|
|
|
|
}
|
2021-03-20 11:34:04 +08:00
|
|
|
}
|
2022-12-11 04:22:58 +01:00
|
|
|
}
|
|
|
|
|
2022-10-28 13:38:14 +08:00
|
|
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
2023-03-24 23:17:54 +08:00
|
|
|
if (prevProps.application !== this.props.application) {
|
|
|
|
const captchaProviderItems = this.getCaptchaProviderItems(this.props.application);
|
|
|
|
if (captchaProviderItems) {
|
2023-04-22 16:16:25 +08:00
|
|
|
if (captchaProviderItems.some(providerItem => providerItem.rule === "Always")) {
|
|
|
|
this.setState({enableCaptchaModal: CaptchaRule.Always});
|
|
|
|
} else if (captchaProviderItems.some(providerItem => providerItem.rule === "Dynamic")) {
|
|
|
|
this.setState({enableCaptchaModal: CaptchaRule.Dynamic});
|
|
|
|
} else {
|
|
|
|
this.setState({enableCaptchaModal: CaptchaRule.Never});
|
|
|
|
}
|
2022-10-28 13:38:14 +08:00
|
|
|
}
|
|
|
|
|
2023-03-24 23:17:54 +08:00
|
|
|
if (this.props.account && this.props.account.owner === this.props.application?.organization) {
|
|
|
|
const params = new URLSearchParams(this.props.location.search);
|
|
|
|
const silentSignin = params.get("silentSignin");
|
|
|
|
if (silentSignin !== null) {
|
|
|
|
this.sendSilentSigninData("signing-in");
|
|
|
|
|
|
|
|
const values = {};
|
|
|
|
values["application"] = this.props.application.name;
|
|
|
|
this.login(values);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.get("popup") === "1") {
|
|
|
|
window.addEventListener("beforeunload", () => {
|
|
|
|
this.sendPopupData({type: "windowClosed"}, params.get("redirect_uri"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.props.application.enableAutoSignin) {
|
|
|
|
const values = {};
|
|
|
|
values["application"] = this.props.application.name;
|
|
|
|
this.login(values);
|
|
|
|
}
|
|
|
|
}
|
2022-10-28 13:38:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-22 16:16:25 +08:00
|
|
|
checkCaptchaStatus(values) {
|
|
|
|
AuthBackend.getCaptchaStatus(values)
|
|
|
|
.then((res) => {
|
|
|
|
if (res.status === "ok") {
|
|
|
|
if (res.data) {
|
|
|
|
this.setState({
|
|
|
|
openCaptchaModal: true,
|
|
|
|
values: values,
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.login(values);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-20 11:34:04 +08:00
|
|
|
getApplicationLogin() {
|
2021-03-20 16:51:10 +08:00
|
|
|
const oAuthParams = Util.getOAuthGetParameters();
|
|
|
|
AuthBackend.getApplicationLogin(oAuthParams)
|
2021-03-20 11:34:04 +08:00
|
|
|
.then((res) => {
|
|
|
|
if (res.status === "ok") {
|
2023-03-24 23:17:54 +08:00
|
|
|
const application = res.data;
|
|
|
|
this.onUpdateApplication(application);
|
2021-03-20 11:34:04 +08:00
|
|
|
} else {
|
2022-12-24 17:55:36 +08:00
|
|
|
this.onUpdateApplication(null);
|
2021-03-20 11:34:04 +08:00
|
|
|
this.setState({
|
|
|
|
msg: res.msg,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getApplication() {
|
2021-02-13 23:00:43 +08:00
|
|
|
if (this.state.applicationName === null) {
|
2023-03-24 23:17:54 +08:00
|
|
|
return null;
|
2021-02-13 23:00:43 +08:00
|
|
|
}
|
|
|
|
|
2023-03-24 23:17:54 +08:00
|
|
|
if (this.state.owner === null || this.state.type === "saml") {
|
2022-09-10 20:41:45 +08:00
|
|
|
ApplicationBackend.getApplication("admin", this.state.applicationName)
|
|
|
|
.then((application) => {
|
2022-12-22 23:39:02 +08:00
|
|
|
this.onUpdateApplication(application);
|
2021-02-13 12:15:19 +08:00
|
|
|
});
|
2022-09-10 20:41:45 +08:00
|
|
|
} else {
|
|
|
|
OrganizationBackend.getDefaultApplication("admin", this.state.owner)
|
|
|
|
.then((res) => {
|
|
|
|
if (res.status === "ok") {
|
2023-03-24 23:17:54 +08:00
|
|
|
const application = res.data;
|
|
|
|
this.onUpdateApplication(application);
|
2022-09-10 20:41:45 +08:00
|
|
|
this.setState({
|
|
|
|
applicationName: res.data.name,
|
2023-03-24 23:17:54 +08:00
|
|
|
});
|
2022-09-10 20:41:45 +08:00
|
|
|
} else {
|
2022-12-24 17:55:36 +08:00
|
|
|
this.onUpdateApplication(null);
|
2022-12-02 00:06:28 +08:00
|
|
|
Setting.showMessage("error", res.msg);
|
2022-09-10 20:41:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getApplicationObj() {
|
2023-03-24 23:17:54 +08:00
|
|
|
return this.props.application;
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
2021-06-20 22:17:03 +08:00
|
|
|
onUpdateAccount(account) {
|
|
|
|
this.props.onUpdateAccount(account);
|
|
|
|
}
|
|
|
|
|
2022-12-22 23:39:02 +08:00
|
|
|
onUpdateApplication(application) {
|
|
|
|
this.props.onUpdateApplication(application);
|
|
|
|
}
|
|
|
|
|
2022-10-22 21:43:41 +08:00
|
|
|
parseOffset(offset) {
|
|
|
|
if (offset === 2 || offset === 4 || Setting.inIframe() || Setting.isMobile()) {
|
|
|
|
return "0 auto";
|
|
|
|
}
|
|
|
|
if (offset === 1) {
|
|
|
|
return "0 10%";
|
|
|
|
}
|
|
|
|
if (offset === 3) {
|
|
|
|
return "0 60%";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-25 21:41:52 +08:00
|
|
|
populateOauthValues(values) {
|
2023-03-23 21:38:33 +08:00
|
|
|
if (this.getApplicationObj()?.organization) {
|
|
|
|
values["organization"] = this.getApplicationObj().organization;
|
2022-09-25 21:41:52 +08:00
|
|
|
}
|
|
|
|
|
2023-03-23 21:38:33 +08:00
|
|
|
const oAuthParams = Util.getOAuthGetParameters();
|
2022-09-25 21:41:52 +08:00
|
|
|
|
2023-03-23 21:38:33 +08:00
|
|
|
values["type"] = oAuthParams?.responseType ?? this.state.type;
|
|
|
|
|
|
|
|
if (oAuthParams?.samlRequest) {
|
|
|
|
values["samlRequest"] = oAuthParams.samlRequest;
|
2022-09-25 21:41:52 +08:00
|
|
|
values["type"] = "saml";
|
2022-12-13 22:32:45 +08:00
|
|
|
values["relayState"] = oAuthParams.relayState;
|
2022-09-25 21:41:52 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-16 22:53:28 +08:00
|
|
|
|
2023-03-22 00:15:17 +08:00
|
|
|
sendPopupData(message, redirectUri) {
|
|
|
|
const params = new URLSearchParams(this.props.location.search);
|
|
|
|
if (params.get("popup") === "1") {
|
|
|
|
window.opener.postMessage(message, redirectUri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-25 21:41:52 +08:00
|
|
|
postCodeLoginAction(res) {
|
|
|
|
const application = this.getApplicationObj();
|
|
|
|
const ths = this;
|
|
|
|
const oAuthParams = Util.getOAuthGetParameters();
|
|
|
|
const code = res.data;
|
|
|
|
const concatChar = oAuthParams?.redirectUri?.includes("?") ? "&" : "?";
|
|
|
|
const noRedirect = oAuthParams.noRedirect;
|
|
|
|
if (Setting.hasPromptPage(application)) {
|
|
|
|
AuthBackend.getAccount("")
|
|
|
|
.then((res) => {
|
|
|
|
let account = null;
|
|
|
|
if (res.status === "ok") {
|
|
|
|
account = res.data;
|
|
|
|
account.organization = res.data2;
|
|
|
|
|
|
|
|
this.onUpdateAccount(account);
|
|
|
|
|
|
|
|
if (Setting.isPromptAnswered(account, application)) {
|
|
|
|
Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}code=${code}&state=${oAuthParams.state}`);
|
|
|
|
} else {
|
|
|
|
Setting.goToLinkSoft(ths, `/prompt/${application.name}?redirectUri=${oAuthParams.redirectUri}&code=${code}&state=${oAuthParams.state}`);
|
|
|
|
}
|
|
|
|
} else {
|
2023-03-18 20:42:02 +08:00
|
|
|
Setting.showMessage("error", `${i18next.t("application:Failed to sign in")}: ${res.msg}`);
|
2022-09-25 21:41:52 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (noRedirect === "true") {
|
|
|
|
window.close();
|
|
|
|
const newWindow = window.open(`${oAuthParams.redirectUri}${concatChar}code=${code}&state=${oAuthParams.state}`);
|
|
|
|
if (newWindow) {
|
|
|
|
setInterval(() => {
|
|
|
|
if (!newWindow.closed) {
|
|
|
|
newWindow.close();
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Setting.goToLink(`${oAuthParams.redirectUri}${concatChar}code=${code}&state=${oAuthParams.state}`);
|
2023-03-22 00:15:17 +08:00
|
|
|
this.sendPopupData({type: "loginSuccess", data: {code: code, state: oAuthParams.state}}, oAuthParams.redirectUri);
|
2022-09-25 21:41:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
onFinish(values) {
|
2022-08-05 17:43:04 +08:00
|
|
|
if (this.state.loginMethod === "webAuthn") {
|
|
|
|
let username = this.state.username;
|
|
|
|
if (username === null || username === "") {
|
|
|
|
username = values["username"];
|
|
|
|
}
|
|
|
|
|
2022-09-25 21:41:52 +08:00
|
|
|
this.signInWithWebAuthn(username, values);
|
2022-08-05 17:43:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-04-22 16:16:25 +08:00
|
|
|
if (this.state.loginMethod === "password") {
|
|
|
|
if (this.state.enableCaptchaModal === CaptchaRule.Always) {
|
|
|
|
this.setState({
|
|
|
|
openCaptchaModal: true,
|
|
|
|
values: values,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
} else if (this.state.enableCaptchaModal === CaptchaRule.Dynamic) {
|
|
|
|
this.checkCaptchaStatus(values);
|
|
|
|
return;
|
|
|
|
}
|
2022-10-28 13:38:14 +08:00
|
|
|
}
|
2023-04-22 16:16:25 +08:00
|
|
|
this.login(values);
|
2022-10-28 13:38:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
login(values) {
|
2022-06-14 21:51:40 +08:00
|
|
|
// here we are supposed to determine whether Casdoor is working as an OAuth server or CAS server
|
2022-04-04 00:09:04 +08:00
|
|
|
if (this.state.type === "cas") {
|
2022-06-14 21:51:40 +08:00
|
|
|
// CAS
|
|
|
|
const casParams = Util.getCasParameters();
|
2022-03-01 19:09:59 +08:00
|
|
|
values["type"] = this.state.type;
|
2022-04-04 00:09:04 +08:00
|
|
|
AuthBackend.loginCas(values, casParams).then((res) => {
|
2022-07-10 15:45:55 +08:00
|
|
|
if (res.status === "ok") {
|
2022-06-14 21:51:40 +08:00
|
|
|
let msg = "Logged in successfully. ";
|
2022-04-25 20:00:57 +08:00
|
|
|
if (casParams.service === "") {
|
2022-06-14 21:51:40 +08:00
|
|
|
// If service was not specified, Casdoor must display a message notifying the client that it has successfully initiated a single sign-on session.
|
|
|
|
msg += "Now you can visit apps protected by Casdoor.";
|
2021-03-20 13:05:34 +08:00
|
|
|
}
|
2022-12-02 00:06:28 +08:00
|
|
|
Setting.showMessage("success", msg);
|
2022-06-14 21:51:40 +08:00
|
|
|
|
2022-04-04 00:09:04 +08:00
|
|
|
if (casParams.service !== "") {
|
2022-08-08 23:35:24 +08:00
|
|
|
const st = res.data;
|
|
|
|
const newUrl = new URL(casParams.service);
|
2022-06-14 21:51:40 +08:00
|
|
|
newUrl.searchParams.append("ticket", st);
|
|
|
|
window.location.href = newUrl.toString();
|
2022-04-04 00:09:04 +08:00
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
} else {
|
2023-03-18 20:42:02 +08:00
|
|
|
Setting.showMessage("error", `${i18next.t("application:Failed to sign in")}: ${res.msg}`);
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
2022-07-10 15:45:55 +08:00
|
|
|
});
|
2022-04-04 00:09:04 +08:00
|
|
|
} else {
|
2022-06-14 21:51:40 +08:00
|
|
|
// OAuth
|
2022-04-04 00:09:04 +08:00
|
|
|
const oAuthParams = Util.getOAuthGetParameters();
|
2022-09-25 21:41:52 +08:00
|
|
|
this.populateOauthValues(values);
|
2022-04-04 00:09:04 +08:00
|
|
|
AuthBackend.login(values, oAuthParams)
|
|
|
|
.then((res) => {
|
2022-07-10 15:45:55 +08:00
|
|
|
if (res.status === "ok") {
|
2022-04-04 00:09:04 +08:00
|
|
|
const responseType = values["type"];
|
2022-10-28 13:38:14 +08:00
|
|
|
|
2022-04-04 00:09:04 +08:00
|
|
|
if (responseType === "login") {
|
2022-12-09 15:11:13 +08:00
|
|
|
Setting.showMessage("success", i18next.t("application:Logged in successfully"));
|
2022-04-04 00:09:04 +08:00
|
|
|
|
|
|
|
const link = Setting.getFromLink();
|
|
|
|
Setting.goToLink(link);
|
|
|
|
} else if (responseType === "code") {
|
2022-09-25 21:41:52 +08:00
|
|
|
this.postCodeLoginAction(res);
|
2022-04-04 00:09:04 +08:00
|
|
|
} else if (responseType === "token" || responseType === "id_token") {
|
2023-04-28 23:54:48 +08:00
|
|
|
const amendatoryResponseType = responseType === "token" ? "access_token" : responseType;
|
2022-04-04 00:09:04 +08:00
|
|
|
const accessToken = res.data;
|
2023-04-28 23:54:48 +08:00
|
|
|
Setting.goToLink(`${oAuthParams.redirectUri}#${amendatoryResponseType}=${accessToken}&state=${oAuthParams.state}&token_type=bearer`);
|
2022-04-08 23:06:48 +08:00
|
|
|
} else if (responseType === "saml") {
|
2023-01-03 19:42:12 +08:00
|
|
|
if (res.data2.method === "POST") {
|
2022-12-13 22:32:45 +08:00
|
|
|
this.setState({
|
|
|
|
samlResponse: res.data,
|
2023-01-03 19:42:12 +08:00
|
|
|
redirectUrl: res.data2.redirectUrl,
|
2022-12-13 22:32:45 +08:00
|
|
|
relayState: oAuthParams.relayState,
|
|
|
|
});
|
|
|
|
} else {
|
2023-01-03 19:42:12 +08:00
|
|
|
const SAMLResponse = res.data;
|
|
|
|
const redirectUri = res.data2.redirectUrl;
|
2022-12-13 22:32:45 +08:00
|
|
|
Setting.goToLink(`${redirectUri}?SAMLResponse=${encodeURIComponent(SAMLResponse)}&RelayState=${oAuthParams.relayState}`);
|
|
|
|
}
|
2022-04-04 00:09:04 +08:00
|
|
|
}
|
|
|
|
} else {
|
2023-03-18 20:42:02 +08:00
|
|
|
Setting.showMessage("error", `${i18next.t("application:Failed to sign in")}: ${res.msg}`);
|
2022-04-04 00:09:04 +08:00
|
|
|
}
|
|
|
|
});
|
2022-07-10 15:45:55 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
|
2021-06-14 22:42:58 +08:00
|
|
|
isProviderVisible(providerItem) {
|
|
|
|
if (this.state.mode === "signup") {
|
|
|
|
return Setting.isProviderVisibleForSignUp(providerItem);
|
|
|
|
} else {
|
|
|
|
return Setting.isProviderVisibleForSignIn(providerItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-20 12:29:34 +08:00
|
|
|
renderForm(application) {
|
|
|
|
if (this.state.msg !== null) {
|
2022-07-10 15:45:55 +08:00
|
|
|
return Util.renderMessage(this.state.msg);
|
2021-03-20 11:34:04 +08:00
|
|
|
}
|
|
|
|
|
2021-06-14 22:42:58 +08:00
|
|
|
if (this.state.mode === "signup" && !application.enableSignUp) {
|
|
|
|
return (
|
|
|
|
<Result
|
|
|
|
status="error"
|
2022-11-27 14:04:45 +01:00
|
|
|
title={i18next.t("application:Sign Up Error")}
|
|
|
|
subTitle={i18next.t("application:The application does not allow to sign up new account")}
|
2021-06-14 22:42:58 +08:00
|
|
|
extra={[
|
2023-02-16 22:53:28 +08:00
|
|
|
<Button type="primary" key="signin"
|
|
|
|
onClick={() => Setting.redirectToLoginPage(application, this.props.history)}>
|
2022-10-27 20:23:57 +02:00
|
|
|
{
|
|
|
|
i18next.t("login:Sign In")
|
|
|
|
}
|
|
|
|
</Button>,
|
2021-06-14 22:42:58 +08:00
|
|
|
]}
|
|
|
|
>
|
|
|
|
</Result>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-06-14 22:42:58 +08:00
|
|
|
}
|
|
|
|
|
2021-03-26 21:58:30 +08:00
|
|
|
if (application.enablePassword) {
|
2023-03-02 20:49:13 +08:00
|
|
|
let loginWidth = 320;
|
|
|
|
if (Setting.getLanguage() === "fr") {
|
2023-03-18 20:31:31 +08:00
|
|
|
loginWidth += 20;
|
2023-03-02 20:49:13 +08:00
|
|
|
} else if (Setting.getLanguage() === "es") {
|
|
|
|
loginWidth += 40;
|
2023-03-18 23:05:37 +08:00
|
|
|
} else if (Setting.getLanguage() === "ru") {
|
|
|
|
loginWidth += 10;
|
2023-03-02 20:49:13 +08:00
|
|
|
}
|
|
|
|
|
2021-03-26 21:58:30 +08:00
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
name="normal_login"
|
|
|
|
initialValues={{
|
|
|
|
organization: application.organization,
|
2021-06-20 22:17:03 +08:00
|
|
|
application: application.name,
|
2021-08-06 20:04:08 +08:00
|
|
|
autoSignin: true,
|
2023-02-18 23:39:32 +08:00
|
|
|
username: Conf.ShowGithubCorner ? "admin" : "",
|
|
|
|
password: Conf.ShowGithubCorner ? "123" : "",
|
2021-03-26 21:58:30 +08:00
|
|
|
}}
|
2023-02-16 22:53:28 +08:00
|
|
|
onFinish={(values) => {
|
|
|
|
this.onFinish(values);
|
|
|
|
}}
|
2023-03-02 20:49:13 +08:00
|
|
|
style={{width: `${loginWidth}px`}}
|
2021-03-26 21:58:30 +08:00
|
|
|
size="large"
|
2023-01-19 11:39:24 +01:00
|
|
|
ref={this.form}
|
2021-02-13 12:15:19 +08:00
|
|
|
>
|
2021-06-21 01:01:16 +08:00
|
|
|
<Form.Item
|
2022-12-06 00:50:17 +08:00
|
|
|
hidden={true}
|
2021-06-21 01:01:16 +08:00
|
|
|
name="application"
|
|
|
|
rules={[
|
|
|
|
{
|
|
|
|
required: true,
|
2022-11-27 14:04:45 +01:00
|
|
|
message: i18next.t("application:Please input your application!"),
|
2021-06-21 01:01:16 +08:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
</Form.Item>
|
2021-04-28 21:25:58 +08:00
|
|
|
<Form.Item
|
2022-12-06 00:50:17 +08:00
|
|
|
hidden={true}
|
2021-04-28 21:25:58 +08:00
|
|
|
name="organization"
|
|
|
|
rules={[
|
|
|
|
{
|
|
|
|
required: true,
|
2022-11-27 14:04:45 +01:00
|
|
|
message: i18next.t("application:Please input your organization!"),
|
2021-04-28 21:25:58 +08:00
|
|
|
},
|
|
|
|
]}
|
2021-03-26 21:58:30 +08:00
|
|
|
>
|
2021-02-13 12:15:19 +08:00
|
|
|
</Form.Item>
|
2022-07-12 20:06:01 +08:00
|
|
|
{this.renderMethodChoiceBox()}
|
2022-09-12 00:01:18 +08:00
|
|
|
<Row style={{minHeight: 130, alignItems: "center"}}>
|
|
|
|
<Col span={24}>
|
|
|
|
<Form.Item
|
|
|
|
name="username"
|
|
|
|
rules={[
|
|
|
|
{
|
|
|
|
required: true,
|
2023-02-12 18:56:56 +08:00
|
|
|
message: i18next.t("login:Please input your Email or Phone!"),
|
2022-09-12 00:01:18 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
validator: (_, value) => {
|
2022-10-03 15:10:48 +08:00
|
|
|
if (this.state.loginMethod === "verificationCode") {
|
2023-03-13 17:48:58 +08:00
|
|
|
if (!Setting.isValidEmail(value) && !Setting.isValidPhone(value)) {
|
2022-09-12 00:01:18 +08:00
|
|
|
this.setState({validEmailOrPhone: false});
|
2023-03-18 10:16:35 +08:00
|
|
|
return Promise.reject(i18next.t("login:The input is not valid Email or phone number!"));
|
2022-09-12 00:01:18 +08:00
|
|
|
}
|
|
|
|
|
2023-03-13 17:48:58 +08:00
|
|
|
if (Setting.isValidEmail(value)) {
|
2022-09-12 00:01:18 +08:00
|
|
|
this.setState({validEmail: true});
|
2023-03-13 17:48:58 +08:00
|
|
|
} else {
|
|
|
|
this.setState({validEmail: false});
|
2022-09-12 00:01:18 +08:00
|
|
|
}
|
|
|
|
}
|
2022-07-12 20:06:01 +08:00
|
|
|
|
2022-09-12 00:01:18 +08:00
|
|
|
this.setState({validEmailOrPhone: true});
|
|
|
|
return Promise.resolve();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<Input
|
2023-02-16 22:53:28 +08:00
|
|
|
id="input"
|
2022-09-12 00:01:18 +08:00
|
|
|
prefix={<UserOutlined className="site-form-item-icon" />}
|
2022-10-03 15:10:48 +08:00
|
|
|
placeholder={(this.state.loginMethod === "verificationCode") ? i18next.t("login:Email or phone") : i18next.t("login:username, Email or phone")}
|
2022-09-12 00:01:18 +08:00
|
|
|
disabled={!application.enablePassword}
|
|
|
|
onChange={e => {
|
|
|
|
this.setState({
|
|
|
|
username: e.target.value,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
{
|
|
|
|
this.renderPasswordOrCodeInput()
|
|
|
|
}
|
|
|
|
</Row>
|
2023-03-26 18:44:47 +08:00
|
|
|
<div style={{display: "inline-flex", justifyContent: "space-between", width: "320px", marginBottom: AgreementModal.isAgreementRequired(application) ? "5px" : "25px"}}>
|
|
|
|
<Form.Item name="autoSignin" valuePropName="checked" noStyle>
|
|
|
|
<Checkbox style={{float: "left"}} disabled={!application.enablePassword}>
|
|
|
|
{i18next.t("login:Auto sign in")}
|
|
|
|
</Checkbox>
|
|
|
|
</Form.Item>
|
2022-10-22 17:17:50 +02:00
|
|
|
{
|
|
|
|
Setting.renderForgetLink(application, i18next.t("login:Forgot password?"))
|
|
|
|
}
|
2023-03-26 18:44:47 +08:00
|
|
|
</div>
|
|
|
|
{AgreementModal.isAgreementRequired(application) ? AgreementModal.renderAgreementFormItem(application, true, {}, this) : null}
|
2021-03-26 21:58:30 +08:00
|
|
|
<Form.Item>
|
2022-10-03 15:10:48 +08:00
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
htmlType="submit"
|
|
|
|
style={{width: "100%", marginBottom: "5px"}}
|
|
|
|
disabled={!application.enablePassword}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
this.state.loginMethod === "webAuthn" ? i18next.t("login:Sign in with WebAuthn") :
|
|
|
|
i18next.t("login:Sign In")
|
|
|
|
}
|
|
|
|
</Button>
|
2022-10-28 13:38:14 +08:00
|
|
|
{
|
|
|
|
this.renderCaptchaModal(application)
|
|
|
|
}
|
2021-03-26 21:58:30 +08:00
|
|
|
{
|
2022-07-28 23:11:33 +08:00
|
|
|
this.renderFooter(application)
|
2021-03-26 21:58:30 +08:00
|
|
|
}
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item>
|
|
|
|
{
|
2021-06-14 22:42:58 +08:00
|
|
|
application.providers.filter(providerItem => this.isProviderVisible(providerItem)).map(providerItem => {
|
2022-09-28 21:09:39 +08:00
|
|
|
return ProviderButton.renderProviderLogo(providerItem.provider, application, 30, 5, "small", this.props.location);
|
2021-03-26 21:58:30 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div style={{marginTop: "20px"}}>
|
2021-03-28 19:15:10 +08:00
|
|
|
<div style={{fontSize: 16, textAlign: "left"}}>
|
2021-06-11 20:33:22 +08:00
|
|
|
{i18next.t("login:To access")}
|
2021-03-27 11:38:15 +08:00
|
|
|
<a target="_blank" rel="noreferrer" href={application.homepageUrl}>
|
2021-03-29 22:11:28 +08:00
|
|
|
<span style={{fontWeight: "bold"}}>
|
|
|
|
{application.displayName}
|
|
|
|
</span>
|
2021-03-26 21:58:30 +08:00
|
|
|
</a>
|
2022-12-06 00:50:17 +08:00
|
|
|
:
|
2021-02-13 12:15:19 +08:00
|
|
|
</div>
|
2022-07-10 15:45:55 +08:00
|
|
|
<br />
|
2021-02-13 23:00:43 +08:00
|
|
|
{
|
2021-06-14 22:42:58 +08:00
|
|
|
application.providers.filter(providerItem => this.isProviderVisible(providerItem)).map(providerItem => {
|
2022-09-28 21:09:39 +08:00
|
|
|
return ProviderButton.renderProviderLogo(providerItem.provider, application, 40, 10, "big", this.props.location);
|
2021-02-13 23:00:43 +08:00
|
|
|
})
|
|
|
|
}
|
2022-07-28 23:11:33 +08:00
|
|
|
<div>
|
|
|
|
<br />
|
|
|
|
{
|
|
|
|
this.renderFooter(application)
|
|
|
|
}
|
|
|
|
</div>
|
2021-03-26 21:58:30 +08:00
|
|
|
</div>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-03-26 21:58:30 +08:00
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
2023-03-05 20:31:46 +08:00
|
|
|
getCaptchaProviderItems(application) {
|
2022-10-28 13:38:14 +08:00
|
|
|
const providers = application?.providers;
|
|
|
|
|
|
|
|
if (providers === undefined || providers === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return providers.filter(providerItem => {
|
|
|
|
if (providerItem.provider === undefined || providerItem.provider === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-05 20:31:46 +08:00
|
|
|
return providerItem.provider.category === "Captcha";
|
2022-10-28 13:38:14 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderCaptchaModal(application) {
|
2023-04-22 16:16:25 +08:00
|
|
|
if (this.state.enableCaptchaModal === CaptchaRule.Never) {
|
2022-10-28 13:38:14 +08:00
|
|
|
return null;
|
|
|
|
}
|
2023-04-22 16:16:25 +08:00
|
|
|
const captchaProviderItems = this.getCaptchaProviderItems(application);
|
|
|
|
const alwaysProviderItems = captchaProviderItems.filter(providerItem => providerItem.rule === "Always");
|
|
|
|
const dynamicProviderItems = captchaProviderItems.filter(providerItem => providerItem.rule === "Dynamic");
|
|
|
|
const provider = alwaysProviderItems.length > 0
|
|
|
|
? alwaysProviderItems[0].provider
|
|
|
|
: dynamicProviderItems[0].provider;
|
2022-10-28 13:38:14 +08:00
|
|
|
|
|
|
|
return <CaptchaModal
|
|
|
|
owner={provider.owner}
|
|
|
|
name={provider.name}
|
2023-03-05 20:31:46 +08:00
|
|
|
visible={this.state.openCaptchaModal}
|
|
|
|
onOk={(captchaType, captchaToken, clientSecret) => {
|
|
|
|
const values = this.state.values;
|
|
|
|
values["captchaType"] = captchaType;
|
|
|
|
values["captchaToken"] = captchaToken;
|
|
|
|
values["clientSecret"] = clientSecret;
|
|
|
|
|
|
|
|
this.login(values);
|
|
|
|
this.setState({openCaptchaModal: false});
|
|
|
|
}}
|
|
|
|
onCancel={() => this.setState({openCaptchaModal: false})}
|
|
|
|
isCurrentProvider={true}
|
2022-10-28 13:38:14 +08:00
|
|
|
/>;
|
|
|
|
}
|
|
|
|
|
2021-06-14 22:42:58 +08:00
|
|
|
renderFooter(application) {
|
2023-04-22 18:20:45 +08:00
|
|
|
return (
|
|
|
|
<span style={{float: "right"}}>
|
|
|
|
{
|
|
|
|
!application.enableSignUp ? null : (
|
|
|
|
<React.Fragment>
|
|
|
|
{i18next.t("login:No account?")}
|
|
|
|
{
|
|
|
|
Setting.renderSignupLink(application, i18next.t("login:sign up now"))
|
|
|
|
}
|
|
|
|
</React.Fragment>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</span>
|
|
|
|
);
|
2021-06-14 22:42:58 +08:00
|
|
|
}
|
|
|
|
|
2022-09-30 01:51:58 +08:00
|
|
|
sendSilentSigninData(data) {
|
|
|
|
if (Setting.inIframe()) {
|
|
|
|
const message = {tag: "Casdoor", type: "SilentSignin", data: data};
|
|
|
|
window.parent.postMessage(message, "*");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 21:15:57 +08:00
|
|
|
renderSignedInBox() {
|
|
|
|
if (this.props.account === undefined || this.props.account === null) {
|
2022-09-30 01:51:58 +08:00
|
|
|
this.sendSilentSigninData("user-not-logged-in");
|
2021-10-09 21:15:57 +08:00
|
|
|
return null;
|
|
|
|
}
|
2022-09-30 01:51:58 +08:00
|
|
|
|
2022-08-08 23:35:24 +08:00
|
|
|
const application = this.getApplicationObj();
|
2023-03-24 23:17:54 +08:00
|
|
|
if (this.props.account.owner !== application?.organization) {
|
2021-11-11 20:43:26 +08:00
|
|
|
return null;
|
|
|
|
}
|
2021-10-09 21:15:57 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div style={{fontSize: 16, textAlign: "left"}}>
|
|
|
|
{i18next.t("login:Continue with")} :
|
|
|
|
</div>
|
2022-07-10 15:45:55 +08:00
|
|
|
<br />
|
2021-10-09 21:15:57 +08:00
|
|
|
<SelfLoginButton account={this.props.account} onClick={() => {
|
2022-08-08 23:35:24 +08:00
|
|
|
const values = {};
|
2023-01-03 19:42:12 +08:00
|
|
|
values["application"] = application.name;
|
2023-03-24 23:17:54 +08:00
|
|
|
this.login(values);
|
2021-10-09 21:15:57 +08:00
|
|
|
}} />
|
2022-07-10 15:45:55 +08:00
|
|
|
<br />
|
|
|
|
<br />
|
2021-10-09 21:15:57 +08:00
|
|
|
<div style={{fontSize: 16, textAlign: "left"}}>
|
|
|
|
{i18next.t("login:Or sign in with another account")} :
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-10-09 21:15:57 +08:00
|
|
|
}
|
|
|
|
|
2022-09-25 21:41:52 +08:00
|
|
|
signInWithWebAuthn(username, values) {
|
|
|
|
const oAuthParams = Util.getOAuthGetParameters();
|
|
|
|
this.populateOauthValues(values);
|
2022-08-08 23:35:24 +08:00
|
|
|
const application = this.getApplicationObj();
|
2022-08-05 17:43:04 +08:00
|
|
|
return fetch(`${Setting.ServerUrl}/api/webauthn/signin/begin?owner=${application.organization}&name=${username}`, {
|
2022-07-12 20:06:01 +08:00
|
|
|
method: "GET",
|
2022-08-06 23:54:56 +08:00
|
|
|
credentials: "include",
|
2022-07-12 20:06:01 +08:00
|
|
|
})
|
|
|
|
.then(res => res.json())
|
|
|
|
.then((credentialRequestOptions) => {
|
|
|
|
if ("status" in credentialRequestOptions) {
|
|
|
|
Setting.showMessage("error", credentialRequestOptions.msg);
|
|
|
|
throw credentialRequestOptions.status.msg;
|
|
|
|
}
|
|
|
|
|
2022-08-05 17:43:04 +08:00
|
|
|
credentialRequestOptions.publicKey.challenge = UserWebauthnBackend.webAuthnBufferDecode(credentialRequestOptions.publicKey.challenge);
|
|
|
|
credentialRequestOptions.publicKey.allowCredentials.forEach(function(listItem) {
|
2022-07-12 20:06:01 +08:00
|
|
|
listItem.id = UserWebauthnBackend.webAuthnBufferDecode(listItem.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
return navigator.credentials.get({
|
2022-08-06 23:54:56 +08:00
|
|
|
publicKey: credentialRequestOptions.publicKey,
|
2022-07-12 20:45:22 +08:00
|
|
|
});
|
2022-07-12 20:06:01 +08:00
|
|
|
})
|
|
|
|
.then((assertion) => {
|
2022-08-08 23:35:24 +08:00
|
|
|
const authData = assertion.response.authenticatorData;
|
|
|
|
const clientDataJSON = assertion.response.clientDataJSON;
|
|
|
|
const rawId = assertion.rawId;
|
|
|
|
const sig = assertion.response.signature;
|
|
|
|
const userHandle = assertion.response.userHandle;
|
2022-12-13 16:57:42 +08:00
|
|
|
return fetch(`${Setting.ServerUrl}/api/webauthn/signin/finish?responseType=${values["type"]}`, {
|
2022-07-12 20:06:01 +08:00
|
|
|
method: "POST",
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify({
|
|
|
|
id: assertion.id,
|
|
|
|
rawId: UserWebauthnBackend.webAuthnBufferEncode(rawId),
|
|
|
|
type: assertion.type,
|
|
|
|
response: {
|
|
|
|
authenticatorData: UserWebauthnBackend.webAuthnBufferEncode(authData),
|
|
|
|
clientDataJSON: UserWebauthnBackend.webAuthnBufferEncode(clientDataJSON),
|
|
|
|
signature: UserWebauthnBackend.webAuthnBufferEncode(sig),
|
|
|
|
userHandle: UserWebauthnBackend.webAuthnBufferEncode(userHandle),
|
|
|
|
},
|
2022-08-06 23:54:56 +08:00
|
|
|
}),
|
2022-07-12 20:06:01 +08:00
|
|
|
})
|
|
|
|
.then(res => res.json()).then((res) => {
|
2022-12-02 00:06:28 +08:00
|
|
|
if (res.status === "ok") {
|
2022-09-25 21:41:52 +08:00
|
|
|
const responseType = values["type"];
|
|
|
|
if (responseType === "code") {
|
|
|
|
this.postCodeLoginAction(res);
|
|
|
|
} else if (responseType === "token" || responseType === "id_token") {
|
|
|
|
const accessToken = res.data;
|
|
|
|
Setting.goToLink(`${oAuthParams.redirectUri}#${responseType}=${accessToken}?state=${oAuthParams.state}&token_type=bearer`);
|
|
|
|
} else {
|
2023-03-18 10:16:35 +08:00
|
|
|
Setting.showMessage("success", i18next.t("login:Successfully logged in with WebAuthn credentials"));
|
2022-09-25 21:41:52 +08:00
|
|
|
Setting.goToLink("/");
|
|
|
|
}
|
2022-07-12 20:06:01 +08:00
|
|
|
} else {
|
|
|
|
Setting.showMessage("error", res.msg);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2022-12-02 00:06:28 +08:00
|
|
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}${error}`);
|
2022-07-12 20:06:01 +08:00
|
|
|
});
|
2022-07-12 20:45:22 +08:00
|
|
|
});
|
2022-07-12 20:06:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
renderPasswordOrCodeInput() {
|
2022-08-08 23:35:24 +08:00
|
|
|
const application = this.getApplicationObj();
|
2022-07-12 20:06:01 +08:00
|
|
|
if (this.state.loginMethod === "password") {
|
2022-10-03 15:10:48 +08:00
|
|
|
return (
|
2022-09-12 00:01:18 +08:00
|
|
|
<Col span={24}>
|
|
|
|
<Form.Item
|
|
|
|
name="password"
|
|
|
|
rules={[{required: true, message: i18next.t("login:Please input your password!")}]}
|
|
|
|
>
|
2022-10-03 15:10:48 +08:00
|
|
|
<Input.Password
|
2022-09-12 00:01:18 +08:00
|
|
|
prefix={<LockOutlined className="site-form-item-icon" />}
|
|
|
|
type="password"
|
2023-03-19 01:01:39 +08:00
|
|
|
placeholder={i18next.t("general:Password")}
|
2022-09-12 00:01:18 +08:00
|
|
|
disabled={!application.enablePassword}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
2022-07-12 20:45:22 +08:00
|
|
|
);
|
2022-10-03 15:10:48 +08:00
|
|
|
} else if (this.state.loginMethod === "verificationCode") {
|
|
|
|
return (
|
|
|
|
<Col span={24}>
|
|
|
|
<Form.Item
|
|
|
|
name="code"
|
|
|
|
rules={[{required: true, message: i18next.t("login:Please input your code!")}]}
|
|
|
|
>
|
2023-02-12 18:56:56 +08:00
|
|
|
<SendCodeInput
|
2022-10-03 15:10:48 +08:00
|
|
|
disabled={this.state.username?.length === 0 || !this.state.validEmailOrPhone}
|
2022-12-11 15:52:36 +08:00
|
|
|
method={"login"}
|
2022-10-03 15:10:48 +08:00
|
|
|
onButtonClickArgs={[this.state.username, this.state.validEmail ? "email" : "phone", Setting.getApplicationName(application)]}
|
|
|
|
application={application}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
2022-07-12 20:06:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-12 20:45:22 +08:00
|
|
|
renderMethodChoiceBox() {
|
2022-08-08 23:35:24 +08:00
|
|
|
const application = this.getApplicationObj();
|
2023-04-22 18:20:45 +08:00
|
|
|
const items = [];
|
|
|
|
items.push({label: i18next.t("general:Password"), key: "password"});
|
|
|
|
application.enableCodeSignin ? items.push({label: i18next.t("login:Verification code"), key: "verificationCode"}) : null;
|
2022-12-04 23:05:30 +08:00
|
|
|
application.enableWebAuthn ? items.push({label: i18next.t("login:WebAuthn"), key: "webAuthn"}) : null;
|
|
|
|
|
2022-10-03 15:10:48 +08:00
|
|
|
if (application.enableCodeSignin || application.enableWebAuthn) {
|
2022-07-12 20:06:01 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2023-02-16 22:53:28 +08:00
|
|
|
<Tabs items={items} size={"small"} defaultActiveKey="password" onChange={(key) => {
|
|
|
|
this.setState({loginMethod: key});
|
|
|
|
}} centered>
|
2022-07-12 20:06:01 +08:00
|
|
|
</Tabs>
|
|
|
|
</div>
|
2022-07-12 20:45:22 +08:00
|
|
|
);
|
2022-07-12 20:06:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
render() {
|
|
|
|
const application = this.getApplicationObj();
|
2023-03-24 23:17:54 +08:00
|
|
|
if (application === undefined) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
if (application === null) {
|
2021-03-26 21:58:19 +08:00
|
|
|
return Util.renderMessageLarge(this, this.state.msg);
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
2022-12-13 22:32:45 +08:00
|
|
|
if (this.state.samlResponse !== "") {
|
|
|
|
return <RedirectForm samlResponse={this.state.samlResponse} redirectUrl={this.state.redirectUrl} relayState={this.state.relayState} />;
|
|
|
|
}
|
|
|
|
|
2021-10-26 13:11:21 +08:00
|
|
|
if (application.signinHtml !== "") {
|
|
|
|
return (
|
2022-07-10 15:45:55 +08:00
|
|
|
<div dangerouslySetInnerHTML={{__html: application.signinHtml}} />
|
|
|
|
);
|
2021-10-26 13:11:21 +08:00
|
|
|
}
|
|
|
|
|
2021-08-07 00:14:24 +08:00
|
|
|
const visibleOAuthProviderItems = application.providers.filter(providerItem => this.isProviderVisible(providerItem));
|
2023-04-17 00:38:48 +08:00
|
|
|
if (this.props.preview !== "auto" && !application.enablePassword && visibleOAuthProviderItems.length === 1) {
|
2021-08-07 00:14:24 +08:00
|
|
|
Setting.goToLink(Provider.getAuthUrl(application, visibleOAuthProviderItems[0].provider, "signup"));
|
|
|
|
return (
|
2023-04-17 00:38:48 +08:00
|
|
|
<div style={{display: "flex", justifyContent: "center", alignItems: "center", width: "100%"}}>
|
|
|
|
<Spin size="large" tip={i18next.t("login:Signing in...")} />
|
2021-08-07 00:14:24 +08:00
|
|
|
</div>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-08-07 00:14:24 +08:00
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
return (
|
2022-12-22 23:39:02 +08:00
|
|
|
<React.Fragment>
|
2022-09-12 00:01:18 +08:00
|
|
|
<CustomGithubCorner />
|
2022-12-24 17:47:05 +08:00
|
|
|
<div className="login-content" style={{margin: this.props.preview ?? this.parseOffset(application.formOffset)}}>
|
2022-12-04 15:53:46 +08:00
|
|
|
{Setting.inIframe() || Setting.isMobile() ? null : <div dangerouslySetInnerHTML={{__html: application.formCss}} />}
|
2022-10-22 21:43:41 +08:00
|
|
|
<div className="login-panel">
|
|
|
|
<div className="side-image" style={{display: application.formOffset !== 4 ? "none" : null}}>
|
|
|
|
<div dangerouslySetInnerHTML={{__html: application.formSideHtml}} />
|
|
|
|
</div>
|
|
|
|
<div className="login-form">
|
2023-02-16 22:53:28 +08:00
|
|
|
<div>
|
2022-10-03 22:40:19 +08:00
|
|
|
<div>
|
|
|
|
{
|
|
|
|
Setting.renderHelmet(application)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Setting.renderLogo(application)
|
|
|
|
}
|
2023-03-26 18:44:47 +08:00
|
|
|
<LanguageSelect languages={application.organizationObj.languages} style={{top: "55px", right: "5px", position: "absolute"}} />
|
2022-10-03 22:40:19 +08:00
|
|
|
{
|
|
|
|
this.renderSignedInBox()
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this.renderForm(application)
|
|
|
|
}
|
|
|
|
</div>
|
2022-09-12 00:01:18 +08:00
|
|
|
</div>
|
2022-09-10 00:56:37 +08:00
|
|
|
</div>
|
2022-10-22 21:43:41 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-12-22 23:39:02 +08:00
|
|
|
</React.Fragment>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 22:11:19 +08:00
|
|
|
export default LoginPage;
|