Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions README.md

This file was deleted.

4 changes: 4 additions & 0 deletions front/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"]
}
1 change: 1 addition & 0 deletions front/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_URL='http://localhost:3000'
21 changes: 21 additions & 0 deletions front/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": [ "error", "single" ],
"semi": ["error", "always"],
"linebreak-style": [ "error", "unix" ]
},
"env": {
"es6": true,
"node": true,
"mocha": true,
"jasmine": true
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true,
"impliedStrict": true
},
"extends": "eslint:recommended"
}
2 changes: 2 additions & 0 deletions front/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/.env
26 changes: 26 additions & 0 deletions front/npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
0 info it worked if it ends with ok
1 verbose cli [ '/Users/Eddie/.nvm/versions/node/v6.11.1/bin/node',
1 verbose cli '/Users/Eddie/.nvm/versions/node/v6.11.1/bin/npm',
1 verbose cli 'run',
1 verbose cli 'start' ]
2 info using npm@3.10.10
3 info using node@v6.11.1
4 verbose stack Error: missing script: start
4 verbose stack at run (/Users/Eddie/.nvm/versions/node/v6.11.1/lib/node_modules/npm/lib/run-script.js:151:19)
4 verbose stack at /Users/Eddie/.nvm/versions/node/v6.11.1/lib/node_modules/npm/lib/run-script.js:61:5
4 verbose stack at /Users/Eddie/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5
4 verbose stack at checkBinReferences_ (/Users/Eddie/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45)
4 verbose stack at final (/Users/Eddie/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3)
4 verbose stack at then (/Users/Eddie/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5)
4 verbose stack at ReadFileContext.<anonymous> (/Users/Eddie/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/read-package-json/read-json.js:295:20)
4 verbose stack at ReadFileContext.callback (/Users/Eddie/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16)
4 verbose stack at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:366:13)
5 verbose cwd /Users/Eddie/codefellows/401/labs/32-auth/front
6 error Darwin 16.7.0
7 error argv "/Users/Eddie/.nvm/versions/node/v6.11.1/bin/node" "/Users/Eddie/.nvm/versions/node/v6.11.1/bin/npm" "run" "start"
8 error node v6.11.1
9 error npm v3.10.10
10 error missing script: start
11 error If you need help, you may report this error at:
11 error <https://github.com/npm/npm/issues>
12 verbose exit [ 1, true ]
39 changes: 39 additions & 0 deletions front/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "frontend",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"build": "webpack",
"watch": "webpack-dev-server --inline --hot"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.16",
"css-loader": "^0.28.7",
"dotenv": "^4.0.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"html-webpack-plugin": "^2.30.1",
"node-sass": "^4.5.3",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-redux": "^5.0.6",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"redux": "^3.7.2",
"sass-loader": "^6.0.6",
"superagent": "^3.6.0",
"uglifyjs-webpack-plugin": "^0.4.6",
"url-loader": "^0.5.9",
"webpack": "^3.5.6",
"webpack-dev-server": "^2.7.1"
}
}
40 changes: 40 additions & 0 deletions front/src/action/auth-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import superagent from 'superagent';

export const tokenSet = token => ({
type: 'TOKEN_SET',
payload: token
});

export const tokenDelete = () => ({
type: 'TOKEN_DELETE',
});

export const signupRequest = user => dispatch => {
return superagent.post(`${__API_URL__}/signup`)
.withCredentials()
.send(user)
.then(res => {
dispatch(tokenSet(res.text))
try {
localStorage.auth = res.text;
} catch(err) {
console.error(err);
}
return res;
})
}

export const loginRequest = user => dispatch => {
return superagent.get(`${__API_URL__}/login`)
.withCredentials()
.auth(user.username, user.password)
.then(res => {
dispatch(tokenSet(res.text));
try {
localStorage.auth = res.text;
} catch(err) {
console.error(err);
}
return res;
})
}
23 changes: 23 additions & 0 deletions front/src/action/profile-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import superagent from 'superagent';

