2021-02-13 13:30:51 +08:00
|
|
|
// Copyright 2021 The casbin 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.
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
import React from "react";
|
2021-02-14 10:56:37 +08:00
|
|
|
import {Button, Card, Col, Input, Row, Select, Switch} from 'antd';
|
2021-02-13 12:15:19 +08:00
|
|
|
import {LinkOutlined} from "@ant-design/icons";
|
|
|
|
import * as ApplicationBackend from "./backend/ApplicationBackend";
|
|
|
|
import * as Setting from "./Setting";
|
|
|
|
import * as ProviderBackend from "./backend/ProviderBackend";
|
|
|
|
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
2021-06-14 13:13:39 +08:00
|
|
|
import SignupPage from "./auth/SignupPage";
|
2021-03-26 21:56:51 +08:00
|
|
|
import LoginPage from "./auth/LoginPage";
|
2021-02-19 23:23:59 +08:00
|
|
|
import i18next from "i18next";
|
2021-03-06 21:41:24 +08:00
|
|
|
import UrlTable from "./UrlTable";
|
2021-02-13 12:15:19 +08:00
|
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
|
|
|
class ApplicationEditPage extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
classes: props,
|
|
|
|
applicationName: props.match.params.applicationName,
|
|
|
|
application: null,
|
|
|
|
organizations: [],
|
|
|
|
providers: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-27 11:38:15 +08:00
|
|
|
UNSAFE_componentWillMount() {
|
2021-02-13 12:15:19 +08:00
|
|
|
this.getApplication();
|
|
|
|
this.getOrganizations();
|
|
|
|
this.getProviders();
|
|
|
|
}
|
|
|
|
|
|
|
|
getApplication() {
|
|
|
|
ApplicationBackend.getApplication("admin", this.state.applicationName)
|
|
|
|
.then((application) => {
|
|
|
|
this.setState({
|
|
|
|
application: application,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getOrganizations() {
|
|
|
|
OrganizationBackend.getOrganizations("admin")
|
|
|
|
.then((res) => {
|
|
|
|
this.setState({
|
2021-03-28 00:48:34 +08:00
|
|
|
organizations: (res.msg === undefined) ? res : [],
|
2021-02-13 12:15:19 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getProviders() {
|
|
|
|
ProviderBackend.getProviders("admin")
|
|
|
|
.then((res) => {
|
|
|
|
this.setState({
|
|
|
|
providers: res,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
parseApplicationField(key, value) {
|
2021-03-14 22:48:09 +08:00
|
|
|
if (["expireInHours"].includes(key)) {
|
|
|
|
value = Setting.myParseInt(value);
|
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateApplicationField(key, value) {
|
|
|
|
value = this.parseApplicationField(key, value);
|
|
|
|
|
|
|
|
let application = this.state.application;
|
|
|
|
application[key] = value;
|
|
|
|
this.setState({
|
|
|
|
application: application,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderApplication() {
|
|
|
|
return (
|
|
|
|
<Card size="small" title={
|
|
|
|
<div>
|
2021-02-19 23:23:59 +08:00
|
|
|
{i18next.t("application:Edit Application")}
|
|
|
|
<Button type="primary" onClick={this.submitApplicationEdit.bind(this)}>{i18next.t("general:Save")}</Button>
|
2021-02-13 12:15:19 +08:00
|
|
|
</div>
|
|
|
|
} style={{marginLeft: '5px'}} type="inner">
|
|
|
|
<Row style={{marginTop: '10px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-02-19 23:23:59 +08:00
|
|
|
{i18next.t("general:Name")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input value={this.state.application.name} onChange={e => {
|
|
|
|
this.updateApplicationField('name', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-04-28 00:13:50 +08:00
|
|
|
{i18next.t("general:Display name")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input value={this.state.application.displayName} onChange={e => {
|
|
|
|
this.updateApplicationField('displayName', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
Logo:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={1}>
|
|
|
|
URL:
|
|
|
|
</Col>
|
|
|
|
<Col span={23} >
|
|
|
|
<Input prefix={<LinkOutlined/>} value={this.state.application.logo} onChange={e => {
|
|
|
|
this.updateApplicationField('logo', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={1}>
|
2021-02-19 23:23:59 +08:00
|
|
|
{i18next.t("general:Preview")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={23} >
|
2021-03-27 11:38:15 +08:00
|
|
|
<a target="_blank" rel="noreferrer" href={this.state.application.logo}>
|
2021-02-13 12:15:19 +08:00
|
|
|
<img src={this.state.application.logo} alt={this.state.application.logo} height={90} style={{marginBottom: '20px'}}/>
|
|
|
|
</a>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-03-06 21:50:48 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
{i18next.t("general:Homepage URL")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input prefix={<LinkOutlined/>} value={this.state.application.homepageUrl} onChange={e => {
|
|
|
|
this.updateApplicationField('homepageUrl', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
{i18next.t("general:Description")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input value={this.state.application.description} onChange={e => {
|
|
|
|
this.updateApplicationField('description', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-02-13 12:15:19 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-02-19 23:23:59 +08:00
|
|
|
{i18next.t("general:Organization")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Select virtual={false} style={{width: '100%'}} value={this.state.application.organization} onChange={(value => {this.updateApplicationField('organization', value);})}>
|
|
|
|
{
|
|
|
|
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
|
|
|
}
|
|
|
|
</Select>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-03-06 16:39:17 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
{i18next.t("provider:Client ID")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input value={this.state.application.clientId} onChange={e => {
|
|
|
|
this.updateApplicationField('clientId', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-04-28 00:13:50 +08:00
|
|
|
{i18next.t("provider:Client secret")}:
|
2021-03-06 16:39:17 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input value={this.state.application.clientSecret} onChange={e => {
|
|
|
|
this.updateApplicationField('clientSecret', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-03-06 21:41:24 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
{i18next.t("application:Redirect URLs")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<UrlTable
|
|
|
|
title="Redirect URLs"
|
2021-03-15 00:01:21 +08:00
|
|
|
table={this.state.application.redirectUris}
|
|
|
|
onUpdateTable={(value) => { this.updateApplicationField('redirectUris', value)}}
|
2021-03-06 21:41:24 +08:00
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-03-14 22:48:09 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-06-14 13:13:39 +08:00
|
|
|
{i18next.t("general:Token expire")}:
|
2021-03-14 22:48:09 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
2021-06-14 13:13:39 +08:00
|
|
|
<Input style={{width: "150px"}} value={this.state.application.expireInHours} suffix="Hours" onChange={e => {
|
2021-03-14 22:48:09 +08:00
|
|
|
this.updateApplicationField('expireInHours', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-02-14 10:56:37 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-04-28 00:13:50 +08:00
|
|
|
{i18next.t("application:Enable password")}:
|
2021-02-14 10:56:37 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={1} >
|
2021-02-14 13:43:55 +08:00
|
|
|
<Switch checked={this.state.application.enablePassword} onChange={checked => {
|
|
|
|
this.updateApplicationField('enablePassword', checked);
|
|
|
|
}} />
|
2021-02-14 10:56:37 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-03-26 21:55:39 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-04-28 00:13:50 +08:00
|
|
|
{i18next.t("application:Enable signup")}:
|
2021-03-26 21:55:39 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={1} >
|
|
|
|
<Switch checked={this.state.application.enableSignUp} onChange={checked => {
|
|
|
|
this.updateApplicationField('enableSignUp', checked);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-02-13 12:15:19 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
2021-05-03 00:48:02 +08:00
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
{i18next.t("general:Signup URL")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input prefix={<LinkOutlined/>} value={this.state.application.signupUrl} onChange={e => {
|
|
|
|
this.updateApplicationField('signupUrl', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
{i18next.t("general:Forget URL")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input prefix={<LinkOutlined/>} value={this.state.application.forgetUrl} onChange={e => {
|
|
|
|
this.updateApplicationField('forgetUrl', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
2021-05-24 21:27:00 +08:00
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
{i18next.t("general:Affiliation URL")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input prefix={<LinkOutlined/>} value={this.state.application.affiliationUrl} onChange={e => {
|
|
|
|
this.updateApplicationField('affiliationUrl', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
2021-02-13 12:15:19 +08:00
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-02-19 23:23:59 +08:00
|
|
|
{i18next.t("general:Providers")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
2021-03-26 21:58:19 +08:00
|
|
|
<Select virtual={false} mode="tags" style={{width: '100%'}}
|
2021-02-13 12:15:19 +08:00
|
|
|
value={this.state.application.providers}
|
|
|
|
onChange={value => {
|
|
|
|
this.updateApplicationField('providers', value);
|
|
|
|
}} >
|
|
|
|
{
|
|
|
|
this.state.providers.map((provider, index) => <Option key={index} value={provider.name}>{provider.name}</Option>)
|
|
|
|
}
|
|
|
|
</Select>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-06-14 13:13:39 +08:00
|
|
|
{i18next.t("general:Preview")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
2021-06-14 13:13:39 +08:00
|
|
|
<Col span={11} >
|
|
|
|
<a style={{marginBottom: '10px'}} target="_blank" rel="noreferrer" href={`/signup/${this.state.application.name}`}>
|
|
|
|
<Button type="primary">{i18next.t("application:Test signup page..")}</Button>
|
|
|
|
</a>
|
|
|
|
<br/>
|
|
|
|
<br/>
|
|
|
|
<div style={{width: "90%", border: "1px solid rgb(217,217,217)", boxShadow: "10px 10px 5px #888888"}}>
|
|
|
|
<SignupPage application={this.state.application} />
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
<Col span={11} >
|
2021-03-27 11:38:15 +08:00
|
|
|
<a style={{marginBottom: '10px'}} target="_blank" rel="noreferrer" href={`/login/oauth/authorize?client_id=${this.state.application.clientId}&response_type=code&redirect_uri=${this.state.application.redirectUris[0]}&scope=read&state=casdoor`}>
|
2021-06-14 13:13:39 +08:00
|
|
|
<Button type="primary">{i18next.t("application:Test signin page..")}</Button>
|
2021-02-13 12:15:19 +08:00
|
|
|
</a>
|
|
|
|
<br/>
|
|
|
|
<br/>
|
2021-06-14 13:13:39 +08:00
|
|
|
<div style={{width: "90%", border: "1px solid rgb(217,217,217)", boxShadow: "10px 10px 5px #888888"}}>
|
2021-03-26 21:56:51 +08:00
|
|
|
<LoginPage type={"login"} application={this.state.application} />
|
2021-02-13 12:15:19 +08:00
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Card>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
submitApplicationEdit() {
|
|
|
|
let application = Setting.deepCopy(this.state.application);
|
|
|
|
ApplicationBackend.updateApplication(this.state.application.owner, this.state.applicationName, application)
|
|
|
|
.then((res) => {
|
2021-03-28 00:48:34 +08:00
|
|
|
if (res.msg === "") {
|
2021-02-13 12:15:19 +08:00
|
|
|
Setting.showMessage("success", `Successfully saved`);
|
|
|
|
this.setState({
|
|
|
|
applicationName: this.state.application.name,
|
|
|
|
});
|
|
|
|
this.props.history.push(`/applications/${this.state.application.name}`);
|
|
|
|
} else {
|
2021-03-28 00:48:34 +08:00
|
|
|
Setting.showMessage("error", res.msg);
|
2021-02-13 12:15:19 +08:00
|
|
|
this.updateApplicationField('name', this.state.applicationName);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2021-03-28 08:59:12 +08:00
|
|
|
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
2021-02-13 12:15:19 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Row style={{width: "100%"}}>
|
|
|
|
<Col span={1}>
|
|
|
|
</Col>
|
|
|
|
<Col span={22}>
|
|
|
|
{
|
|
|
|
this.state.application !== null ? this.renderApplication() : null
|
|
|
|
}
|
|
|
|
</Col>
|
|
|
|
<Col span={1}>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{margin: 10}}>
|
|
|
|
<Col span={2}>
|
|
|
|
</Col>
|
|
|
|
<Col span={18}>
|
2021-02-19 23:23:59 +08:00
|
|
|
<Button type="primary" size="large" onClick={this.submitApplicationEdit.bind(this)}>{i18next.t("general:Save")}</Button>
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ApplicationEditPage;
|