mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Merge branch 'master' of https://github.com/ClaytonWWilson/CS307-Team24
This commit is contained in:
commit
c241455c4b
@ -36,7 +36,7 @@ class App extends Component {
|
|||||||
<Route exact path="/user" component={user}/>
|
<Route exact path="/user" component={user}/>
|
||||||
<Route exact path="/home" component={writeMicroblog}/>
|
<Route exact path="/home" component={writeMicroblog}/>
|
||||||
<Route exact path="/edit" component={edit}/>
|
<Route exact path="/edit" component={edit}/>
|
||||||
<Route exact path="/userline" component={userLine}/>
|
<Route exact path="/user" component={userLine}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Router>
|
</Router>
|
||||||
|
|||||||
@ -1,26 +1,73 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import '../App.css';
|
import '../App.css';
|
||||||
|
import axios from 'axios';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import logo from '../images/twistter-logo.png';
|
import logo from '../images/twistter-logo.png';
|
||||||
import TextField from '@material-ui/core/TextField';
|
import TextField from '@material-ui/core/TextField';
|
||||||
|
|
||||||
class Login extends Component {
|
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() {
|
render() {
|
||||||
|
const { classes } = this.props;
|
||||||
|
const { errors } = this.state;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<b>Log in to Twistter</b>
|
<b>Log in to Twistter</b>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<TextField className="authInput" id="email" name="email" label="Email" />
|
<form noValidate onSubmit={this.handleSubmit}>
|
||||||
|
<TextField className="authInput" id="email" name="email" label="Email" helperText={errors.email} error={errors.email ? true : false}
|
||||||
|
value={this.state.email} onChange={this.handleChange} />
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<TextField className="authInput" id="password" name="password" label="Password" />
|
<TextField className="authInput" id="password" name="password" label="Password" helperText={errors.password} error={errors.password ? true : false}
|
||||||
|
value={this.state.password} onChange={this.handleChange} />
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
|
||||||
<button className="authButtons register" type="submit">Sign in</button>
|
<button className="authButtons register" type="submit">Sign in</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Login.propTypes = {
|
||||||
|
classes: PropTypes.object.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export default Login;
|
export default Login;
|
||||||
@ -2,28 +2,96 @@ import React, { Component } from 'react';
|
|||||||
import '../App.css';
|
import '../App.css';
|
||||||
|
|
||||||
import logo from '../images/twistter-logo.png';
|
import logo from '../images/twistter-logo.png';
|
||||||
|
import axios from 'axios';
|
||||||
import TextField from '@material-ui/core/TextField';
|
import TextField from '@material-ui/core/TextField';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
|
||||||
class Register extends Component {
|
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() {
|
render() {
|
||||||
|
const { classes } = this.props;
|
||||||
|
const { errors } = this.state;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<b>Create your account</b>
|
<b>Create your account</b>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<TextField className="authInput" id="email" name="email" label="Email" />
|
<form noValidate onSubmit={this.handleSubmit}>
|
||||||
|
|
||||||
|
<TextField className="authInput" id="email" name="email" label="Email" helperText={errors.email} error={errors.email ? true : false}
|
||||||
|
value={this.state.email} onChange={this.handleChange}/>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<TextField className="authInput" id="username" name="username" label="Username" />
|
<TextField className="authInput" id="username" name="handle" label="Username" helperText={errors.handle} error={errors.handle ? true : false}
|
||||||
|
value={this.state.handle} onChange={this.handleChange} />
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<TextField className="authInput" id="password" name="password" label="Password" />
|
<TextField className="authInput" id="password" name="password" label="Password" helperText={errors.password} error={errors.password ? true : false}
|
||||||
|
value={this.state.password} onChange={this.handleChange} />
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<TextField className="authInput" id="confirmPassword" name="confirmPassword" label="Confirm Password" />
|
<TextField className="authInput" id="confirmPassword" name="confirmPassword" label="Confirm Password" helperText={errors.confirmPassword} error={errors.confirmPassword ? true : false}
|
||||||
|
value={this.state.confirmPassword} onChange={this.handleChange} />
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
{
|
||||||
|
errors.general &&
|
||||||
|
(<div className={classes.customError}>
|
||||||
|
{errors.general}
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
<button class="authButtons register" id="submit">Sign up</button>
|
<button class="authButtons register" id="submit">Sign up</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Register.propTypes = {
|
||||||
|
classes: PropTypes.object.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
export default Register;
|
export default Register;
|
||||||
Loading…
Reference in New Issue
Block a user