2021-01-12 23:21:07 +08:00
|
|
|
|
import React from "react";
|
|
|
|
|
import {Button, Checkbox, Col, Form, Input, Row} from "antd";
|
|
|
|
|
import {LockOutlined, UserOutlined} from "@ant-design/icons";
|
2021-02-11 16:43:30 +08:00
|
|
|
|
import * as ApplicationBackend from "./backend/ApplicationBackend";
|
2021-02-11 23:51:29 +08:00
|
|
|
|
import * as AccountBackend from "./backend/AccountBackend";
|
|
|
|
|
import * as Setting from "./Setting";
|
2021-01-12 23:21:07 +08:00
|
|
|
|
|
|
|
|
|
class Face extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
classes: props,
|
2021-02-13 01:33:06 +08:00
|
|
|
|
applicationName: props.applicationName !== undefined ? props.applicationName : (props.match === undefined ? null : props.match.params.applicationName),
|
2021-02-11 16:43:30 +08:00
|
|
|
|
application: null,
|
2021-01-12 23:21:07 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 16:43:30 +08:00
|
|
|
|
componentWillMount() {
|
|
|
|
|
this.getApplication();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getApplication() {
|
|
|
|
|
ApplicationBackend.getApplication("admin", this.state.applicationName)
|
|
|
|
|
.then((application) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
application: application,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getApplicationObj() {
|
|
|
|
|
if (this.props.application !== undefined) {
|
|
|
|
|
return this.props.application;
|
|
|
|
|
} else {
|
|
|
|
|
return this.state.application;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 23:51:29 +08:00
|
|
|
|
onFinish(values) {
|
|
|
|
|
AccountBackend.login(values)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.status === 'ok') {
|
2021-02-13 00:11:12 +08:00
|
|
|
|
this.props.onLoggedIn();
|
2021-02-11 23:51:29 +08:00
|
|
|
|
Setting.showMessage("success", `Logged in successfully`);
|
|
|
|
|
Setting.goToLink("/");
|
|
|
|
|
} else {
|
|
|
|
|
Setting.showMessage("error", `Log in failed:${res.msg}`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-12 23:21:07 +08:00
|
|
|
|
renderForm() {
|
|
|
|
|
return (
|
|
|
|
|
<Form
|
|
|
|
|
name="normal_login"
|
2021-02-13 00:11:12 +08:00
|
|
|
|
initialValues={{
|
|
|
|
|
organization: this.getApplicationObj().organization,
|
|
|
|
|
remember: true
|
|
|
|
|
}}
|
2021-02-11 23:51:29 +08:00
|
|
|
|
onFinish={this.onFinish.bind(this)}
|
2021-01-12 23:21:07 +08:00
|
|
|
|
style={{width: "250px"}}
|
|
|
|
|
size="large"
|
|
|
|
|
>
|
|
|
|
|
<Form.Item
|
|
|
|
|
name="username"
|
|
|
|
|
rules={[{ required: true, message: 'Please input your Username!' }]}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
prefix={<UserOutlined className="site-form-item-icon" />}
|
|
|
|
|
placeholder="username"
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
name="password"
|
|
|
|
|
rules={[{ required: true, message: 'Please input your Password!' }]}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
prefix={<LockOutlined className="site-form-item-icon" />}
|
|
|
|
|
type="password"
|
|
|
|
|
placeholder="password"
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<Form.Item name="remember" valuePropName="checked" noStyle>
|
|
|
|
|
<Checkbox style={{float: "left"}}>Auto login</Checkbox>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<a style={{float: "right"}} href="">
|
|
|
|
|
Forgot password?
|
|
|
|
|
</a>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
htmlType="submit"
|
|
|
|
|
style={{width: "100%"}}
|
|
|
|
|
>
|
|
|
|
|
Login
|
|
|
|
|
</Button>
|
|
|
|
|
<div style={{float: "right"}}>
|
|
|
|
|
No account yet, <a href="/register">sign up now</a>
|
|
|
|
|
</div>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2021-02-11 16:43:30 +08:00
|
|
|
|
const application = this.getApplicationObj();
|
2021-02-13 00:11:12 +08:00
|
|
|
|
if (application === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-02-11 16:43:30 +08:00
|
|
|
|
|
2021-01-12 23:21:07 +08:00
|
|
|
|
return (
|
|
|
|
|
<Row>
|
|
|
|
|
<Col span={24} style={{display: "flex", justifyContent: "center"}} >
|
|
|
|
|
<div style={{marginTop: "80px", textAlign: "center"}}>
|
2021-02-13 00:11:12 +08:00
|
|
|
|
<img src={application.logo} alt={application.displayName} style={{marginBottom: '50px'}}/>
|
2021-01-12 23:21:07 +08:00
|
|
|
|
{
|
2021-02-11 16:43:30 +08:00
|
|
|
|
this.renderForm(application)
|
2021-01-12 23:21:07 +08:00
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Face;
|