Merge branch 'application-mgt-new' into 'application-mgt-new'

Add login

See merge request tcdlpds/carbon-device-mgt!3
feature/appm-store/pbac
Dharmakeerthi Lasantha 6 years ago
commit dd5109c2aa

@ -18,7 +18,8 @@
"react-highlight-words": "^0.16.0", "react-highlight-words": "^0.16.0",
"react-router-config": "^5.0.0", "react-router-config": "^5.0.0",
"react-router-dom": "latest", "react-router-dom": "latest",
"react-scripts": "2.1.8" "react-scripts": "2.1.8",
"react-router": "latest"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.0.0", "@babel/core": "^7.0.0",

@ -13,19 +13,19 @@ import {Provider} from "react-redux";
const routes = [ const routes = [
{ {
path: '/publisher/Login', path: '/publisher/login',
component: Login component: Login
}, },
{ {
path: '/publisher/dashboard', path: '/publisher',
component: Dashboard, component: Dashboard,
routes: [ routes: [
{ {
path: '/publisher/dashboard/apps', path: '/publisher/apps',
component: Apps component: Apps
}, },
{ {
path: '/publisher/dashboard/new-app', path: '/publisher/new-app',
component: AddNewApp component: AddNewApp
} }
] ]

@ -1,9 +1,10 @@
import React from "react"; import React from "react";
import {Typography, Row, Col, Form, Icon, Input, Button, Checkbox,} from 'antd'; import {Typography, Row, Col, Form, Icon, Input, Button, Checkbox} from 'antd';
import styles from './Login.less'; import styles from './Login.less';
import axios from 'axios'; import axios from 'axios';
const {Title} = Typography; const {Title} = Typography;
const {Text} = Typography;
class Login extends React.Component { class Login extends React.Component {
render() { render() {
@ -35,17 +36,41 @@ class Login extends React.Component {
} }
class NormalLoginForm extends React.Component { class NormalLoginForm extends React.Component {
constructor(props) {
super(props);
this.state = {
inValid: false,
loading : false
};
}
handleSubmit = (e) => { handleSubmit = (e) => {
const thisForm = this;
e.preventDefault(); e.preventDefault();
this.props.form.validateFields((err, values) => { this.props.form.validateFields((err, values) => {
thisForm.setState({
inValid: false
});
if (!err) { if (!err) {
thisForm.setState({
loading: true
});
console.log('Received values of form: ', values); console.log('Received values of form: ', values);
let data = "username="+values.username+"&password="+values.password+"&platform=publisher"; let data = "username=" + values.username + "&password=" + values.password + "&platform=publisher";
axios.post('https://localhost:9443/api/application-mgt-handler/v1.0/login', data axios.post('https://localhost:9443/api/application-mgt-handler/v1.0/login', data
).then(res => { ).then(res => {
console.log(res); if (res.status === 200) {
console.log(res.data); window.location = res.data.url;
}) }
}).catch(function (error) {
if (error.response.status === 400) {
thisForm.setState({
inValid: true,
loading: false
});
}
});
} }
}); });
@ -53,6 +78,14 @@ class NormalLoginForm extends React.Component {
render() { render() {
const {getFieldDecorator} = this.props.form; const {getFieldDecorator} = this.props.form;
let errorMsg = "";
if (this.state.inValid) {
errorMsg = <Text type="danger">Invalid Login Details</Text>;
}
let loading = "";
if (this.state.loading) {
loading = <Text type="secondary">Loading..</Text>;
}
return ( return (
<Form onSubmit={this.handleSubmit} className="login-form"> <Form onSubmit={this.handleSubmit} className="login-form">
<Form.Item> <Form.Item>
@ -72,13 +105,16 @@ class NormalLoginForm extends React.Component {
placeholder="Password"/> placeholder="Password"/>
)} )}
</Form.Item> </Form.Item>
{loading}
{errorMsg}
<Form.Item> <Form.Item>
{getFieldDecorator('remember', { {getFieldDecorator('remember', {
valuePropName: 'checked', valuePropName: 'checked',
initialValue: true, initialValue: true,
})( })(
<Checkbox>Remember me....</Checkbox> <Checkbox>Remember me</Checkbox>
)} )}
<br/>
<a className="login-form-forgot" href="">Forgot password</a> <a className="login-form-forgot" href="">Forgot password</a>
<Button block type="primary" htmlType="submit" className="login-form-button"> <Button block type="primary" htmlType="submit" className="login-form-button">
Log in Log in

@ -1,19 +1,20 @@
import React from "react"; import React from "react";
import { Layout, Menu, Icon } from 'antd'; import {Layout, Menu, Icon} from 'antd';
const { Header, Content, Footer } = Layout; const {Header, Content, Footer} = Layout;
import styles from './Dashboard.less'; import styles from './Dashboard.less';
import Logo from "../../../public/images/logo.svg"; import Logo from "../../../public/images/logo.svg";
import {Link, NavLink} from "react-router-dom"; import {Link, NavLink} from "react-router-dom";
import RouteWithSubRoutes from "../../components/RouteWithSubRoutes" import RouteWithSubRoutes from "../../components/RouteWithSubRoutes"
import { Switch, Redirect } from 'react-router'
class Dashboard extends React.Component { class Dashboard extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
routes : props.routes routes: props.routes
} }
} }
@ -28,20 +29,24 @@ class Dashboard extends React.Component {
theme="light" theme="light"
mode="horizontal" mode="horizontal"
defaultSelectedKeys={['2']} defaultSelectedKeys={['2']}
style={{ lineHeight: '64px' }} style={{lineHeight: '64px'}}
> >
<Menu.Item key="1"><Link to="apps"><Icon type="appstore" />Apps</Link></Menu.Item> <Menu.Item key="1"><Link to="apps"><Icon type="appstore"/>Apps</Link></Menu.Item>
<Menu.Item key="2"><Link to="apps"><Icon type="line-chart" />Apps</Link></Menu.Item> <Menu.Item key="2"><Link to="apps"><Icon type="line-chart"/>Apps</Link></Menu.Item>
<Menu.Item key="3"><Link to="new-app"><Icon type="upload" />Add New App</Link></Menu.Item> <Menu.Item key="3"><Link to="new-app"><Icon type="upload"/>Add New App</Link></Menu.Item>
</Menu> </Menu>
</Header> </Header>
<Content style={{ padding: '0 0' }}> <Content style={{padding: '0 0'}}>
{this.state.routes.map((route) => ( <Switch>
<RouteWithSubRoutes key={route.path} {...route} /> <Redirect exact from="/publisher" to="/publisher/apps"/>
))} {this.state.routes.map((route) => (
<RouteWithSubRoutes key={route.path} {...route} />
))}
</Switch>
</Content> </Content>
<Footer style={{ textAlign: 'center' }}> <Footer style={{textAlign: 'center'}}>
©2019 entgra.io ©2019 entgra.io
</Footer> </Footer>
</Layout> </Layout>

Loading…
Cancel
Save