2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import * as React from 'react';
19 import { withRouter, RouteComponentProps } from 'react-router-dom';
21 import Alert from '@material-ui/lab/Alert';
22 import Avatar from '@material-ui/core/Avatar';
23 import Button from '@material-ui/core/Button';
24 import CssBaseline from '@material-ui/core/CssBaseline';
25 import FormControl from '@material-ui/core/FormControl';
26 import FormControlLabel from '@material-ui/core/FormControlLabel';
27 import Checkbox from '@material-ui/core/Checkbox';
28 import Input from '@material-ui/core/Input';
29 import InputLabel from '@material-ui/core/InputLabel';
30 import LockIcon from '@material-ui/icons/LockOutlined';
31 import Paper from '@material-ui/core/Paper';
32 import Typography from '@material-ui/core/Typography';
33 import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';
35 import connect, { Connect } from '../flux/connect';
36 import authenticationService from '../services/authenticationService';
38 import { UpdateAuthentication } from '../actions/authentication';
40 const styles = (theme: Theme) => createStyles({
43 display: 'block', // Fix IE11 issue.
44 marginLeft: theme.spacing(3),
45 marginRight: theme.spacing(3),
46 [theme.breakpoints.up(400 + theme.spacing(3) * 2)]: {
53 marginTop: theme.spacing(8),
55 flexDirection: 'column',
57 padding: `${theme.spacing(2)}px ${theme.spacing(3)}px ${theme.spacing(3)}px`,
60 margin: theme.spacing(1),
61 backgroundColor: theme.palette.secondary.main,
64 width: '100%', // Fix IE11 issue.
65 marginTop: theme.spacing(1),
68 marginTop: theme.spacing(3),
72 type LoginProps = RouteComponentProps<{}> & WithStyles<typeof styles> & Connect;
74 interface ILoginState {
83 // todo: ggf. redirect to einbauen
84 class LoginComponent extends React.Component<LoginProps, ILoginState> {
86 constructor(props: LoginProps) {
98 render(): JSX.Element {
99 const { classes } = this.props;
103 <main className={classes.layout}>
104 <Paper className={classes.paper}>
105 <Avatar className={classes.avatar}>
108 <Typography variant="caption">Sign in</Typography>
109 <form className={classes.form}>
110 <FormControl margin="normal" required fullWidth>
111 <InputLabel htmlFor="username">Username</InputLabel>
112 <Input id="username" name="username" autoComplete="username" autoFocus
113 disabled={this.state.busy}
114 value={this.state.username}
115 onChange={event => { this.setState({ username: event.target.value }) }} />
117 <FormControl margin="normal" required fullWidth>
118 <InputLabel htmlFor="password">Password</InputLabel>
123 autoComplete="current-password"
124 disabled={this.state.busy}
125 value={this.state.password}
126 onChange={event => { this.setState({ password: event.target.value }) }}
129 <FormControl margin="normal" required fullWidth>
130 <InputLabel htmlFor="password">Domain</InputLabel>
135 disabled={this.state.busy}
136 value={this.state.scope}
137 onChange={event => { this.setState({ scope: event.target.value }) }}
141 control={<Checkbox value="remember" color="secondary" />}
149 disabled={this.state.busy}
150 className={classes.submit}
151 onClick={this.onSignIn}
156 {this.state.message && <Alert severity="error">{this.state.message}</Alert>}
163 private onSignIn = async (event: React.MouseEvent<HTMLButtonElement>) => {
164 event.preventDefault();
166 this.setState({ busy: true });
167 // const token = await authenticationService.authenticateUserOAuth(this.state.username, this.state.password, this.state.scope);
168 const token = await authenticationService.authenticateUserBasicAuth(this.state.username, this.state.password, this.state.scope);
169 this.props.dispatch(new UpdateAuthentication(token));
170 this.setState({ busy: false });
174 this.props.state.framework.navigationState.search &&
175 this.props.state.framework.navigationState.search.replace(/^\?/, "")
176 .split('&').map(e => e.split("="));
177 const returnTo = query && query.find(e => e[0] === "returnTo");
178 this.props.history.replace(returnTo && returnTo[1] || "/");
182 message: "Could not log in. Please check your credentials or ask your administrator for assistence.",
189 export const Login = withStyles(styles)(withRouter(connect()(LoginComponent)));
190 export default Login;