// Copyright 2021 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. import React from "react"; import {Button, Card, Col, Input, InputNumber, Row, Select} from "antd"; import * as CertBackend from "./backend/CertBackend"; import * as Setting from "./Setting"; import i18next from "i18next"; import copy from "copy-to-clipboard"; import FileSaver from "file-saver"; const {Option} = Select; const {TextArea} = Input; class CertEditPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, certName: props.match.params.certName, cert: null, mode: props.location.mode !== undefined ? props.location.mode : "edit", }; } UNSAFE_componentWillMount() { this.getCert(); } getCert() { CertBackend.getCert("admin", this.state.certName) .then((cert) => { this.setState({ cert: cert, }); }); } parseCertField(key, value) { if (["port"].includes(key)) { value = Setting.myParseInt(value); } return value; } updateCertField(key, value) { value = this.parseCertField(key, value); let cert = this.state.cert; cert[key] = value; this.setState({ cert: cert, }); } renderCert() { return ( {this.state.mode === "add" ? i18next.t("cert:New Cert") : i18next.t("cert:Edit Cert")}     {this.state.mode === "add" ? : null} } style={(Setting.isMobile()) ? {margin: "5px"} : {}} type="inner"> {Setting.getLabel(i18next.t("general:Name"), i18next.t("general:Name - Tooltip"))} : { this.updateCertField("name", e.target.value); }} /> {Setting.getLabel(i18next.t("general:Display name"), i18next.t("general:Display name - Tooltip"))} : { this.updateCertField("displayName", e.target.value); }} /> {Setting.getLabel(i18next.t("cert:Scope"), i18next.t("cert:Scope - Tooltip"))} : {Setting.getLabel(i18next.t("cert:Type"), i18next.t("cert:Type - Tooltip"))} : {Setting.getLabel(i18next.t("cert:Crypto algorithm"), i18next.t("cert:Crypto algorithm - Tooltip"))} : {Setting.getLabel(i18next.t("cert:Bit size"), i18next.t("cert:Bit size - Tooltip"))} : { this.updateCertField("bitSize", value); }} /> {Setting.getLabel(i18next.t("cert:Expire in years"), i18next.t("cert:Expire in years - Tooltip"))} : { this.updateCertField("expireInYears", value); }} /> {Setting.getLabel(i18next.t("cert:Certificate"), i18next.t("cert:Certificate - Tooltip"))} :