diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index d541be6..e111282 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -36,7 +36,7 @@ class App extends Component { - + diff --git a/twistter-frontend/src/pages/Login.js b/twistter-frontend/src/pages/Login.js index 76531d2..2b671ce 100644 --- a/twistter-frontend/src/pages/Login.js +++ b/twistter-frontend/src/pages/Login.js @@ -1,26 +1,73 @@ /* eslint-disable */ import React, { Component } from 'react'; import '../App.css'; +import axios from 'axios'; +import PropTypes from 'prop-types'; import logo from '../images/twistter-logo.png'; import TextField from '@material-ui/core/TextField'; class Login extends Component { + constructor() { + super(); + this.state = { + email: '', + password: '', + errors: {} + }; + this.handleChange = this.handleChange.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); +}; +handleSubmit = (event) => { + event.preventDefault(); + const userData = { + email: this.state.email, + password: this.state.password + }; + axios.post('http://localhost:5001/twistter-e4649/us-central1/api/login', userData) + .then(res => { + console.log(res.data); + localStorage.setItem('firebaseIdToken', `Bearer ${res.data.token}`); + this.props.history.push('/home'); + }) + .catch(err => { + this.setState({ + errors: err.response.data + }); + }); +}; +handleChange = (event) => { + this.setState({ + [event.target.name]: event.target.value + }); +}; + render() { + const { classes } = this.props; + const { errors } = this.state; return (
logo

Log in to Twistter

- +
+

- +

+ +
); }; } +Login.propTypes = { + classes: PropTypes.object.isRequired +}; + export default Login; \ No newline at end of file diff --git a/twistter-frontend/src/pages/Register.js b/twistter-frontend/src/pages/Register.js index 3d5db00..d168315 100644 --- a/twistter-frontend/src/pages/Register.js +++ b/twistter-frontend/src/pages/Register.js @@ -2,28 +2,96 @@ import React, { Component } from 'react'; import '../App.css'; import logo from '../images/twistter-logo.png'; +import axios from 'axios'; import TextField from '@material-ui/core/TextField'; +import PropTypes from 'prop-types'; + class Register extends Component { + + constructor() { + super(); + this.state = { + email: '', + handle: '', + password: '', + confirmPassword: '', + errors: {} + }; + + this.handleSubmit = this.handleSubmit.bind(this); + this.handleChange = this.handleChange.bind(this); +}; + + +handleSubmit = (event) => { + const newUserData = { + email: this.state.email, + handle: this.state.handle, + password: this.state.password, + confirmPassword: this.state.confirmPassword + }; + axios.post('http://localhost:5001/twistter-e4649/us-central1/api/signup', newUserData) + .then(res => { + console.log(res.data); + localStorage.setItem('firebaseIdToken', `Bearer ${res.data.token}`); + this.props.history.push('/'); + }) + .catch(err => { + this.setState({ + errors: err.response.data + }); + }); + alert("You successfully registered"); + event.preventDefault(); + this.setState({email: '', handle: '', password: '', confirmPassword: ''}); +}; + + +handleChange = (event) => { + this.setState({ + [event.target.name]: event.target.value + }); +}; + render() { + const { classes } = this.props; + const { errors } = this.state; return (
logo

Create your account

- +
+ +

- +

- +

- +

+ { + errors.general && + (
+ {errors.general} +
) + } +
); } + } +Register.propTypes = { + classes: PropTypes.object.isRequired +}; export default Register; \ No newline at end of file