Skip to content

Commit

Permalink
fix(): login
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Aug 15, 2019
1 parent 97cde6c commit ed00ea7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/js/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ const store = configureStore();
export default class App extends React.Component {
constructor(props){
super(props);

Parse.initialize(process.env.REACT_APP_parseAppId , process.env.REACT_APP_parseJavascriptKey);
Parse.serverURL = process.env.REACT_APP_parseServerUrl;
console.log(Parse.User);
}
render() {
return (
Expand Down
53 changes: 46 additions & 7 deletions src/js/pages/Login.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,78 @@
import React from 'react';
import { Link } from "react-router-dom";
import Parse from 'parse';
import { Redirect } from "react-router-dom";

import { Button, Form, Grid, Header, Image, Message, Segment } from 'semantic-ui-react';

class LoginForm extends React.Component{
constructor(props){
super(props);

Parse.initialize(process.env.REACT_APP_parseAppId , process.env.REACT_APP_parseJavascriptKey);
Parse.serverURL = process.env.REACT_APP_parseServerUrl;

this.state = {
username: '',
password: '',
toDashboard: false
}
}

handleChange = (e, { name, value }) => this.setState({
[name]: value
})

logIn = () => {
// Create a new instance of the user class
var that = this;
Parse.User.logIn(this.state.username, this.state.password).then(function(user) {
console.log('User created successful with name: ' + user.get("username") + ' and email: ' + user.get("email"));
that.setState({
toDashboard:true
});
})/*.catch(function(error){
console.log("Error: " + error.code + " " + error.message);
});*/
}
render(){
if (this.state.toDashboard === true) {
return <Redirect to='/app/home' />
}

const { username, password } = this.state;

return(
<Grid textAlign='center' style={{ height: '100vh' }} verticalAlign='middle'>
<Grid.Column style={{ maxWidth: 450 }}>
<Header as='h2' color='teal' textAlign='center'>
Log-in to your account
</Header>
<Form size='large'>
<Form size='large' onSubmit={this.handleSubmit}>
<Segment stacked>
<Form.Input fluid icon='user' iconPosition='left' placeholder='E-mail address' />
<Form.Input fluid icon='user' iconPosition='left' placeholder='E-mail address' name='username' value={username} onChange={this.handleChange} />
<Form.Input
fluid
icon='lock'
iconPosition='left'
placeholder='Password'
type='password'
name='password'
value={password}
onChange={this.handleChange}
/>
<Button as={Link} to='/app/home' color='teal' fluid size='large'>
<Button onClick={this.logIn} color='teal' fluid size='large'>
Login
</Button>
</Segment>
</Form>
{/*<Message>
<Message>
New to us? <a href='/'>Sign Up</a>
</Message>*/}
</Message>
</Grid.Column>
</Grid>
)
}
}

{/* as={Link} to='/app/home' */}

export default LoginForm;

0 comments on commit ed00ea7

Please sign in to comment.