// 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 OrganizationBackend from "./backend/OrganizationBackend"; 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, owner: props.match.params.organizationName, cert: null, organizations: [], mode: props.location.mode !== undefined ? props.location.mode : "edit", }; } UNSAFE_componentWillMount() { this.getCert(); this.getOrganizations(); } getCert() { CertBackend.getCert(this.state.owner, this.state.certName) .then((res) => { if (res.data === null) { this.props.history.push("/404"); return; } if (res.status === "error") { Setting.showMessage("error", res.msg); return; } this.setState({ cert: res.data, }); }); } getOrganizations() { OrganizationBackend.getOrganizations("admin") .then((res) => { this.setState({ organizations: res.data || [], }); }); } parseCertField(key, value) { if (["port"].includes(key)) { value = Setting.myParseInt(value); } return value; } updateCertField(key, value) { value = this.parseCertField(key, value); const cert = this.state.cert; cert[key] = value; this.setState({ cert: cert, }); } renderCert() { const editorWidth = Setting.isMobile() ? 22 : 9; 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:Organization"), i18next.t("general:Organization - Tooltip"))} : {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("provider:Scope"), i18next.t("cert:Scope - Tooltip"))} : {Setting.getLabel(i18next.t("provider: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"))} : {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"))} :