From 29c07a9b144dd8f16da38de83d93263cf08774b7 Mon Sep 17 00:00:00 2001 From: Danny Voltz Date: Wed, 2 Oct 2019 16:24:01 -0500 Subject: [PATCH 1/2] commit --- twistter-frontend/src/App.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index f7157c9..27042e7 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -5,16 +5,16 @@ import './App.css'; import { BrowserRouter as Router } from 'react-router-dom'; import Route from 'react-router-dom/Route'; + import NavBar, { Navbar } from './components/layout/NavBar'; -// Pages import home from './Home.js'; import register from './Register.js'; import login from './Login.js'; import user from './pages/user'; import writeMicroblog from './Writing_Microblogs.js'; -import edit from './pages/edit.js'; import userLine from './Userline.js'; +import logout from './Logout.js' class App extends Component { render() { @@ -30,8 +30,8 @@ class App extends Component { - + @@ -39,4 +39,4 @@ class App extends Component { } } -export default App; \ No newline at end of file +export default App; From 64657fa3af4c6fa98f4bfd3531c416605ae4a69e Mon Sep 17 00:00:00 2001 From: Aditya Sankaran Date: Thu, 3 Oct 2019 09:29:22 -0400 Subject: [PATCH 2/2] fixed login and register. working on frontend now --- twistter-frontend/src/App.js | 2 +- twistter-frontend/src/pages/Login.js | 51 ++++++++++++++++- twistter-frontend/src/pages/Register.js | 76 +++++++++++++++++++++++-- 3 files changed, 122 insertions(+), 7 deletions(-) diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index f7c6c32..ccbff92 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