2022-06-18 16:00:31 +08:00
|
|
|
// Copyright 2022 The Casdoor Authors. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2022-10-28 13:38:14 +08:00
|
|
|
import {Button} from "antd";
|
2022-06-18 16:00:31 +08:00
|
|
|
import React from "react";
|
|
|
|
import i18next from "i18next";
|
2023-03-26 18:44:47 +08:00
|
|
|
import {CaptchaModal} from "./modal/CaptchaModal";
|
2022-10-28 13:38:14 +08:00
|
|
|
import * as UserBackend from "../backend/UserBackend";
|
2022-06-18 16:00:31 +08:00
|
|
|
|
2023-03-05 20:31:46 +08:00
|
|
|
export const CaptchaPreview = (props) => {
|
|
|
|
const {owner, name, provider, captchaType, subType, clientId, clientSecret, clientId2, clientSecret2, providerUrl} = props;
|
|
|
|
const [visible, setVisible] = React.useState(false);
|
2022-06-18 16:00:31 +08:00
|
|
|
|
|
|
|
const clickPreview = () => {
|
|
|
|
provider.name = name;
|
|
|
|
provider.clientId = clientId;
|
|
|
|
provider.type = captchaType;
|
|
|
|
provider.providerUrl = providerUrl;
|
|
|
|
if (clientSecret !== "***") {
|
|
|
|
provider.clientSecret = clientSecret;
|
2023-03-05 20:31:46 +08:00
|
|
|
setVisible(true);
|
2022-06-18 16:00:31 +08:00
|
|
|
} else {
|
2023-03-05 20:31:46 +08:00
|
|
|
setVisible(true);
|
2022-06-18 16:00:31 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-05 20:31:46 +08:00
|
|
|
const isButtonDisabled = () => {
|
2022-06-29 11:31:32 +08:00
|
|
|
if (captchaType !== "Default") {
|
|
|
|
if (!clientId || !clientSecret) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (captchaType === "Aliyun Captcha") {
|
|
|
|
if (!subType || !clientId2 || !clientSecret2) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2023-03-05 20:31:46 +08:00
|
|
|
const onOk = (captchaType, captchaToken, clientSecret) => {
|
2023-12-11 18:01:56 +08:00
|
|
|
UserBackend.verifyCaptcha(owner, name, captchaType, captchaToken, clientSecret).then(() => {
|
2023-03-05 20:31:46 +08:00
|
|
|
setVisible(false);
|
2022-10-28 13:38:14 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onCancel = () => {
|
2023-03-05 20:31:46 +08:00
|
|
|
setVisible(false);
|
2022-10-28 13:38:14 +08:00
|
|
|
};
|
|
|
|
|
2022-06-18 16:00:31 +08:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2022-06-29 11:31:32 +08:00
|
|
|
<Button
|
2022-07-10 15:45:55 +08:00
|
|
|
style={{fontSize: 14}}
|
2022-06-29 11:31:32 +08:00
|
|
|
type={"primary"}
|
|
|
|
onClick={clickPreview}
|
2023-03-05 20:31:46 +08:00
|
|
|
disabled={isButtonDisabled()}
|
2022-06-29 11:31:32 +08:00
|
|
|
>
|
2022-06-18 16:00:31 +08:00
|
|
|
{i18next.t("general:Preview")}
|
|
|
|
</Button>
|
2022-10-28 13:38:14 +08:00
|
|
|
<CaptchaModal
|
|
|
|
owner={owner}
|
|
|
|
name={name}
|
2023-03-05 20:31:46 +08:00
|
|
|
visible={visible}
|
2022-10-28 13:38:14 +08:00
|
|
|
onOk={onOk}
|
|
|
|
onCancel={onCancel}
|
2023-03-05 20:31:46 +08:00
|
|
|
isCurrentProvider={true}
|
2022-10-28 13:38:14 +08:00
|
|
|
/>
|
2022-06-18 16:00:31 +08:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|