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";
|
2021-06-14 22:42:58 +08:00
|
|
|
import {Link} from "react-router-dom";
|
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";
|
2021-02-14 15:40:57 +08:00
|
|
|
import * as AuthBackend from "./AuthBackend";
|
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";
|
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";
|
2021-10-09 21:15:57 +08:00
|
|
|
import SelfLoginButton from "./SelfLoginButton";
|
2021-06-14 23:43:09 +08:00
|
|
|
import {GithubLoginButton, GoogleLoginButton} from "react-social-login-buttons";
|
2021-06-14 23:29:22 +08:00
|
|
|
import FacebookLoginButton from "./FacebookLoginButton";
|
2021-03-29 22:11:28 +08:00
|
|
|
import QqLoginButton from "./QqLoginButton";
|
2021-06-14 23:29:22 +08:00
|
|
|
import DingTalkLoginButton from "./DingTalkLoginButton";
|
|
|
|
import GiteeLoginButton from "./GiteeLoginButton";
|
|
|
|
import WechatLoginButton from "./WechatLoginButton";
|
|
|
|
import WeiboLoginButton from "./WeiboLoginButton";
|
2021-04-27 22:03:22 +08:00
|
|
|
import i18next from "i18next";
|
2021-08-01 22:10:47 +08:00
|
|
|
import LinkedInLoginButton from "./LinkedInLoginButton";
|
|
|
|
import WeComLoginButton from "./WeComLoginButton";
|
2021-08-14 16:00:38 +08:00
|
|
|
import LarkLoginButton from "./LarkLoginButton";
|
2021-08-19 21:03:57 +08:00
|
|
|
import GitLabLoginButton from "./GitLabLoginButton";
|
2022-02-20 15:01:48 +08:00
|
|
|
import AdfsLoginButton from "./AdfsLoginButton";
|
2022-01-22 19:36:44 +08:00
|
|
|
import BaiduLoginButton from "./BaiduLoginButton";
|
2022-04-02 22:37:13 +08:00
|
|
|
import AlipayLoginButton from "./AlipayLoginButton";
|
2022-03-18 18:28:46 +08:00
|
|
|
import CasdoorLoginButton from "./CasdoorLoginButton";
|
2022-02-05 21:54:38 +08:00
|
|
|
import InfoflowLoginButton from "./InfoflowLoginButton";
|
2022-07-10 15:45:55 +08:00
|
|
|
import AppleLoginButton from "./AppleLoginButton";
|
2021-12-10 00:55:27 +08:00
|
|
|
import AzureADLoginButton from "./AzureADLoginButton";
|
|
|
|
import SlackLoginButton from "./SlackLoginButton";
|
2022-02-16 19:57:46 +08:00
|
|
|
import SteamLoginButton from "./SteamLoginButton";
|
2022-05-01 18:31:42 +08:00
|
|
|
import OktaLoginButton from "./OktaLoginButton";
|
2022-05-15 20:59:21 +08:00
|
|
|
import DouyinLoginButton from "./DouyinLoginButton";
|
2021-11-06 22:04:20 +08:00
|
|
|
import CustomGithubCorner from "../CustomGithubCorner";
|
2022-01-07 20:34:27 +08:00
|
|
|
import {CountDownInput} from "../common/CountDownInput";
|
2022-05-12 10:07:52 +08:00
|
|
|
import BilibiliLoginButton from "./BilibiliLoginButton";
|
2021-02-13 12:15:19 +08:00
|
|
|
|
2022-07-12 20:45:22 +08:00
|
|
|
const {TabPane} = Tabs;
|
2022-07-12 20:06:01 +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,
|
2021-02-13 12:15:19 +08:00
|
|
|
applicationName: props.applicationName !== undefined ? props.applicationName : (props.match === undefined ? null : props.match.params.applicationName),
|
2022-04-08 23:06:48 +08:00
|
|
|
owner : props.owner !== undefined ? props.owner : (props.match === undefined ? null : props.match.params.owner),
|
2021-02-13 12:15:19 +08:00
|
|
|
application: null,
|
2021-06-14 22:42:58 +08:00
|
|
|
mode: props.mode !== undefined ? props.mode : (props.match === undefined ? null : props.match.params.mode), // "signup" or "signin"
|
2021-11-28 21:10:21 +08:00
|
|
|
isCodeSignin: false,
|
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,
|
|
|
|
validPhone: false,
|
2022-07-12 20:06:01 +08:00
|
|
|
loginMethod: "password"
|
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) {
|
2022-07-10 15:45:55 +08:00
|
|
|
this.state.owner = props.match?.params.owner;
|
|
|
|
this.state.applicationName = props.match?.params.casApplicationName;
|
2022-04-04 00:09:04 +08:00
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
2021-03-27 11:38:15 +08:00
|
|
|
UNSAFE_componentWillMount() {
|
2022-04-04 00:09:04 +08:00
|
|
|
if (this.state.type === "login" || this.state.type === "cas") {
|
2021-03-20 11:34:04 +08:00
|
|
|
this.getApplication();
|
|
|
|
} else if (this.state.type === "code") {
|
|
|
|
this.getApplicationLogin();
|
2022-07-10 15:45:55 +08:00
|
|
|
} else if (this.state.type === "saml") {
|
2022-04-08 23:06:48 +08:00
|
|
|
this.getSamlApplication();
|
2021-03-20 11:34:04 +08:00
|
|
|
} else {
|
|
|
|
Util.showMessage("error", `Unknown authentication type: ${this.state.type}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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") {
|
|
|
|
this.setState({
|
|
|
|
application: res.data,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Util.showMessage("error", res.msg);
|
|
|
|
this.setState({
|
|
|
|
application: res.data,
|
|
|
|
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) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-19 01:14:41 +08:00
|
|
|
ApplicationBackend.getApplication("admin", this.state.applicationName)
|
2021-02-13 12:15:19 +08:00
|
|
|
.then((application) => {
|
|
|
|
this.setState({
|
|
|
|
application: application,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-10 15:45:55 +08:00
|
|
|
getSamlApplication() {
|
|
|
|
if (this.state.applicationName === null) {
|
2022-04-08 23:06:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ApplicationBackend.getApplication(this.state.owner, this.state.applicationName)
|
|
|
|
.then((application) => {
|
|
|
|
this.setState({
|
|
|
|
application: application,
|
|
|
|
});
|
|
|
|
}
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2022-04-08 23:06:48 +08:00
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
getApplicationObj() {
|
|
|
|
if (this.props.application !== undefined) {
|
|
|
|
return this.props.application;
|
|
|
|
} else {
|
|
|
|
return this.state.application;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-20 22:17:03 +08:00
|
|
|
onUpdateAccount(account) {
|
|
|
|
this.props.onUpdateAccount(account);
|
|
|
|
}
|
|
|
|
|
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"];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.signInWithWebAuthn(username);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-20 22:17:03 +08:00
|
|
|
const application = this.getApplicationObj();
|
|
|
|
const ths = this;
|
2022-04-04 00:09:04 +08:00
|
|
|
|
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-04-04 00:09:04 +08:00
|
|
|
Util.showMessage("success", msg);
|
2022-06-14 21:51:40 +08:00
|
|
|
|
2022-04-04 00:09:04 +08:00
|
|
|
if (casParams.service !== "") {
|
2022-06-14 21:51:40 +08:00
|
|
|
let st = res.data;
|
|
|
|
let newUrl = new URL(casParams.service);
|
|
|
|
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 {
|
2021-03-26 21:57:41 +08:00
|
|
|
Util.showMessage("error", `Failed to log 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();
|
|
|
|
if (oAuthParams !== null && oAuthParams.responseType != null && oAuthParams.responseType !== "") {
|
2022-06-14 21:51:40 +08:00
|
|
|
values["type"] = oAuthParams.responseType;
|
|
|
|
} else {
|
2022-04-04 00:09:04 +08:00
|
|
|
values["type"] = this.state.type;
|
|
|
|
}
|
|
|
|
values["phonePrefix"] = this.getApplicationObj()?.organizationObj.phonePrefix;
|
2022-04-08 23:06:48 +08:00
|
|
|
|
2022-06-14 21:51:40 +08:00
|
|
|
if (oAuthParams !== null) {
|
2022-04-08 23:06:48 +08:00
|
|
|
values["samlRequest"] = oAuthParams.samlRequest;
|
|
|
|
}
|
2022-06-14 21:51:40 +08:00
|
|
|
|
2022-04-08 23:06:48 +08:00
|
|
|
if (values["samlRequest"] != null && values["samlRequest"] !== "") {
|
2022-07-10 15:45:55 +08:00
|
|
|
values["type"] = "saml";
|
2022-04-08 23:06:48 +08:00
|
|
|
}
|
2022-06-14 21:51:40 +08:00
|
|
|
|
2022-07-26 19:27:24 +08:00
|
|
|
if (this.state.owner != null) {
|
|
|
|
values["organization"] = this.state.owner;
|
|
|
|
}
|
|
|
|
|
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"];
|
|
|
|
if (responseType === "login") {
|
2022-07-10 15:45:55 +08:00
|
|
|
Util.showMessage("success", "Logged in successfully");
|
2022-04-04 00:09:04 +08:00
|
|
|
|
|
|
|
const link = Setting.getFromLink();
|
|
|
|
Setting.goToLink(link);
|
|
|
|
} else if (responseType === "code") {
|
|
|
|
const code = res.data;
|
2022-07-10 15:45:55 +08:00
|
|
|
const concatChar = oAuthParams?.redirectUri?.includes("?") ? "&" : "?";
|
2022-07-26 23:03:55 +08:00
|
|
|
const noRedirect = oAuthParams.noRedirect;
|
2022-04-04 00:09:04 +08:00
|
|
|
|
|
|
|
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 {
|
|
|
|
Setting.showMessage("error", `Failed to sign in: ${res.msg}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2022-07-26 23:03:55 +08:00
|
|
|
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}`);
|
|
|
|
}
|
2022-04-04 00:09:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Util.showMessage("success", `Authorization code: ${res.data}`);
|
|
|
|
} else if (responseType === "token" || responseType === "id_token") {
|
|
|
|
const accessToken = res.data;
|
|
|
|
Setting.goToLink(`${oAuthParams.redirectUri}#${responseType}=${accessToken}?state=${oAuthParams.state}&token_type=bearer`);
|
2022-04-08 23:06:48 +08:00
|
|
|
} else if (responseType === "saml") {
|
|
|
|
const SAMLResponse = res.data;
|
|
|
|
const redirectUri = res.data2;
|
|
|
|
Setting.goToLink(`${redirectUri}?SAMLResponse=${encodeURIComponent(SAMLResponse)}&RelayState=${oAuthParams.relayState}`);
|
2022-04-04 00:09:04 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Util.showMessage("error", `Failed to log in: ${res.msg}`);
|
|
|
|
}
|
|
|
|
});
|
2022-07-10 15:45:55 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
|
2021-06-11 20:33:22 +08:00
|
|
|
getSigninButton(type) {
|
|
|
|
const text = i18next.t("login:Sign in with {type}").replace("{type}", type);
|
2021-03-29 22:11:28 +08:00
|
|
|
if (type === "GitHub") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <GithubLoginButton text={text} align={"center"} />;
|
2021-03-29 22:11:28 +08:00
|
|
|
} else if (type === "Google") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <GoogleLoginButton text={text} align={"center"} />;
|
2021-03-29 22:11:28 +08:00
|
|
|
} else if (type === "QQ") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <QqLoginButton text={text} align={"center"} />;
|
2021-06-14 23:29:22 +08:00
|
|
|
} else if (type === "Facebook") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <FacebookLoginButton text={text} align={"center"} />;
|
2021-06-14 23:29:22 +08:00
|
|
|
} else if (type === "Weibo") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <WeiboLoginButton text={text} align={"center"} />;
|
2021-06-14 23:29:22 +08:00
|
|
|
} else if (type === "Gitee") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <GiteeLoginButton text={text} align={"center"} />;
|
2021-06-14 23:29:22 +08:00
|
|
|
} else if (type === "WeChat") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <WechatLoginButton text={text} align={"center"} />;
|
2021-06-14 23:29:22 +08:00
|
|
|
} else if (type === "DingTalk") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <DingTalkLoginButton text={text} align={"center"} />;
|
|
|
|
} else if (type === "LinkedIn") {
|
|
|
|
return <LinkedInLoginButton text={text} align={"center"} />;
|
2021-08-01 22:10:47 +08:00
|
|
|
} else if (type === "WeCom") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <WeComLoginButton text={text} align={"center"} />;
|
2021-08-14 16:00:38 +08:00
|
|
|
} else if (type === "Lark") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <LarkLoginButton text={text} align={"center"} />;
|
2021-08-19 21:03:57 +08:00
|
|
|
} else if (type === "GitLab") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <GitLabLoginButton text={text} align={"center"} />;
|
2022-02-20 15:01:48 +08:00
|
|
|
} else if (type === "Adfs") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <AdfsLoginButton text={text} align={"center"} />;
|
2022-03-18 18:28:46 +08:00
|
|
|
} else if (type === "Casdoor") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <CasdoorLoginButton text={text} align={"center"} />;
|
2022-01-22 19:36:44 +08:00
|
|
|
} else if (type === "Baidu") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <BaiduLoginButton text={text} align={"center"} />;
|
2022-04-02 22:37:13 +08:00
|
|
|
} else if (type === "Alipay") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <AlipayLoginButton text={text} align={"center"} />;
|
2022-02-05 21:54:38 +08:00
|
|
|
} else if (type === "Infoflow") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <InfoflowLoginButton text={text} align={"center"} />;
|
2021-12-10 00:55:27 +08:00
|
|
|
} else if (type === "Apple") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <AppleLoginButton text={text} align={"center"} />;
|
2021-12-10 00:55:27 +08:00
|
|
|
} else if (type === "AzureAD") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <AzureADLoginButton text={text} align={"center"} />;
|
2021-12-10 00:55:27 +08:00
|
|
|
} else if (type === "Slack") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <SlackLoginButton text={text} align={"center"} />;
|
2022-02-16 19:57:46 +08:00
|
|
|
} else if (type === "Steam") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <SteamLoginButton text={text} align={"center"} />;
|
2022-05-12 10:07:52 +08:00
|
|
|
} else if (type === "Bilibili") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <BilibiliLoginButton text={text} align={"center"} />;
|
2022-05-01 18:31:42 +08:00
|
|
|
} else if (type === "Okta") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <OktaLoginButton text={text} align={"center"} />;
|
2022-05-15 20:59:21 +08:00
|
|
|
} else if (type === "Douyin") {
|
2022-07-10 15:45:55 +08:00
|
|
|
return <DouyinLoginButton text={text} align={"center"} />;
|
2021-03-29 22:11:28 +08:00
|
|
|
}
|
2021-08-01 22:10:47 +08:00
|
|
|
|
|
|
|
return text;
|
2021-03-29 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
2021-12-13 19:49:30 +08:00
|
|
|
getSamlUrl(provider) {
|
2021-12-10 00:23:04 +08:00
|
|
|
const params = new URLSearchParams(this.props.location.search);
|
2021-12-13 19:49:30 +08:00
|
|
|
let clientId = params.get("client_id");
|
2021-12-10 00:23:04 +08:00
|
|
|
let application = params.get("state");
|
|
|
|
let realRedirectUri = params.get("redirect_uri");
|
2021-12-13 19:49:30 +08:00
|
|
|
let redirectUri = `${window.location.origin}/callback/saml`;
|
|
|
|
let providerName = provider.name;
|
2021-12-15 21:38:00 +08:00
|
|
|
let relayState = `${clientId}&${application}&${providerName}&${realRedirectUri}&${redirectUri}`;
|
|
|
|
AuthBackend.getSamlLogin(`${provider.owner}/${providerName}`, btoa(relayState)).then((res) => {
|
|
|
|
if (res.data2 === "POST") {
|
2022-07-10 15:45:55 +08:00
|
|
|
document.write(res.data);
|
2021-12-15 21:38:00 +08:00
|
|
|
} else {
|
2022-07-10 15:45:55 +08:00
|
|
|
window.location.href = res.data;
|
2021-12-15 21:38:00 +08:00
|
|
|
}
|
2021-12-06 21:46:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-28 20:20:40 +08:00
|
|
|
renderProviderLogo(provider, application, width, margin, size) {
|
|
|
|
if (size === "small") {
|
2021-12-06 21:46:50 +08:00
|
|
|
if (provider.category === "OAuth") {
|
|
|
|
return (
|
|
|
|
<a key={provider.displayName} href={Provider.getAuthUrl(application, provider, "signup")}>
|
2022-04-21 21:52:34 +08:00
|
|
|
<img width={width} height={width} src={Setting.getProviderLogoURL(provider)} alt={provider.displayName} style={{margin: margin}} />
|
2021-12-06 21:46:50 +08:00
|
|
|
</a>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-12-06 21:46:50 +08:00
|
|
|
} else if (provider.category === "SAML") {
|
|
|
|
return (
|
2022-06-17 19:57:11 +08:00
|
|
|
<a key={provider.displayName} onClick={this.getSamlUrl.bind(this, provider)}>
|
2022-04-21 21:52:34 +08:00
|
|
|
<img width={width} height={width} src={Setting.getProviderLogoURL(provider)} alt={provider.displayName} style={{margin: margin}} />
|
2021-12-06 21:46:50 +08:00
|
|
|
</a>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-12-06 21:46:50 +08:00
|
|
|
}
|
2022-07-10 15:45:55 +08:00
|
|
|
|
2021-03-28 20:20:40 +08:00
|
|
|
} else {
|
|
|
|
return (
|
2021-03-29 22:11:28 +08:00
|
|
|
<div key={provider.displayName} style={{marginBottom: "10px"}}>
|
|
|
|
<a href={Provider.getAuthUrl(application, provider, "signup")}>
|
|
|
|
{
|
2021-06-11 20:33:22 +08:00
|
|
|
this.getSigninButton(provider.type)
|
2021-03-29 22:11:28 +08:00
|
|
|
}
|
|
|
|
</a>
|
|
|
|
</div>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-03-28 20:20:40 +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"
|
|
|
|
title="Sign Up Error"
|
|
|
|
subTitle={"The application does not allow to sign up new account"}
|
|
|
|
extra={[
|
|
|
|
<Link onClick={() => {
|
|
|
|
Setting.goToLogin(this, application);
|
|
|
|
}}>
|
|
|
|
<Button type="primary" key="signin">
|
|
|
|
Sign In
|
|
|
|
</Button>
|
|
|
|
</Link>
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
</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) {
|
|
|
|
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,
|
2021-03-26 21:58:30 +08:00
|
|
|
}}
|
2022-07-10 15:45:55 +08:00
|
|
|
onFinish={(values) => {this.onFinish(values);}}
|
2021-11-28 21:10:21 +08:00
|
|
|
style={{width: "300px"}}
|
2021-03-26 21:58:30 +08:00
|
|
|
size="large"
|
2021-02-13 12:15:19 +08:00
|
|
|
>
|
2021-06-21 01:01:16 +08:00
|
|
|
<Form.Item
|
|
|
|
style={{height: 0, visibility: "hidden"}}
|
|
|
|
name="application"
|
|
|
|
rules={[
|
|
|
|
{
|
|
|
|
required: true,
|
2022-07-10 15:45:55 +08:00
|
|
|
message: "Please input your application!",
|
2021-06-21 01:01:16 +08:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
</Form.Item>
|
2021-04-28 21:25:58 +08:00
|
|
|
<Form.Item
|
|
|
|
style={{height: 0, visibility: "hidden"}}
|
|
|
|
name="organization"
|
|
|
|
rules={[
|
|
|
|
{
|
|
|
|
required: true,
|
2022-07-10 15:45:55 +08:00
|
|
|
message: "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()}
|
2021-03-26 21:58:30 +08:00
|
|
|
<Form.Item
|
|
|
|
name="username"
|
2021-12-07 00:05:53 +08:00
|
|
|
rules={[
|
2022-07-10 15:45:55 +08:00
|
|
|
{
|
|
|
|
required: true,
|
|
|
|
message: i18next.t("login:Please input your username, Email or phone!")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
validator: (_, value) => {
|
|
|
|
if (this.state.isCodeSignin) {
|
|
|
|
if (this.state.email !== "" && !Setting.isValidEmail(this.state.username) && !Setting.isValidPhone(this.state.username)) {
|
|
|
|
this.setState({validEmailOrPhone: false});
|
|
|
|
return Promise.reject(i18next.t("login:The input is not valid Email or Phone!"));
|
2022-03-18 20:12:29 +08:00
|
|
|
}
|
2022-07-12 20:06:01 +08:00
|
|
|
|
|
|
|
if (Setting.isValidPhone(this.state.username)) {
|
|
|
|
this.setState({validPhone: true});
|
|
|
|
}
|
|
|
|
if (Setting.isValidEmail(this.state.username)) {
|
|
|
|
this.setState({validEmail: true});
|
|
|
|
}
|
2021-12-07 00:05:53 +08:00
|
|
|
}
|
2022-07-12 20:06:01 +08:00
|
|
|
|
2022-07-10 15:45:55 +08:00
|
|
|
this.setState({validEmailOrPhone: true});
|
|
|
|
return Promise.resolve();
|
2021-12-07 00:05:53 +08:00
|
|
|
}
|
2022-07-10 15:45:55 +08:00
|
|
|
}
|
|
|
|
]}
|
2021-03-26 21:58:30 +08:00
|
|
|
>
|
|
|
|
<Input
|
|
|
|
prefix={<UserOutlined className="site-form-item-icon" />}
|
2022-07-10 15:45:55 +08:00
|
|
|
placeholder={this.state.isCodeSignin ? i18next.t("login:Email or phone") : i18next.t("login:username, Email or phone")}
|
2021-03-26 21:58:30 +08:00
|
|
|
disabled={!application.enablePassword}
|
2021-11-28 21:10:21 +08:00
|
|
|
onChange={e => {
|
|
|
|
this.setState({
|
|
|
|
username: e.target.value,
|
|
|
|
});
|
|
|
|
}}
|
2021-03-26 21:58:30 +08:00
|
|
|
/>
|
|
|
|
</Form.Item>
|
2021-11-28 21:10:21 +08:00
|
|
|
{
|
2022-07-12 20:06:01 +08:00
|
|
|
this.renderPasswordOrCodeInput()
|
2021-11-28 21:10:21 +08:00
|
|
|
}
|
2021-03-26 21:58:30 +08:00
|
|
|
<Form.Item>
|
2021-07-18 07:54:49 +08:00
|
|
|
<Form.Item name="autoSignin" valuePropName="checked" noStyle>
|
2021-03-26 21:58:30 +08:00
|
|
|
<Checkbox style={{float: "left"}} disabled={!application.enablePassword}>
|
2021-08-06 20:04:08 +08:00
|
|
|
{i18next.t("login:Auto sign in")}
|
2021-03-26 21:58:30 +08:00
|
|
|
</Checkbox>
|
|
|
|
</Form.Item>
|
2022-06-17 19:57:11 +08:00
|
|
|
<a style={{float: "right"}} onClick={() => {
|
2021-05-03 00:48:02 +08:00
|
|
|
Setting.goToForget(this, application);
|
|
|
|
}}>
|
2021-06-04 21:09:34 +08:00
|
|
|
{i18next.t("login:Forgot password?")}
|
|
|
|
</a>
|
2021-03-26 21:58:30 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item>
|
2022-07-12 20:06:01 +08:00
|
|
|
{
|
|
|
|
this.state.loginMethod === "password" ?
|
|
|
|
(
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
htmlType="submit"
|
2022-07-12 20:45:22 +08:00
|
|
|
style={{width: "100%", marginBottom: "5px"}}
|
2022-07-12 20:06:01 +08:00
|
|
|
disabled={!application.enablePassword}
|
|
|
|
>
|
|
|
|
{i18next.t("login:Sign In")}
|
|
|
|
</Button>
|
|
|
|
) :
|
|
|
|
(
|
2022-08-05 17:43:04 +08:00
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
htmlType="submit"
|
|
|
|
style={{width: "100%", marginBottom: "5px"}}
|
|
|
|
disabled={!application.enablePassword}
|
|
|
|
>
|
|
|
|
{i18next.t("login:Sign in with WebAuthn")}
|
|
|
|
</Button>
|
2022-07-12 20:06:01 +08:00
|
|
|
)
|
|
|
|
}
|
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 => {
|
2021-06-14 21:35:19 +08:00
|
|
|
return this.renderProviderLogo(providerItem.provider, application, 30, 5, "small");
|
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>
|
2021-06-11 20:33:22 +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 => {
|
2021-06-14 21:35:19 +08:00
|
|
|
return this.renderProviderLogo(providerItem.provider, application, 40, 10, "big");
|
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
|
|
|
}
|
|
|
|
|
2021-06-14 22:42:58 +08:00
|
|
|
renderFooter(application) {
|
|
|
|
if (this.state.mode === "signup") {
|
|
|
|
return (
|
|
|
|
<div style={{float: "right"}}>
|
|
|
|
{i18next.t("signup:Have account?")}
|
|
|
|
<Link onClick={() => {
|
|
|
|
Setting.goToLogin(this, application);
|
|
|
|
}}>
|
|
|
|
{i18next.t("signup:sign in now")}
|
|
|
|
</Link>
|
|
|
|
</div>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-06-14 22:42:58 +08:00
|
|
|
} else {
|
|
|
|
return (
|
2021-11-28 21:10:21 +08:00
|
|
|
<React.Fragment>
|
|
|
|
<span style={{float: "left"}}>
|
2021-12-31 13:36:10 +08:00
|
|
|
{
|
|
|
|
!application.enableCodeSignin ? null : (
|
2022-06-17 19:57:11 +08:00
|
|
|
<a onClick={() => {
|
2021-12-31 13:36:10 +08:00
|
|
|
this.setState({
|
|
|
|
isCodeSignin: !this.state.isCodeSignin,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
{this.state.isCodeSignin ? i18next.t("login:Sign in with password") : i18next.t("login:Sign in with code")}
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
}
|
2021-11-28 21:10:21 +08:00
|
|
|
</span>
|
|
|
|
<span style={{float: "right"}}>
|
2022-07-28 23:11:33 +08:00
|
|
|
{
|
|
|
|
!application.enableSignUp ? null : (
|
|
|
|
<>
|
|
|
|
{i18next.t("login:No account?")}
|
|
|
|
<a onClick={() => {
|
|
|
|
sessionStorage.setItem("signinUrl", window.location.href);
|
|
|
|
Setting.goToSignup(this, application);
|
|
|
|
}}>
|
|
|
|
{i18next.t("login:sign up now")}
|
|
|
|
</a>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2021-11-28 21:10:21 +08:00
|
|
|
</span>
|
|
|
|
</React.Fragment>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-06-14 22:42:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 21:15:57 +08:00
|
|
|
renderSignedInBox() {
|
|
|
|
if (this.props.account === undefined || this.props.account === null) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-07-10 15:45:55 +08:00
|
|
|
let application = this.getApplicationObj();
|
2021-11-11 20:43:26 +08:00
|
|
|
if (this.props.account.owner !== application.organization) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-10-09 21:15:57 +08:00
|
|
|
|
2022-01-23 13:02:55 +08:00
|
|
|
const params = new URLSearchParams(this.props.location.search);
|
|
|
|
let silentSignin = params.get("silentSignin");
|
|
|
|
if (silentSignin !== null) {
|
|
|
|
if (window !== window.parent) {
|
|
|
|
const message = {tag: "Casdoor", type: "SilentSignin", data: "signing-in"};
|
|
|
|
window.parent.postMessage(message, "*");
|
|
|
|
}
|
|
|
|
|
|
|
|
let values = {};
|
|
|
|
values["application"] = this.state.application.name;
|
|
|
|
this.onFinish(values);
|
|
|
|
}
|
|
|
|
|
2021-10-09 21:15:57 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2022-07-10 15:45:55 +08:00
|
|
|
{/* {*/}
|
2022-04-25 20:00:57 +08:00
|
|
|
{/* JSON.stringify(silentSignin)*/}
|
2022-07-10 15:45:55 +08:00
|
|
|
{/* }*/}
|
2021-10-09 21:15:57 +08:00
|
|
|
<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={() => {
|
|
|
|
let values = {};
|
|
|
|
values["application"] = this.state.application.name;
|
|
|
|
this.onFinish(values);
|
|
|
|
}} />
|
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-08-05 17:43:04 +08:00
|
|
|
signInWithWebAuthn(username) {
|
|
|
|
if (username === null || username === "") {
|
2022-07-12 20:06:01 +08:00
|
|
|
Setting.showMessage("error", "username is required for webauthn login");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let 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",
|
|
|
|
credentials: "include"
|
|
|
|
})
|
|
|
|
.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-05 17:43:04 +08:00
|
|
|
publicKey: credentialRequestOptions.publicKey
|
2022-07-12 20:45:22 +08:00
|
|
|
});
|
2022-07-12 20:06:01 +08:00
|
|
|
})
|
|
|
|
.then((assertion) => {
|
|
|
|
let authData = assertion.response.authenticatorData;
|
|
|
|
let clientDataJSON = assertion.response.clientDataJSON;
|
|
|
|
let rawId = assertion.rawId;
|
|
|
|
let sig = assertion.response.signature;
|
|
|
|
let userHandle = assertion.response.userHandle;
|
|
|
|
return fetch(`${Setting.ServerUrl}/api/webauthn/signin/finish`, {
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(res => res.json()).then((res) => {
|
|
|
|
if (res.msg === "") {
|
2022-07-12 20:45:22 +08:00
|
|
|
Setting.showMessage("success", "Successfully logged in with webauthn credentials");
|
2022-07-12 20:06:01 +08:00
|
|
|
Setting.goToLink("/");
|
|
|
|
} else {
|
|
|
|
Setting.showMessage("error", res.msg);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
|
|
|
});
|
2022-07-12 20:45:22 +08:00
|
|
|
});
|
2022-07-12 20:06:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
renderPasswordOrCodeInput() {
|
|
|
|
let application = this.getApplicationObj();
|
|
|
|
if (this.state.loginMethod === "password") {
|
|
|
|
return this.state.isCodeSignin ? (
|
|
|
|
<Form.Item
|
|
|
|
name="code"
|
|
|
|
rules={[{required: true, message: i18next.t("login:Please input your code!")}]}
|
|
|
|
>
|
|
|
|
<CountDownInput
|
|
|
|
disabled={this.state.username?.length === 0 || !this.state.validEmailOrPhone}
|
2022-07-25 23:46:38 +08:00
|
|
|
onButtonClickArgs={[this.state.username, this.state.validEmail ? "email" : "phone", Setting.getApplicationName(application)]}
|
2022-07-12 20:06:01 +08:00
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
) : (
|
|
|
|
<Form.Item
|
|
|
|
name="password"
|
|
|
|
rules={[{required: true, message: i18next.t("login:Please input your password!")}]}
|
|
|
|
>
|
|
|
|
<Input
|
|
|
|
prefix={<LockOutlined className="site-form-item-icon" />}
|
|
|
|
type="password"
|
|
|
|
placeholder={i18next.t("login:Password")}
|
|
|
|
disabled={!application.enablePassword}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
2022-07-12 20:45:22 +08:00
|
|
|
);
|
2022-07-12 20:06:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-12 20:45:22 +08:00
|
|
|
renderMethodChoiceBox() {
|
2022-07-12 20:06:01 +08:00
|
|
|
let application = this.getApplicationObj();
|
|
|
|
if (application.enableWebAuthn) {
|
|
|
|
return (
|
|
|
|
<div>
|
2022-07-12 20:45:22 +08:00
|
|
|
<Tabs defaultActiveKey="password" onChange={(key) => {this.setState({loginMethod: key});}} centered>
|
|
|
|
<TabPane tab={i18next.t("login:Password")} key="password" />
|
|
|
|
<TabPane tab={"WebAuthn"} key="webAuthn" />
|
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();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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));
|
2021-09-20 22:55:17 +08:00
|
|
|
if (this.props.application === undefined && !application.enablePassword && visibleOAuthProviderItems.length === 1) {
|
2021-08-07 00:14:24 +08:00
|
|
|
Setting.goToLink(Provider.getAuthUrl(application, visibleOAuthProviderItems[0].provider, "signup"));
|
|
|
|
return (
|
|
|
|
<div style={{textAlign: "center"}}>
|
|
|
|
<Spin size="large" tip={i18next.t("login:Signing in...")} style={{paddingTop: "10%"}} />
|
|
|
|
</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 (
|
|
|
|
<Row>
|
2021-03-20 11:34:04 +08:00
|
|
|
<Col span={24} style={{display: "flex", justifyContent: "center"}}>
|
2021-06-15 22:12:50 +08:00
|
|
|
<div style={{marginTop: "80px", marginBottom: "50px", textAlign: "center"}}>
|
2021-04-29 21:28:24 +08:00
|
|
|
{
|
|
|
|
Setting.renderHelmet(application)
|
|
|
|
}
|
2021-11-06 22:04:20 +08:00
|
|
|
<CustomGithubCorner />
|
2021-03-06 21:50:48 +08:00
|
|
|
{
|
2021-04-28 15:54:50 +08:00
|
|
|
Setting.renderLogo(application)
|
2021-03-06 21:50:48 +08:00
|
|
|
}
|
2022-07-10 15:45:55 +08:00
|
|
|
{/* {*/}
|
2021-03-15 00:28:34 +08:00
|
|
|
{/* this.state.clientId !== null ? "Redirect" : null*/}
|
2022-07-10 15:45:55 +08:00
|
|
|
{/* }*/}
|
2021-10-09 21:15:57 +08:00
|
|
|
{
|
|
|
|
this.renderSignedInBox()
|
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
{
|
|
|
|
this.renderForm(application)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-26 21:56:51 +08:00
|
|
|
export default LoginPage;
|