-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97cde6c
commit ed00ea7
Showing
2 changed files
with
47 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |