Merge branch 'master' into profile_display

This commit is contained in:
Leon Liang
2019-10-24 22:12:02 -04:00
committed by GitHub
17 changed files with 291 additions and 244 deletions

View File

@@ -1,5 +1,10 @@
This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).
Cloud: https://us-central1-twistter-e4649.cloudfunctions.net/api
Local: http://localhost:5001/twistter-e4649/us-central1/api (npm install --save firebase)
Below you will find some information on how to perform common tasks.<br>
You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md).

View File

@@ -27,6 +27,7 @@ import signup from './pages/Signup';
import login from './pages/Login';
import user from './pages/user';
import logout from './pages/Logout';
import Delete from './pages/Delete';
import writeMicroblog from './Writing_Microblogs.js';
import editProfile from './pages/editProfile';
import userLine from './Userline.js';
@@ -63,6 +64,7 @@ class App extends Component {
<AuthRoute exact path="/signup" component={signup} />
<AuthRoute exact path="/login" component={login} />
<Route exact path="/logout" component={logout} />
<Route exact path="/delete" component={Delete} />
<Route exact path="/user" component={user} />
<Route exact path="/home" component={writeMicroblog} />

View File

@@ -50,9 +50,12 @@ import withStyles from "@material-ui/core/styles/withStyles";
<Button component={ Link } to='/signup'>
Sign Up
</Button>
<Button component={ Link } to='/logout'>
Logout
</Button>
<Button component={ Link } to='/logout'>
Logout
</Button>
<Button component={ Link } to='/delete'>
Delete Account
</Button>
</ToolBar>
</AppBar>
)

View File

@@ -0,0 +1,56 @@
/* eslint-disable */
import React, { Component } from "react";
import PropTypes from "prop-types";
// Material UI stuff
import Button from "@material-ui/core/Button";
import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff
import { logoutUser } from "../redux/actions/userActions";
import { connect } from "react-redux";
const styles = {
form: {
textAlign: "center"
},
textField: {
marginBottom: 30
},
pageTitle: {
marginBottom: 40
},
button: {
positon: "relative",
marginBottom: 30
},
progress: {
position: "absolute"
}
};
export class Delete extends Component {
componentDidMount() {
this.props.logoutUser();
this.props.history.push('/');
}
render() {
return null;
}
}
const mapStateToProps = (state) => ({
user: state.user
});
const mapActionsToProps = { logoutUser };
Delete.propTypes = {
logoutUser: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired
};
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Delete));

View File

@@ -146,7 +146,7 @@ export class Login extends Component {
)}
</Button>
{errors.general && (
<Typography color="error">Wrong Email or Password</Typography>
<Typography color="error">Invalid username/email or password</Typography>
)}
</form>
</Grid>

View File

@@ -159,7 +159,7 @@ export class Signup extends Component {
)}
</Button>
{errors.general && (
<Typography color="error">Wrong Email or Password</Typography>
<Typography color="error">Invalid username/email or password</Typography>
)}
</form>
</Grid>

View File

@@ -88,6 +88,14 @@ export class edit extends Component {
handle: this.state.handle,
bio: this.state.bio
};
// Removes all keys from newProfileData that are empty, undefined, or null
Object.keys(newProfileData).forEach(key => {
if (newProfileData[key] === "" || newProfileData[key] === undefined || newProfileData[key] === null) {
delete newProfileData[key];
}
})
axios
.post("/updateProfileInfo", newProfileData)
.then((res) => {

View File

@@ -61,6 +61,26 @@ export const logoutUser = () => (dispatch) => {
dispatch({ type: SET_UNAUTHENTICATED });
}
export const deleteUser = () => (dispatch) => {
axios
.delete("/delete")
.then((res) => {
console.log(res);
console.log("User account successfully deleted.");
}
)
.catch((err) => {
dispatch ({
type: SET_ERRORS,
payload: err.response.data,
})
});
localStorage.removeItem('FBIdToken');
delete axios.defaults.headers.common['Authorization'];
dispatch({ type: SET_UNAUTHENTICATED });
}
const setAuthorizationHeader = (token) => {
const FBIdToken = `Bearer ${token}`;
localStorage.setItem('FBIdToken', FBIdToken);