export const profileCreate = profile => ({
type: 'PROFILE_CREATE',
payload: profile
});

export const profileUpdate = profile => ({
type: 'PROFILE_UPDATE',
payload: profile
});

export const profileCreateRequest = profile => (dispatch, getState) => {
let {auth} = getState();
return superagent.post(`${__API_URL__}/profiles`)
.set('Authorization', `Bearer ${auth}`)
.field('bio', profile.bio)
.attach('avatar', profile.avatar)
.then(res => {
dispatch(profileCreate(res.body));
return res;
});
};
32 changes: 32 additions & 0 deletions front/src/component/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import {Provider} from 'react-redux';
import {BrowserRouter, Route, Link} from 'react-router-dom';

import Dashboard from '../dashboard';
import createAppStore from '../../lib/createAppStore.js';

let store = createAppStore()

class App extends React.Component {
render() {
return(
<span id="app">
<Provider store={store}>
<BrowserRouter>
<section>
<nav>
<ul>
<li><Link to='/welcome/signup'>signup</Link></li>
<li><Link to='/welcome/login'>login</Link></li>
</ul>
</nav>
<Route path='/welcome/:auth' component={Dashboard} />
</section>
</BrowserRouter>
</Provider>
</span>
)
}
}

export default App;
97 changes: 97 additions & 0 deletions front/src/component/auth-form/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from 'react';
import * as util from '../../lib/util.js';

class AuthForm extends React.Component {
constructor(props) {
super(props);
this.state = {
username: '',
password: '',
email: '',
usernameError: null,
passwordError: null,
emailError: null,
error: null
}

this.onChange = this.onChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}

onChange(e) {
let {name, value} = e.target;

function errorCheck(errorName) {
return name === errorName && !value ? `${errorName} required`: null;
}

this.setState({
[name]: value,
usernameError: errorCheck('username'),
emailError: errorCheck('email'),
passwordError: errorCheck('password')
})
}

onSubmit(e) {
e.preventDefault();

this.props.onComplete(this.state)
.then(() => {
this.setState({ username: '', email: '', password: ''})
})
.catch(error => {
console.error(error);
this.setState({error});
})
}




render() {

let emailInput = (
<input
name='email'
type='text'
placeholder='Enter a valid email address'
value={this.state.email}
onChange={this.onChange}
/>
)

return(
<form onSubmit={this.onSubmit}>
<input
name='username'
type='text'
placeholder='Enter a username'
value={this.state.username}
onChange={this.onChange}
/>
{util.renderIf(this.state.usernameError,
<span className='tooltip'>
{this.state.usernameError}
</span>
)}
<input
name='password'
type='password'
placeholder='Enter a password'
value={this.state.password}
onChange={this.onChange}
/>
{util.renderIf(this.state.passwordError,
<span className='tooltip'>
{this.state.passwordError}
</span>
)}
{util.renderIf(this.props.auth === 'signup', emailInput)}
<button type='submit'>{this.props.buttonText}</button>
</form>
)
}
}

export default AuthForm;
33 changes: 33 additions & 0 deletions front/src/component/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import {connect} from 'react-redux';

import AuthFrom from '../auth-form';
import * as authReqs from '../../action/auth-action.js'

class Dashboard extends React.Component {
render() {

let {params} = this.props.match;

let onComplete = params.auth === 'login'?
this.props.login:
this.props.signup;

return(
<AuthFrom
onComplete={onComplete}
auth={params.auth}
buttonText={params.auth}
/>
)
}
};

let mapDispatchToProps = dispatch => {
return {
signup: user => dispatch(authReqs.signupRequest(user)),
login: user => dispatch(authReqs.loginRequest(user))
}
}

export default connect(undefined, mapDispatchToProps)(Dashboard);
Empty file.
10 changes: 10 additions & 0 deletions front/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Every day that passes brings us one step closer to the void</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
Loading