From c19f06ea3f201dcf25d22aadb9849658b82d4c7e Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 14:24:45 -0700 Subject: [PATCH 01/32] Created scaffolding for front end --- front/.babelrc | 0 front/.env | 0 front/package.json | 12 ++++++++++++ front/src/index.html | 0 front/src/main.js | 0 front/webpack.config.js | 0 6 files changed, 12 insertions(+) create mode 100644 front/.babelrc create mode 100644 front/.env create mode 100644 front/package.json create mode 100644 front/src/index.html create mode 100644 front/src/main.js create mode 100644 front/webpack.config.js diff --git a/front/.babelrc b/front/.babelrc new file mode 100644 index 0000000..e69de29 diff --git a/front/.env b/front/.env new file mode 100644 index 0000000..e69de29 diff --git a/front/package.json b/front/package.json new file mode 100644 index 0000000..c03ccc9 --- /dev/null +++ b/front/package.json @@ -0,0 +1,12 @@ +{ + "name": "front", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/front/src/index.html b/front/src/index.html new file mode 100644 index 0000000..e69de29 diff --git a/front/src/main.js b/front/src/main.js new file mode 100644 index 0000000..e69de29 diff --git a/front/webpack.config.js b/front/webpack.config.js new file mode 100644 index 0000000..e69de29 From 369122989c91f04b03a1319bd59f09c5d5c40e85 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 14:25:45 -0700 Subject: [PATCH 02/32] Removed stock README.md file --- README.md | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 5c5bf64..0000000 --- a/README.md +++ /dev/null @@ -1,49 +0,0 @@ -![cf](https://i.imgur.com/7v5ASc8.png) 32: Authentication and Authorization -====== - -## Submission Instructions -* fork this repository & create a new branch for your work -* write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan` -* push to your repository -* submit a pull request to this repository -* submit a link to your PR in canvas -* write a question and observation on canvas - -## Learning Objectives -* students will be able to manage basic and bearer auth on the client side -* students will learn to manage cookies on the client side - -## Requirements -#### Configuration -#### backend -* clone [sluggram-backend](http://github.com/slugbyte/sluggram) - -##### frontend -* `README.md` -* `.babelrc` -* `.gitignore` -* `package.json` -* `webpack.config.js` -* `src/**` -* `src/main.js` -* `src/style` -* `src/style/main.scss` -* `src/style/lib` - * `_vars.scss` -* `src/style/base` - * `_base.scss` - * `_reset.scss` -* `src/style/layout` - * `_header.scss` - * `_footer.scss` - * `_content.scss` - -#### Feature Tasks -* create a simple front end for your cf-gram (or comparable) API -* create a landing page that enables a user to signup and signin - * redirect the user to the dashboard page on signup or signin - * store the users token in `localStorage` on signin - -#### Test -* test your redux reducers -* **optional:** test your `util` methods From 261645b577d868ff6038cc0f75354944d0630002 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 14:36:27 -0700 Subject: [PATCH 03/32] Added .env file to sluggram backend --- sluggram | 1 + 1 file changed, 1 insertion(+) create mode 160000 sluggram diff --git a/sluggram b/sluggram new file mode 160000 index 0000000..1fc6e99 --- /dev/null +++ b/sluggram @@ -0,0 +1 @@ +Subproject commit 1fc6e992ae12d84d6e3f8dfc67a18c9f2eca29ad From 1d82802a39326110876cb2c5ad5de53ed6cdaca5 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 15:49:15 -0700 Subject: [PATCH 04/32] Added package.json dependancies and added custom npm scripts --- front/.babelrc | 4 ++ front/.env | 1 + front/.gitignore | 2 + front/package.json | 28 +++++++++++++- front/webpack.config.js | 85 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 front/.gitignore diff --git a/front/.babelrc b/front/.babelrc index e69de29..4285987 100644 --- a/front/.babelrc +++ b/front/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": ["es2015", "react"], + "plugins": [] +} diff --git a/front/.env b/front/.env index e69de29..eb4ac6b 100644 --- a/front/.env +++ b/front/.env @@ -0,0 +1 @@ +API_URL='http://localhost:3000' diff --git a/front/.gitignore b/front/.gitignore new file mode 100644 index 0000000..94c74ef --- /dev/null +++ b/front/.gitignore @@ -0,0 +1,2 @@ +/node_modules +/.env diff --git a/front/package.json b/front/package.json index c03ccc9..6e0bd35 100644 --- a/front/package.json +++ b/front/package.json @@ -4,9 +4,33 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "webpack", + "watch": "webpack-dev-server --inline --hot" }, "keywords": [], "author": "", - "license": "ISC" + "license": "ISC", + "dependencies": { + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "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-dom": "^4.2.2", + "redux": "^3.7.2", + "sass-loader": "^6.0.6", + "uglifyjs-webpack-plugin": "^0.4.6", + "url-loader": "^0.5.9", + "webpack": "^3.5.6", + "webpack-dev-server": "^2.7.1" + } } diff --git a/front/webpack.config.js b/front/webpack.config.js index e69de29..9dc9986 100644 --- a/front/webpack.config.js +++ b/front/webpack.config.js @@ -0,0 +1,85 @@ +'use strict'; + +const HtmlPlugin = require('html-webpack-plugin'); +const ExtractPlugin = require('extract-text-webpack-plugin'); +const UglifyPlugin = require('uglifyjs-webpack-plugin'); +const CleanPlugin = require('clean-webpack-plugin'); +const {DefinePlugin, EnvironmentPlugin} = require('webpack'); + +let production = process.env.NODE_ENV === 'production'; + +let plugins = [ + new HtmlPlugin({template: `${__dirname}/src/index.html`}), + new ExtractPlugin('bundle-[hash].css'), + new EnvironmentPlugin(['NODE_ENV']), + new DefinePlugin({ + __DEBUG__: JSON.stringify(!production), + __API_URL__: JSON.stringify(process.env.API_URL) + }) +]; + +if(production) { + plugins = [...plugins, new CleanPlugin, new UglifyPlugin]; +} + +module.exports = { + devtool: production ? undefined : 'eval', + entry: `${__dirname}/src/main.js`, + devServer: { + historyApiFallback: true + }, + plugins, + output: { + path: `${__dirname}/build`, + filename: 'bundle-[hash].js', + publicPath: process.env.CDN_URL + }, + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader' + }, + { + test: /\.scss$/, + loader: ExtractPlugin.extract(['css-loader', 'sass-loader']) + }, + { + test: /\.(woff|woff2|ttf|eot|glyph|\.svg)$/, + use: [ + { + loader: 'url-loader', + options: { + limit: 10000, + name: 'font/[name].[ext]' + } + } + ] + }, + { + test: /\.(jpg|jpeg|gif|png|tiff|svg)$/, + exclude: /\.glyph.svg/, + use: [ + { + loader: 'url-loader', + options: { + limit: 6000, + name: 'image/[name].[ext]' + } + } + ] + }, + { + test: /\.(mp3|aac|aiff|wav|flac|m4a|mp4|ogg)$/, + exclude: /\.glyph.svg/, + use: [ + { + loader: 'file-loader', + options: { name: 'audio/[name].[ext]' } + } + ] + } + ] + } +}; From da6127da73f2bcc3f206c1da2972ad5d650d1be3 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 15:52:00 -0700 Subject: [PATCH 05/32] Wrote bare minimum to run npm run watch and render a webpage --- front/src/index.html | 10 ++++++++++ front/src/main.js | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/front/src/index.html b/front/src/index.html index e69de29..6c60996 100644 --- a/front/src/index.html +++ b/front/src/index.html @@ -0,0 +1,10 @@ + + + + + Auth Lab >:D + + +
+ + diff --git a/front/src/main.js b/front/src/main.js index e69de29..08033a1 100644 --- a/front/src/main.js +++ b/front/src/main.js @@ -0,0 +1,4 @@ +import React from 'react'; +import ReactDom from 'react-dom'; + +ReactDom.render(

Hello

, document.getElementById('root')); From 8a06b9310c8b41a68fd69bb1dcb03fd05bac6182 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 16:14:28 -0700 Subject: [PATCH 06/32] Created the action creaters without the API calls yet :D --- front/.eslintrc | 21 +++++++++++++++++++++ front/package.json | 7 +++++-- front/src/action/auth-action.js | 11 +++++++++++ front/src/component/app/index.js | 0 front/src/component/auth-form/index.js | 0 front/src/component/dashboard/index.js | 0 front/src/reducer/auth.js | 0 7 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 front/.eslintrc create mode 100644 front/src/action/auth-action.js create mode 100644 front/src/component/app/index.js create mode 100644 front/src/component/auth-form/index.js create mode 100644 front/src/component/dashboard/index.js create mode 100644 front/src/reducer/auth.js diff --git a/front/.eslintrc b/front/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/front/.eslintrc @@ -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" +} diff --git a/front/package.json b/front/package.json index 6e0bd35..dc51e76 100644 --- a/front/package.json +++ b/front/package.json @@ -1,8 +1,8 @@ { - "name": "front", + "name": "frontend", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "webpack.config.js", "scripts": { "build": "webpack", "watch": "webpack-dev-server --inline --hot" @@ -13,6 +13,7 @@ "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", @@ -25,9 +26,11 @@ "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", diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js new file mode 100644 index 0000000..c43d1e6 --- /dev/null +++ b/front/src/action/auth-action.js @@ -0,0 +1,11 @@ +import superagent from 'superagent'; + + +export const setToken = (token) => ({ + type: 'TOKEN_SET', + payload: 'token' +}); + +export const deleteToken = () => ({ + type: 'TOKEN_DELETE' +}) diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js new file mode 100644 index 0000000..e69de29 diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js new file mode 100644 index 0000000..e69de29 diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js new file mode 100644 index 0000000..e69de29 diff --git a/front/src/reducer/auth.js b/front/src/reducer/auth.js new file mode 100644 index 0000000..e69de29 From 718565cba4a529e4c5123014c525888b79988ad7 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 16:26:38 -0700 Subject: [PATCH 07/32] Added actions for API calls --- front/src/action/auth-action.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js index c43d1e6..e33fd82 100644 --- a/front/src/action/auth-action.js +++ b/front/src/action/auth-action.js @@ -3,9 +3,34 @@ import superagent from 'superagent'; export const setToken = (token) => ({ type: 'TOKEN_SET', - payload: 'token' + payload: token }); export const deleteToken = () => ({ type: 'TOKEN_DELETE' }) + +export const signupRequest => user => dispatch => { + return superagent.post(`${__API_URL__}/signup`) + .withCredentials() + .send(user) + .then(res => { + dispatch(setToken(res.text)); + try { + localStorage.token = res.text; + } catch (err) { + console.log(err); + } + return res; + }) +} + +export const loginRequest = user => dispatch => { + return superagent.get(`${__API_URL__}/login`) + .auth(uers.username, user.password) + .withCredentials() + .then(res => { + dispatch(setToken(res.text)); + return res; + }) +} From 5201b51198d1661cb1aa078537ff88aea106fa0e Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 16:43:08 -0700 Subject: [PATCH 08/32] Added reducer for auth --- front/src/reducer/index.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 front/src/reducer/index.js diff --git a/front/src/reducer/index.js b/front/src/reducer/index.js new file mode 100644 index 0000000..e69de29 From edc1d530c8c7db3ab04bf3bd7126ec07783d6479 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 17:32:59 -0700 Subject: [PATCH 09/32] Wrote thunk and reporter middleware. Created store modudle --- front/src/lib/createStore.js | 10 ++++++++++ front/src/lib/reporter.js | 15 +++++++++++++++ front/src/lib/thunk.js | 4 ++++ front/src/lib/util.js | 20 ++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 front/src/lib/createStore.js create mode 100644 front/src/lib/reporter.js create mode 100644 front/src/lib/thunk.js create mode 100644 front/src/lib/util.js diff --git a/front/src/lib/createStore.js b/front/src/lib/createStore.js new file mode 100644 index 0000000..164f4b8 --- /dev/null +++ b/front/src/lib/createStore.js @@ -0,0 +1,10 @@ +import {createStore, applyMiddleware} from 'redux'; +import reducer from '../reducer'; +import thunk from './thunk.js'; +import reporter from './reporter.js'; + +let appCreateStore = () => { + return createStore(reducer, applyMiddleware(reporter, thunk)); +} + +export default appCreateStore; diff --git a/front/src/lib/reporter.js b/front/src/lib/reporter.js new file mode 100644 index 0000000..0a347af --- /dev/null +++ b/front/src/lib/reporter.js @@ -0,0 +1,15 @@ +let reporter = store => next => action => { + console.log('__ACTION__', action); + + try { + let result = next(action); + console.log('__STATE__', store.getState()); + return result; + } catch (error) { + error.action = action; + console.error('__ERROR__', error); + return error; + } +} + +export default reporter; diff --git a/front/src/lib/thunk.js b/front/src/lib/thunk.js new file mode 100644 index 0000000..cc7c035 --- /dev/null +++ b/front/src/lib/thunk.js @@ -0,0 +1,4 @@ +export default store => next => action => + typeof action === 'function' ? + action(store.dispatch, store.getState): + next(action); diff --git a/front/src/lib/util.js b/front/src/lib/util.js new file mode 100644 index 0000000..7f6aa16 --- /dev/null +++ b/front/src/lib/util.js @@ -0,0 +1,20 @@ + +export const log = (...args) => + __DEBUG__ ? console.log(...args) : undefined; + +export const logError = (...args) => + __DEBUG__ ? console.error(...args) : undefined; + +export const renderIf = (test, firstCom, secondCom) => test ? firstCom : secondCom; + +export const classToggler = (options) => + Object.keys(options).filter(key => !!options[key]).join(' '); + +export const map = (list, ...args) => + Array.prototype.map.apply(list, args); + +export const filter = (list, ...args) => + Array.prototype.filter.apply(list, args); + +export const reduce = (list, ...args) => + Array.prototype.reduce.apply(list, args); From 52165304827e8fe4ba12e4e64e775d6a3e0f2048 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 17:34:37 -0700 Subject: [PATCH 10/32] Created combined reducer --- front/.babelrc | 2 +- front/src/reducer/auth.js | 12 ++++++++++++ front/src/reducer/index.js | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/front/.babelrc b/front/.babelrc index 4285987..47c9ace 100644 --- a/front/.babelrc +++ b/front/.babelrc @@ -1,4 +1,4 @@ { "presets": ["es2015", "react"], - "plugins": [] + "plugins": ["transform-object-rest-spread"] } diff --git a/front/src/reducer/auth.js b/front/src/reducer/auth.js index e69de29..db94ae9 100644 --- a/front/src/reducer/auth.js +++ b/front/src/reducer/auth.js @@ -0,0 +1,12 @@ + +export default (state=null, action) => { + let {type, payload} = action; + switch(type) { + case 'TOKEN_SET': + return payload + case 'TOKEN_DELETE': + return null + default: + return state + } +} diff --git a/front/src/reducer/index.js b/front/src/reducer/index.js index e69de29..536da7d 100644 --- a/front/src/reducer/index.js +++ b/front/src/reducer/index.js @@ -0,0 +1,6 @@ +import {combineReducers} from 'redux'; +import auth from './auth.js'; + +export default combineReducers({ + ayth, +}); From f1dc3ce03fceae8a8e360dec6bbb779b0365622a Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 18:31:29 -0700 Subject: [PATCH 11/32] Added dashboard component --- front/src/component/app/index.js | 30 ++++++++++++++++++++++++++ front/src/component/dashboard/index.js | 29 +++++++++++++++++++++++++ front/src/main.js | 3 ++- front/src/reducer/index.js | 2 +- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index e69de29..7c001e7 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -0,0 +1,30 @@ +import React from 'react'; +import {Provider} from 'react-redux'; +import {BrowserRouter, Route, Link} from 'react-router-dom'; +import createStore from '../../lib/createStore'; + +let store = createStore(); + +class App extends React.Component { + render() { + return( + + + +
+ + +
+
+
+
+ ) + } +} + +export default App; diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js index e69de29..4f067c5 100644 --- a/front/src/component/dashboard/index.js +++ b/front/src/component/dashboard/index.js @@ -0,0 +1,29 @@ +import React from 'react'; +import {connect} from 'react-redux'; +import {signupRequest, loginRequest} from '../../action/auth-action.js'; +import * as util from '../../lib/util.js' + +class Dashboard extends React.Component { + render() { + let {params} = this.props.match; + console.log(params); + + let onComplete = params.auth === 'login' + ? this.props.login + : this.props.signup + return ( +
+ +
+ ) + } +} + +let mapDispatchToProps = (dispatch) => { + return { + signup: (user) => dispatch(signupRequest(user)), + login: (user) => dispatch(loginRequest(user)) + } +} + +export default connect(undefined, mapDispatchToProps)(Dashboard); diff --git a/front/src/main.js b/front/src/main.js index 08033a1..faafd74 100644 --- a/front/src/main.js +++ b/front/src/main.js @@ -1,4 +1,5 @@ import React from 'react'; import ReactDom from 'react-dom'; +import App from './component/app'; -ReactDom.render(

Hello

, document.getElementById('root')); +ReactDom.render(, document.getElementById('root')); diff --git a/front/src/reducer/index.js b/front/src/reducer/index.js index 536da7d..eba40e8 100644 --- a/front/src/reducer/index.js +++ b/front/src/reducer/index.js @@ -2,5 +2,5 @@ import {combineReducers} from 'redux'; import auth from './auth.js'; export default combineReducers({ - ayth, + auth, }); From e3517c3b86bb8beffc94d93778834660ac0c290f Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 18:40:17 -0700 Subject: [PATCH 12/32] Added habdlers in Auth Form --- front/src/component/auth-form/index.js | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js index e69de29..85f20e5 100644 --- a/front/src/component/auth-form/index.js +++ b/front/src/component/auth-form/index.js @@ -0,0 +1,40 @@ +import React from 'react'; + +class AuthForm extends React.Component { + constructor(props) { + super(props); + } + + handleChange(e) { + let {name, value} = e.target; + + let errorCheck = (errorName) => { + let errorCondition = (name === errorName && !value); + return errorCondition ? `${errorName} required`: null; + } + + this.setState({ + [name]: value, + usernameError: errorCheck('username'), + emailError: errorCheck('email'), + password: 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}) + }) + } +} From a44cb06f63692ff2fc891f50e90bd94951e70cd9 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 19:37:00 -0700 Subject: [PATCH 13/32] Got button to appear :D --- front/src/action/auth-action.js | 2 +- front/src/component/app/index.js | 1 + front/src/component/auth-form/index.js | 57 ++++++++++++++++++-------- front/src/component/dashboard/index.js | 6 ++- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js index e33fd82..940f7d5 100644 --- a/front/src/action/auth-action.js +++ b/front/src/action/auth-action.js @@ -10,7 +10,7 @@ export const deleteToken = () => ({ type: 'TOKEN_DELETE' }) -export const signupRequest => user => dispatch => { +export const signupRequest = user => dispatch => { return superagent.post(`${__API_URL__}/signup`) .withCredentials() .send(user) diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index 7c001e7..74c5cfd 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -2,6 +2,7 @@ import React from 'react'; import {Provider} from 'react-redux'; import {BrowserRouter, Route, Link} from 'react-router-dom'; import createStore from '../../lib/createStore'; +import Dashboard from '../dashboard'; let store = createStore(); diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js index 85f20e5..dcb76ef 100644 --- a/front/src/component/auth-form/index.js +++ b/front/src/component/auth-form/index.js @@ -1,16 +1,30 @@ import React from 'react'; +import * as util from '../../lib/util.js'; class AuthForm extends React.Component { constructor(props) { super(props); + + this.state = { + username: '', + email: '', + password: '', + usernameError: null, + passwordError: null, + emailError: null, + error: null + }; + + this.onChange = this.onChange.bind(this); + this.onSubmit = this.onChange.bind(this); } - handleChange(e) { + onChange(e) { let {name, value} = e.target; let errorCheck = (errorName) => { let errorCondition = (name === errorName && !value); - return errorCondition ? `${errorName} required`: null; + return errorCondition ? `${errorName} required`:null; } this.setState({ @@ -22,19 +36,28 @@ class AuthForm extends React.Component { } onSubmit(e) { - e.preventDefault(); - this.props.onComplete(this.state) - .then(() => { - this.setState({ - username: '', - email: '', - password: '' - }) - - }) - .catch(error => { - console.error(error); - this.setState({error}) - }) - } + e.preventDefault(); + this.props.onComplete(this.state) + .then(() => { + this.setState({ + username: '', + email: '', + password: '' + }) + }) + .catch(error => { + console.error(error); + this.setState({error}) + }) + } + + render() { + return( +
+ +
+ ) + } } + +export default AuthForm; diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js index 4f067c5..d8a0852 100644 --- a/front/src/component/dashboard/index.js +++ b/front/src/component/dashboard/index.js @@ -2,6 +2,7 @@ import React from 'react'; import {connect} from 'react-redux'; import {signupRequest, loginRequest} from '../../action/auth-action.js'; import * as util from '../../lib/util.js' +import AuthForm from '../auth-form'; class Dashboard extends React.Component { render() { @@ -13,7 +14,10 @@ class Dashboard extends React.Component { : this.props.signup return (
- +
) } From 3ffa45962c0f308a1fa6c19c89966fc5c457ade7 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 19:47:14 -0700 Subject: [PATCH 14/32] Added an email form --- front/src/component/auth-form/index.js | 12 ++++++++++++ front/src/component/dashboard/index.js | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js index dcb76ef..8e5fda6 100644 --- a/front/src/component/auth-form/index.js +++ b/front/src/component/auth-form/index.js @@ -52,8 +52,20 @@ class AuthForm extends React.Component { } render() { + console.log(util); return(
+ + {util.renderIf(this.props.auth === 'signup', + + )}
) diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js index d8a0852..4c0391e 100644 --- a/front/src/component/dashboard/index.js +++ b/front/src/component/dashboard/index.js @@ -16,7 +16,8 @@ class Dashboard extends React.Component {
) From f6e4ee6cbf1119c8689d40474fc35261266cb984 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 20:57:16 -0700 Subject: [PATCH 15/32] Rejoicegit add .! It works??? --- front/src/action/auth-action.js | 2 +- front/src/component/auth-form/index.js | 30 ++++++++++++++++++++++---- front/webpack.config.js | 1 + 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js index 940f7d5..fee020c 100644 --- a/front/src/action/auth-action.js +++ b/front/src/action/auth-action.js @@ -27,7 +27,7 @@ export const signupRequest = user => dispatch => { export const loginRequest = user => dispatch => { return superagent.get(`${__API_URL__}/login`) - .auth(uers.username, user.password) + .auth(user.username, user.password) .withCredentials() .then(res => { dispatch(setToken(res.text)); diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js index 8e5fda6..2073db5 100644 --- a/front/src/component/auth-form/index.js +++ b/front/src/component/auth-form/index.js @@ -16,7 +16,7 @@ class AuthForm extends React.Component { }; this.onChange = this.onChange.bind(this); - this.onSubmit = this.onChange.bind(this); + this.onSubmit = this.onSubmit.bind(this); } onChange(e) { @@ -31,7 +31,7 @@ class AuthForm extends React.Component { [name]: value, usernameError: errorCheck('username'), emailError: errorCheck('email'), - password: errorCheck('password') + passwordError: errorCheck('password') }); } @@ -52,7 +52,6 @@ class AuthForm extends React.Component { } render() { - console.log(util); return(
@@ -62,10 +61,33 @@ class AuthForm extends React.Component { name='email' value={this.state.email} placeholder='Please enter an email address' - required={true} onChange={this.onChange} /> )} + {util.renderIf(this.state.username, + + {this.state.usernameError} + + )} + + {util.renderIf(this.state.password, + + {this.state.passwordError} + + )} +
) diff --git a/front/webpack.config.js b/front/webpack.config.js index 9dc9986..4592355 100644 --- a/front/webpack.config.js +++ b/front/webpack.config.js @@ -6,6 +6,7 @@ const UglifyPlugin = require('uglifyjs-webpack-plugin'); const CleanPlugin = require('clean-webpack-plugin'); const {DefinePlugin, EnvironmentPlugin} = require('webpack'); +require('dotenv').config(); let production = process.env.NODE_ENV === 'production'; let plugins = [ From eac2b7107ba3169647ebda1a2c7f63d4c26624d9 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 6 Sep 2017 21:00:05 -0700 Subject: [PATCH 16/32] Added style scaffolding :D --- front/src/action/auth-action.js | 5 +++++ front/src/style/base/_base.scss | 0 front/src/style/base/_reset.scss | 0 front/src/style/layout/_footer.scss | 0 front/src/style/layout/_header.scss | 0 front/src/style/layout/_main.scss | 0 front/src/style/lib/_vars.scss | 0 7 files changed, 5 insertions(+) create mode 100644 front/src/style/base/_base.scss create mode 100644 front/src/style/base/_reset.scss create mode 100644 front/src/style/layout/_footer.scss create mode 100644 front/src/style/layout/_header.scss create mode 100644 front/src/style/layout/_main.scss create mode 100644 front/src/style/lib/_vars.scss diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js index fee020c..363ec86 100644 --- a/front/src/action/auth-action.js +++ b/front/src/action/auth-action.js @@ -31,6 +31,11 @@ export const loginRequest = user => dispatch => { .withCredentials() .then(res => { dispatch(setToken(res.text)); + try { + localStorage.token = res.text; + } catch (err) { + console.log(err); + } return res; }) } diff --git a/front/src/style/base/_base.scss b/front/src/style/base/_base.scss new file mode 100644 index 0000000..e69de29 diff --git a/front/src/style/base/_reset.scss b/front/src/style/base/_reset.scss new file mode 100644 index 0000000..e69de29 diff --git a/front/src/style/layout/_footer.scss b/front/src/style/layout/_footer.scss new file mode 100644 index 0000000..e69de29 diff --git a/front/src/style/layout/_header.scss b/front/src/style/layout/_header.scss new file mode 100644 index 0000000..e69de29 diff --git a/front/src/style/layout/_main.scss b/front/src/style/layout/_main.scss new file mode 100644 index 0000000..e69de29 diff --git a/front/src/style/lib/_vars.scss b/front/src/style/lib/_vars.scss new file mode 100644 index 0000000..e69de29 From e19fc6caa51548c96ce5ffab0171fc404a10d39e Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 7 Sep 2017 16:38:30 -0700 Subject: [PATCH 17/32] Deleted old lab and started from scratch. Added an ass ton of scaffolding --- front/src/action/auth-action.js | 41 -------- front/src/component/app/index.js | 26 ++--- front/src/component/auth-form/index.js | 97 ------------------- front/src/component/dashboard/index.js | 34 ------- .../_base.scss => component/landing/index.js} | 0 front/src/index.html | 2 +- front/src/lib/createStore.js | 10 -- front/src/lib/reporter.js | 15 --- front/src/lib/thunk.js | 4 - front/src/lib/util.js | 20 ---- front/src/reducer/auth.js | 12 --- front/src/reducer/index.js | 6 -- front/src/style/base/_reset.scss | 0 front/src/style/layout/_footer.scss | 0 front/src/style/layout/_header.scss | 0 front/src/style/layout/_main.scss | 0 front/src/style/lib/_vars.scss | 0 17 files changed, 8 insertions(+), 259 deletions(-) delete mode 100644 front/src/action/auth-action.js delete mode 100644 front/src/component/auth-form/index.js rename front/src/{style/base/_base.scss => component/landing/index.js} (100%) delete mode 100644 front/src/style/base/_reset.scss delete mode 100644 front/src/style/layout/_footer.scss delete mode 100644 front/src/style/layout/_header.scss delete mode 100644 front/src/style/layout/_main.scss delete mode 100644 front/src/style/lib/_vars.scss diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js deleted file mode 100644 index 363ec86..0000000 --- a/front/src/action/auth-action.js +++ /dev/null @@ -1,41 +0,0 @@ -import superagent from 'superagent'; - - -export const setToken = (token) => ({ - type: 'TOKEN_SET', - payload: token -}); - -export const deleteToken = () => ({ - type: 'TOKEN_DELETE' -}) - -export const signupRequest = user => dispatch => { - return superagent.post(`${__API_URL__}/signup`) - .withCredentials() - .send(user) - .then(res => { - dispatch(setToken(res.text)); - try { - localStorage.token = res.text; - } catch (err) { - console.log(err); - } - return res; - }) -} - -export const loginRequest = user => dispatch => { - return superagent.get(`${__API_URL__}/login`) - .auth(user.username, user.password) - .withCredentials() - .then(res => { - dispatch(setToken(res.text)); - try { - localStorage.token = res.text; - } catch (err) { - console.log(err); - } - return res; - }) -} diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index 74c5cfd..5ae6705 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -1,27 +1,15 @@ -import React from 'react'; +import React from 'React'; import {Provider} from 'react-redux'; -import {BrowserRouter, Route, Link} from 'react-router-dom'; -import createStore from '../../lib/createStore'; -import Dashboard from '../dashboard'; - -let store = createStore(); +import {BroswerRouter, Route, Link} from 'react-router-dom'; class App extends React.Component { render() { return( - - - -
- - -
-
+ + + + + ) diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js deleted file mode 100644 index 2073db5..0000000 --- a/front/src/component/auth-form/index.js +++ /dev/null @@ -1,97 +0,0 @@ -import React from 'react'; -import * as util from '../../lib/util.js'; - -class AuthForm extends React.Component { - constructor(props) { - super(props); - - this.state = { - username: '', - email: '', - password: '', - 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; - - let errorCheck = (errorName) => { - let errorCondition = (name === errorName && !value); - return errorCondition ? `${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() { - return( -
- - {util.renderIf(this.props.auth === 'signup', - - )} - {util.renderIf(this.state.username, - - {this.state.usernameError} - - )} - - {util.renderIf(this.state.password, - - {this.state.passwordError} - - )} - - -
- ) - } -} - -export default AuthForm; diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js index 4c0391e..e69de29 100644 --- a/front/src/component/dashboard/index.js +++ b/front/src/component/dashboard/index.js @@ -1,34 +0,0 @@ -import React from 'react'; -import {connect} from 'react-redux'; -import {signupRequest, loginRequest} from '../../action/auth-action.js'; -import * as util from '../../lib/util.js' -import AuthForm from '../auth-form'; - -class Dashboard extends React.Component { - render() { - let {params} = this.props.match; - console.log(params); - - let onComplete = params.auth === 'login' - ? this.props.login - : this.props.signup - return ( -
- -
- ) - } -} - -let mapDispatchToProps = (dispatch) => { - return { - signup: (user) => dispatch(signupRequest(user)), - login: (user) => dispatch(loginRequest(user)) - } -} - -export default connect(undefined, mapDispatchToProps)(Dashboard); diff --git a/front/src/style/base/_base.scss b/front/src/component/landing/index.js similarity index 100% rename from front/src/style/base/_base.scss rename to front/src/component/landing/index.js diff --git a/front/src/index.html b/front/src/index.html index 6c60996..fb1a284 100644 --- a/front/src/index.html +++ b/front/src/index.html @@ -2,7 +2,7 @@ - Auth Lab >:D + Every day that passes brings us one step closer to the void
diff --git a/front/src/lib/createStore.js b/front/src/lib/createStore.js index 164f4b8..e69de29 100644 --- a/front/src/lib/createStore.js +++ b/front/src/lib/createStore.js @@ -1,10 +0,0 @@ -import {createStore, applyMiddleware} from 'redux'; -import reducer from '../reducer'; -import thunk from './thunk.js'; -import reporter from './reporter.js'; - -let appCreateStore = () => { - return createStore(reducer, applyMiddleware(reporter, thunk)); -} - -export default appCreateStore; diff --git a/front/src/lib/reporter.js b/front/src/lib/reporter.js index 0a347af..e69de29 100644 --- a/front/src/lib/reporter.js +++ b/front/src/lib/reporter.js @@ -1,15 +0,0 @@ -let reporter = store => next => action => { - console.log('__ACTION__', action); - - try { - let result = next(action); - console.log('__STATE__', store.getState()); - return result; - } catch (error) { - error.action = action; - console.error('__ERROR__', error); - return error; - } -} - -export default reporter; diff --git a/front/src/lib/thunk.js b/front/src/lib/thunk.js index cc7c035..e69de29 100644 --- a/front/src/lib/thunk.js +++ b/front/src/lib/thunk.js @@ -1,4 +0,0 @@ -export default store => next => action => - typeof action === 'function' ? - action(store.dispatch, store.getState): - next(action); diff --git a/front/src/lib/util.js b/front/src/lib/util.js index 7f6aa16..e69de29 100644 --- a/front/src/lib/util.js +++ b/front/src/lib/util.js @@ -1,20 +0,0 @@ - -export const log = (...args) => - __DEBUG__ ? console.log(...args) : undefined; - -export const logError = (...args) => - __DEBUG__ ? console.error(...args) : undefined; - -export const renderIf = (test, firstCom, secondCom) => test ? firstCom : secondCom; - -export const classToggler = (options) => - Object.keys(options).filter(key => !!options[key]).join(' '); - -export const map = (list, ...args) => - Array.prototype.map.apply(list, args); - -export const filter = (list, ...args) => - Array.prototype.filter.apply(list, args); - -export const reduce = (list, ...args) => - Array.prototype.reduce.apply(list, args); diff --git a/front/src/reducer/auth.js b/front/src/reducer/auth.js index db94ae9..e69de29 100644 --- a/front/src/reducer/auth.js +++ b/front/src/reducer/auth.js @@ -1,12 +0,0 @@ - -export default (state=null, action) => { - let {type, payload} = action; - switch(type) { - case 'TOKEN_SET': - return payload - case 'TOKEN_DELETE': - return null - default: - return state - } -} diff --git a/front/src/reducer/index.js b/front/src/reducer/index.js index eba40e8..e69de29 100644 --- a/front/src/reducer/index.js +++ b/front/src/reducer/index.js @@ -1,6 +0,0 @@ -import {combineReducers} from 'redux'; -import auth from './auth.js'; - -export default combineReducers({ - auth, -}); diff --git a/front/src/style/base/_reset.scss b/front/src/style/base/_reset.scss deleted file mode 100644 index e69de29..0000000 diff --git a/front/src/style/layout/_footer.scss b/front/src/style/layout/_footer.scss deleted file mode 100644 index e69de29..0000000 diff --git a/front/src/style/layout/_header.scss b/front/src/style/layout/_header.scss deleted file mode 100644 index e69de29..0000000 diff --git a/front/src/style/layout/_main.scss b/front/src/style/layout/_main.scss deleted file mode 100644 index e69de29..0000000 diff --git a/front/src/style/lib/_vars.scss b/front/src/style/lib/_vars.scss deleted file mode 100644 index e69de29..0000000 From e24f30e71326c306be0e73bbd243330522db331c Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 7 Sep 2017 17:32:10 -0700 Subject: [PATCH 18/32] Added auth action and reducer, Created combined reducer, created store... --- front/src/action/auth-action.js | 40 ++++++++++++++++++++++++++++++ front/src/action/profile-action.js | 0 front/src/component/app/index.js | 5 +++- front/src/lib/createStore.js | 10 ++++++++ front/src/reducer/auth.js | 12 +++++++++ front/src/reducer/index.js | 6 +++++ 6 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 front/src/action/auth-action.js create mode 100644 front/src/action/profile-action.js diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js new file mode 100644 index 0000000..e725f64 --- /dev/null +++ b/front/src/action/auth-action.js @@ -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 => dispath => { + 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; + }) +} diff --git a/front/src/action/profile-action.js b/front/src/action/profile-action.js new file mode 100644 index 0000000..e69de29 diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index 5ae6705..71cbbfd 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -1,12 +1,15 @@ import React from 'React'; import {Provider} from 'react-redux'; import {BroswerRouter, Route, Link} from 'react-router-dom'; +import createStore from '../../lib/createStore.js'; + +let store = createStore() class App extends React.Component { render() { return( - + diff --git a/front/src/lib/createStore.js b/front/src/lib/createStore.js index e69de29..0a39d71 100644 --- a/front/src/lib/createStore.js +++ b/front/src/lib/createStore.js @@ -0,0 +1,10 @@ +import {createStore, applyMiddleware} from 'redux'; +import reducer from '../reducer'; +import thunk from './thunk.js'; +import reporter from './reporter.js'; + +const createAppStore = function() { + return createStore(reducer, applyMiddleware(thunk, reporter)); +}; + +module.exports = createAppStore; diff --git a/front/src/reducer/auth.js b/front/src/reducer/auth.js index e69de29..6d1198f 100644 --- a/front/src/reducer/auth.js +++ b/front/src/reducer/auth.js @@ -0,0 +1,12 @@ +export default (state=null, action) => { + let {type, payload} = action; + + switch(payload) { + case 'TOKEN_SET': + return payload; + case 'TOKEN_DELETE': + return null; + default: + return state; + } +} diff --git a/front/src/reducer/index.js b/front/src/reducer/index.js index e69de29..c61fb7e 100644 --- a/front/src/reducer/index.js +++ b/front/src/reducer/index.js @@ -0,0 +1,6 @@ +import {combineReducers} from 'redux'; +import auth from './auth.js'; + +module.exports = combineReducers({ + auth, +}); From 9b70804cbfc3b4f4e8209c9550b0f68349195eae Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 7 Sep 2017 17:34:22 -0700 Subject: [PATCH 19/32] The gingerbread man is in a gingerbread house. Is he made form the house or is the house made from his flesh? He screams, for he does not know... --- front/src/lib/reporter.js | 15 +++++++++++++++ front/src/lib/thunk.js | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/front/src/lib/reporter.js b/front/src/lib/reporter.js index e69de29..0a347af 100644 --- a/front/src/lib/reporter.js +++ b/front/src/lib/reporter.js @@ -0,0 +1,15 @@ +let reporter = store => next => action => { + console.log('__ACTION__', action); + + try { + let result = next(action); + console.log('__STATE__', store.getState()); + return result; + } catch (error) { + error.action = action; + console.error('__ERROR__', error); + return error; + } +} + +export default reporter; diff --git a/front/src/lib/thunk.js b/front/src/lib/thunk.js index e69de29..c9d6452 100644 --- a/front/src/lib/thunk.js +++ b/front/src/lib/thunk.js @@ -0,0 +1,4 @@ +export default store => next => action => + typeof action === 'function' + ? action(store.dispatch, store.getState) + : next(action); From f7ca90e572d3159daa03109a173f9d021ddcd912 Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 7 Sep 2017 17:47:17 -0700 Subject: [PATCH 20/32] Finished setting up the scaffolding :D --- front/src/component/app/index.js | 16 +++++++++------- front/src/component/dashboard/index.js | 11 +++++++++++ .../lib/{createStore.js => createAppStore.js} | 0 3 files changed, 20 insertions(+), 7 deletions(-) rename front/src/lib/{createStore.js => createAppStore.js} (100%) diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index 71cbbfd..85735ca 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -1,18 +1,20 @@ -import React from 'React'; +import React from 'react'; import {Provider} from 'react-redux'; -import {BroswerRouter, Route, Link} from 'react-router-dom'; -import createStore from '../../lib/createStore.js'; +import {BrowserRouter, Route, Link} from 'react-router-dom'; -let store = createStore() +import Dashboard from '../dashboard'; +import createAppStore from '../../lib/createAppStore.js'; + +let store = createAppStore() class App extends React.Component { render() { return( - - - + + + ) diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js index e69de29..3246d4b 100644 --- a/front/src/component/dashboard/index.js +++ b/front/src/component/dashboard/index.js @@ -0,0 +1,11 @@ +import React from 'react'; + +class Dashboard extends React.Component { + render() { + return( +

Hello

+ ) + } +}; + +export default Dashboard; diff --git a/front/src/lib/createStore.js b/front/src/lib/createAppStore.js similarity index 100% rename from front/src/lib/createStore.js rename to front/src/lib/createAppStore.js From 3bbb4ecf1ccdaf850a9799256ef3a2636ffa195b Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 7 Sep 2017 19:22:10 -0700 Subject: [PATCH 21/32] Finished auth portion --- front/npm-debug.log | 26 ++++++++++ front/src/action/auth-action.js | 2 +- front/src/component/app/index.js | 10 +++- front/src/component/auth-form/index.js | 71 ++++++++++++++++++++++++++ front/src/component/dashboard/index.js | 26 +++++++++- front/src/lib/util.js | 3 ++ 6 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 front/npm-debug.log create mode 100644 front/src/component/auth-form/index.js diff --git a/front/npm-debug.log b/front/npm-debug.log new file mode 100644 index 0000000..5f4547c --- /dev/null +++ b/front/npm-debug.log @@ -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. (/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 +12 verbose exit [ 1, true ] diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js index e725f64..591edb2 100644 --- a/front/src/action/auth-action.js +++ b/front/src/action/auth-action.js @@ -9,7 +9,7 @@ export const tokenDelete = () => ({ type: 'TOKEN_DELETE', }); -export const signupRequest = user => dispath => { +export const signupRequest = user => dispatch => { return superagent.post(`${__API_URL__}/signup`) .withCredentials() .send(user) diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index 85735ca..c07770c 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -13,7 +13,15 @@ class App extends React.Component { - +
+ + +
diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js new file mode 100644 index 0000000..c9d64a4 --- /dev/null +++ b/front/src/component/auth-form/index.js @@ -0,0 +1,71 @@ +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) { + this.setState({ + [e.target.name]: e.target.value + }) + } + + onSubmit(e) { + e.preventDefault(); + console.log(this.state); + this.props.onComplete(this.state); + } + + + + + render() { + + let emailInput = ( + + ) + + return( +
+ + + {util.renderIf(this.props.auth === 'signup', emailInput)} + +
+ ) + } +} + +export default AuthForm; diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js index 3246d4b..d0006d7 100644 --- a/front/src/component/dashboard/index.js +++ b/front/src/component/dashboard/index.js @@ -1,11 +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( -

Hello

+ ) } }; -export default Dashboard; +let mapDispatchToProps = dispatch => { + return { + signup: user => dispatch(authReqs.signupRequest(user)), + login: user => dispatch(authReqs.loginRequest(user)) + } +} + +export default connect(undefined, mapDispatchToProps)(Dashboard); diff --git a/front/src/lib/util.js b/front/src/lib/util.js index e69de29..a8c6d8d 100644 --- a/front/src/lib/util.js +++ b/front/src/lib/util.js @@ -0,0 +1,3 @@ +export const renderIf = (condition, firstCom, secondCom) => { + return condition ? firstCom : secondCom; +} From 9994e62dfebe4b3193ccaff4605a2a0fb677fcc6 Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 7 Sep 2017 19:33:53 -0700 Subject: [PATCH 22/32] There's a special place in hell for those who don't indent correctly --- front/src/component/auth-form/index.js | 32 +++++++++++++++++++++++--- front/src/lib/createAppStore.js | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js index c9d64a4..30c5ea7 100644 --- a/front/src/component/auth-form/index.js +++ b/front/src/component/auth-form/index.js @@ -19,15 +19,31 @@ class AuthForm extends React.Component { } onChange(e) { + let {name, value} = e.target; + + function errorCheck(errorName) { + return name === errorName && !value ? `${errorName} required`: null; + } + this.setState({ - [e.target.name]: e.target.value + [name]: value, + usernameError: errorCheck('username'), + emailError: errorCheck('email'), + passwordError: errorCheck('password') }) } onSubmit(e) { e.preventDefault(); - console.log(this.state); - this.props.onComplete(this.state); + + this.props.onComplete(this.state) + .then(() => { + this.setState({ username: '', email: '', password: ''}) + }) + .catch(error => { + console.error(error); + this.setState({error}); + }) } @@ -54,6 +70,11 @@ class AuthForm extends React.Component { value={this.state.username} onChange={this.onChange} /> + {util.renderIf(this.state.usernameError, + + {this.state.usernameError} + + )} + {util.renderIf(this.state.passwordError, + + {this.state.passwordError} + + )} {util.renderIf(this.props.auth === 'signup', emailInput)} diff --git a/front/src/lib/createAppStore.js b/front/src/lib/createAppStore.js index 0a39d71..97aa1b2 100644 --- a/front/src/lib/createAppStore.js +++ b/front/src/lib/createAppStore.js @@ -3,7 +3,7 @@ import reducer from '../reducer'; import thunk from './thunk.js'; import reporter from './reporter.js'; -const createAppStore = function() { +let createAppStore = () => { return createStore(reducer, applyMiddleware(thunk, reporter)); }; From 173629562ee4e0d43d65cb46b72e766b1c1a9c45 Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 7 Sep 2017 22:08:11 -0700 Subject: [PATCH 23/32] Added profile action --- front/src/action/profile-action.js | 23 +++++++++++++++++++++++ front/src/reducer/profile.js | 0 2 files changed, 23 insertions(+) create mode 100644 front/src/reducer/profile.js diff --git a/front/src/action/profile-action.js b/front/src/action/profile-action.js index e69de29..cd2d31d 100644 --- a/front/src/action/profile-action.js +++ b/front/src/action/profile-action.js @@ -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; + }); +}; diff --git a/front/src/reducer/profile.js b/front/src/reducer/profile.js new file mode 100644 index 0000000..e69de29 From 248619fe58c53f4bd6e2bbdc4c88ae5e69f65fbf Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 7 Sep 2017 22:29:49 -0700 Subject: [PATCH 24/32] Made custom dynamic validation module --- front/src/lib/valiation.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 front/src/lib/valiation.js diff --git a/front/src/lib/valiation.js b/front/src/lib/valiation.js new file mode 100644 index 0000000..81c0d6d --- /dev/null +++ b/front/src/lib/valiation.js @@ -0,0 +1,10 @@ +module.exports = (profile, preReqs) => { + let incomplete = false; + for (let i = 0; i < preReqs.length; i++) { + if(!profile[preReqs[i]]) { + console.error(`VALIDATION ERROR: Missing ${preReqs[i]} property.`); + incomplete = true; + } + } + if(incomplete) throw new Error('VALIDATION ERROR: process terminated.'); +}; From c4a4c34d84784690160981084577d5c65009d764 Mon Sep 17 00:00:00 2001 From: Eddie Date: Sun, 10 Sep 2017 20:17:14 -0700 Subject: [PATCH 25/32] Winner winner chicken dinner --- front/src/lib/valiation.js | 2 ++ front/src/reducer/profile.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/front/src/lib/valiation.js b/front/src/lib/valiation.js index 81c0d6d..14f5cad 100644 --- a/front/src/lib/valiation.js +++ b/front/src/lib/valiation.js @@ -1,10 +1,12 @@ module.exports = (profile, preReqs) => { let incomplete = false; + for (let i = 0; i < preReqs.length; i++) { if(!profile[preReqs[i]]) { console.error(`VALIDATION ERROR: Missing ${preReqs[i]} property.`); incomplete = true; } } + if(incomplete) throw new Error('VALIDATION ERROR: process terminated.'); }; diff --git a/front/src/reducer/profile.js b/front/src/reducer/profile.js index e69de29..93100a5 100644 --- a/front/src/reducer/profile.js +++ b/front/src/reducer/profile.js @@ -0,0 +1,7 @@ +import validate from '../lib/validate.js'; + +let profileReqs = ['avatar', 'email', 'bio', '_id', 'owner', 'username']; + +module.exports = (state, action => { + let {type, payload} = action; +}) From e9003d7e0dfaac9c4f69c14fa9c66d07965170dc Mon Sep 17 00:00:00 2001 From: Eddie Date: Sun, 10 Sep 2017 21:11:44 -0700 Subject: [PATCH 26/32] Added profile route and some middleware --- front/npm-debug.log | 26 ------------- front/src/component/dashboard/index.js | 6 ++- front/src/lib/util.js | 39 ++++++++++++++++++- front/src/lib/{valiation.js => validation.js} | 0 front/src/reducer/auth.js | 4 +- front/src/reducer/index.js | 2 + front/src/reducer/profile.js | 15 ++++++- 7 files changed, 60 insertions(+), 32 deletions(-) delete mode 100644 front/npm-debug.log rename front/src/lib/{valiation.js => validation.js} (100%) diff --git a/front/npm-debug.log b/front/npm-debug.log deleted file mode 100644 index 5f4547c..0000000 --- a/front/npm-debug.log +++ /dev/null @@ -1,26 +0,0 @@ -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. (/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 -12 verbose exit [ 1, true ] diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js index d0006d7..16aae23 100644 --- a/front/src/component/dashboard/index.js +++ b/front/src/component/dashboard/index.js @@ -13,6 +13,8 @@ class Dashboard extends React.Component { this.props.login: this.props.signup; + console.log(this.props.auth); + return( ({ + auth: store.auth +}) let mapDispatchToProps = dispatch => { return { signup: user => dispatch(authReqs.signupRequest(user)), diff --git a/front/src/lib/util.js b/front/src/lib/util.js index a8c6d8d..f012a7a 100644 --- a/front/src/lib/util.js +++ b/front/src/lib/util.js @@ -1,3 +1,38 @@ -export const renderIf = (condition, firstCom, secondCom) => { - return condition ? firstCom : secondCom; +export const photoToDataURL = (file) => { + return new Promise((resolve, reject) => { + let reader = new FileReader(); + reader.addEventListener('load', () => { + resolve(reader.result); + }) + reader.addEventListener('error', () => { + reject(reader.error); + }); + if (file) { + return reader.readAsDataURL(file) + } + return reject(new Error('ERROR: No file provided')); + }) } + +// got from: +// https://stackoverflow.com/questions/14573223/set-cookie-and-get-cookie-with-javascript +export const readCookie = (name) => { + var nameEQ = name + '='; + var ca = document.cookie.split(';'); + for(var i=0; i < ca.length; i++) { + var c = ca[i]; + while(c.charAt(0) == ' ') c = c.substring(1, c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); + } + return null; +} +export const log = (...args) => + __DEBUG__ ? console.log(...args) : undefined; + +export const logError = (...args) => + __DEBUG__ ? console.error(...args) : undefined; + +export const renderIf = (test, component) => test ? component : undefined; + +export const classToggler = (options) => + Object.keys(options).filter(key => !!options[key]).join(' '); diff --git a/front/src/lib/valiation.js b/front/src/lib/validation.js similarity index 100% rename from front/src/lib/valiation.js rename to front/src/lib/validation.js diff --git a/front/src/reducer/auth.js b/front/src/reducer/auth.js index 6d1198f..a41fbf8 100644 --- a/front/src/reducer/auth.js +++ b/front/src/reducer/auth.js @@ -1,7 +1,7 @@ -export default (state=null, action) => { +module.exports = (state=null, action) => { let {type, payload} = action; - switch(payload) { + switch(type) { case 'TOKEN_SET': return payload; case 'TOKEN_DELETE': diff --git a/front/src/reducer/index.js b/front/src/reducer/index.js index c61fb7e..e781a72 100644 --- a/front/src/reducer/index.js +++ b/front/src/reducer/index.js @@ -1,6 +1,8 @@ import {combineReducers} from 'redux'; import auth from './auth.js'; +import profile from './profile.js' module.exports = combineReducers({ auth, + profile }); diff --git a/front/src/reducer/profile.js b/front/src/reducer/profile.js index 93100a5..eeb7a5e 100644 --- a/front/src/reducer/profile.js +++ b/front/src/reducer/profile.js @@ -1,7 +1,20 @@ -import validate from '../lib/validate.js'; +import validate from '../lib/validation.js'; let profileReqs = ['avatar', 'email', 'bio', '_id', 'owner', 'username']; module.exports = (state, action => { let {type, payload} = action; + + switch(type) { + case 'PROFILE_CREATE': + validate(payload, profileReqs); + return payload; + case 'PROFILE_UPDATE': + validate(payload, profileReqs); + return {...state, ...payload}; + case 'LOGOUT': + return null; + default: + return state; + } }) From f8a63fd25d1e2bc247771f7db9251f03fab75e0a Mon Sep 17 00:00:00 2001 From: Eddie Date: Sun, 10 Sep 2017 22:38:11 -0700 Subject: [PATCH 27/32] Added profile form component --- front/src/component/profile-form/index.js | 64 +++++++++++++++++++ .../src/component/settings-container/index.js | 0 2 files changed, 64 insertions(+) create mode 100644 front/src/component/profile-form/index.js create mode 100644 front/src/component/settings-container/index.js diff --git a/front/src/component/profile-form/index.js b/front/src/component/profile-form/index.js new file mode 100644 index 0000000..b139fd3 --- /dev/null +++ b/front/src/component/profile-form/index.js @@ -0,0 +1,64 @@ +import React from 'react'; +import * as util from '../../lib/util.js'; + +class ProfileForm extends React.Component { + constructor(props) { + super(props); + this.state = props.profile ? + {...props.profile, bio: ''} : + {bio: '', avatar: null, preview: ''} + + this.onChange = this.onChange.bind(this); + this.onSubmit = this.onSubmit.bind(this); + } + + componentWillReceiveProps(props) { + if(props.profile) { + this.setState(props.porfile); + } + } + + onChange(e) => { + let {type, name} = e.target; + if(name === 'bio') this.setState({bio: e.target.value}); + + if(name === 'avatar') { + let {files} = e.target; + let avatar = files[0]; + this.setState({avatar}); + util.photoToDataURL(avatar) + .then(preview => this.setState({preview})) + .catch(err => console.error(err)); + } + } + + onSubmit(e) { + e.preventDefault(); + this.props.onComplete(this.state); + } + + render() { + return( +
+ + + + +
+ ) + } +} + +export default ProfileForm; diff --git a/front/src/component/settings-container/index.js b/front/src/component/settings-container/index.js new file mode 100644 index 0000000..e69de29 From ff0803d9612e8232432c030c0656d57d8c3c52a3 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 11 Sep 2017 09:21:10 -0700 Subject: [PATCH 28/32] Plugged in settings componenet --- front/src/component/app/index.js | 7 ++- front/src/component/dashboard/index.js | 37 --------------- front/src/component/landing/index.js | 33 +++++++++++++ front/src/component/profile-form/index.js | 6 +-- .../src/component/settings-container/index.js | 47 +++++++++++++++++++ front/src/reducer/auth.js | 2 +- front/src/reducer/profile.js | 4 +- 7 files changed, 91 insertions(+), 45 deletions(-) delete mode 100644 front/src/component/dashboard/index.js diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index c07770c..c3ca2be 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -2,7 +2,8 @@ import React from 'react'; import {Provider} from 'react-redux'; import {BrowserRouter, Route, Link} from 'react-router-dom'; -import Dashboard from '../dashboard'; +import Landing from '../landing'; +import SettingsContainer from '../settings-container'; import createAppStore from '../../lib/createAppStore.js'; let store = createAppStore() @@ -18,9 +19,11 @@ class App extends React.Component {
  • signup
  • login
  • +
  • settings
- + +
diff --git a/front/src/component/dashboard/index.js b/front/src/component/dashboard/index.js deleted file mode 100644 index 16aae23..0000000 --- a/front/src/component/dashboard/index.js +++ /dev/null @@ -1,37 +0,0 @@ -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; - - console.log(this.props.auth); - - return( - - ) - } -}; -let mapStoreToState = store => ({ - auth: store.auth -}) -let mapDispatchToProps = dispatch => { - return { - signup: user => dispatch(authReqs.signupRequest(user)), - login: user => dispatch(authReqs.loginRequest(user)) - } -} - -export default connect(undefined, mapDispatchToProps)(Dashboard); diff --git a/front/src/component/landing/index.js b/front/src/component/landing/index.js index e69de29..61ce5d4 100644 --- a/front/src/component/landing/index.js +++ b/front/src/component/landing/index.js @@ -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 Landing extends React.Component { + render() { + + let {params} = this.props.match; + + let onComplete = params.auth === 'login'? + this.props.login: + this.props.signup; + + return( + + ) + } +}; + +let mapDispatchToProps = dispatch => { + return { + signup: user => dispatch(authReqs.signupRequest(user)), + login: user => dispatch(authReqs.loginRequest(user)) + } +} + +export default connect(undefined, mapDispatchToProps)(Landing); diff --git a/front/src/component/profile-form/index.js b/front/src/component/profile-form/index.js index b139fd3..c8f850a 100644 --- a/front/src/component/profile-form/index.js +++ b/front/src/component/profile-form/index.js @@ -18,7 +18,7 @@ class ProfileForm extends React.Component { } } - onChange(e) => { + onChange(e) { let {type, name} = e.target; if(name === 'bio') this.setState({bio: e.target.value}); @@ -42,8 +42,8 @@ class ProfileForm extends React.Component {
- + > + console.log('__RESPONSE__: ', res)) + .catch(err => console.error(err)); + } + + handleProfileUpdate(profile) { + + } + + render() { + let onComplete = this.props.profile ? + this.handleProfileCreate : + this.handleProfileUpdate; + + return ( +
+ +
+ ) + } +} + +let mapStateToProps = store => ({ + profile: store.profile +}) + +let mapDispatchToProps = dispatch => ({ + profileCreate: profile => dispatch(profileCreateRequest(profile)) +}) + +export default connect(mapStateToProps, mapDispatchToProps)(SettingsContainer); diff --git a/front/src/reducer/auth.js b/front/src/reducer/auth.js index a41fbf8..4bd3bcf 100644 --- a/front/src/reducer/auth.js +++ b/front/src/reducer/auth.js @@ -9,4 +9,4 @@ module.exports = (state=null, action) => { default: return state; } -} +}; diff --git a/front/src/reducer/profile.js b/front/src/reducer/profile.js index eeb7a5e..c651d65 100644 --- a/front/src/reducer/profile.js +++ b/front/src/reducer/profile.js @@ -2,7 +2,7 @@ import validate from '../lib/validation.js'; let profileReqs = ['avatar', 'email', 'bio', '_id', 'owner', 'username']; -module.exports = (state, action => { +module.exports = (state=null, action) => { let {type, payload} = action; switch(type) { @@ -17,4 +17,4 @@ module.exports = (state, action => { default: return state; } -}) +} From 6e3c90186b3f445eecd03fea03b88fd1da107995 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 11 Sep 2017 10:31:10 -0700 Subject: [PATCH 29/32] The ginger bread man lives in a gingerbread house. Is he made from the house? Or is the house made form his flesh? He screams, for he does not know.... --- front/src/component/app/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index c3ca2be..2305648 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -5,6 +5,7 @@ import {BrowserRouter, Route, Link} from 'react-router-dom'; import Landing from '../landing'; import SettingsContainer from '../settings-container'; import createAppStore from '../../lib/createAppStore.js'; +import tokenSet from '../../action/profile-action'; let store = createAppStore() @@ -32,4 +33,12 @@ class App extends React.Component { } } +let mapSateToProps = store => ({ + profile: store.profile +}); + +let mapDispatchToProps = dispatch => ({ + tokenSet: token => dispatch(tokenSet(token)) +}) + export default App; From 16f85629803f6456feaa33d37f24b9dfd38b7458 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 11 Sep 2017 17:05:55 -0700 Subject: [PATCH 30/32] Added new component directories --- front/.env | 3 +++ front/src/component/app/index.js | 9 --------- front/src/component/avatar/index.js | 0 front/src/component/photo-form/index.js | 0 front/src/component/photo-item/index.js | 0 5 files changed, 3 insertions(+), 9 deletions(-) create mode 100644 front/src/component/avatar/index.js create mode 100644 front/src/component/photo-form/index.js create mode 100644 front/src/component/photo-item/index.js diff --git a/front/.env b/front/.env index eb4ac6b..e6141bc 100644 --- a/front/.env +++ b/front/.env @@ -1 +1,4 @@ API_URL='http://localhost:3000' +AWS_BUCKET='cf-giggle-app' +AWS_SECRET_ACCESS_KEY='teODM4s7oh9X0tZXQjSomsu7X1HLtz5o6mlTjId5' +AWS_ACCESS_KEY_ID='AKIAIYVWTGIO4BMPFKCA' diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index 2305648..c3ca2be 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -5,7 +5,6 @@ import {BrowserRouter, Route, Link} from 'react-router-dom'; import Landing from '../landing'; import SettingsContainer from '../settings-container'; import createAppStore from '../../lib/createAppStore.js'; -import tokenSet from '../../action/profile-action'; let store = createAppStore() @@ -33,12 +32,4 @@ class App extends React.Component { } } -let mapSateToProps = store => ({ - profile: store.profile -}); - -let mapDispatchToProps = dispatch => ({ - tokenSet: token => dispatch(tokenSet(token)) -}) - export default App; diff --git a/front/src/component/avatar/index.js b/front/src/component/avatar/index.js new file mode 100644 index 0000000..e69de29 diff --git a/front/src/component/photo-form/index.js b/front/src/component/photo-form/index.js new file mode 100644 index 0000000..e69de29 diff --git a/front/src/component/photo-item/index.js b/front/src/component/photo-item/index.js new file mode 100644 index 0000000..e69de29 From 8d2a03812c5f74a7a80dedaadd56198da8a8c8b9 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 11 Sep 2017 17:14:56 -0700 Subject: [PATCH 31/32] deleted .env --- front/.env | 4 ---- front/.gitignore | 2 +- front/src/component/avatar/index.js | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) delete mode 100644 front/.env diff --git a/front/.env b/front/.env deleted file mode 100644 index e6141bc..0000000 --- a/front/.env +++ /dev/null @@ -1,4 +0,0 @@ -API_URL='http://localhost:3000' -AWS_BUCKET='cf-giggle-app' -AWS_SECRET_ACCESS_KEY='teODM4s7oh9X0tZXQjSomsu7X1HLtz5o6mlTjId5' -AWS_ACCESS_KEY_ID='AKIAIYVWTGIO4BMPFKCA' diff --git a/front/.gitignore b/front/.gitignore index 94c74ef..dc150eb 100644 --- a/front/.gitignore +++ b/front/.gitignore @@ -1,2 +1,2 @@ /node_modules -/.env +.env diff --git a/front/src/component/avatar/index.js b/front/src/component/avatar/index.js index e69de29..e6684b2 100644 --- a/front/src/component/avatar/index.js +++ b/front/src/component/avatar/index.js @@ -0,0 +1,16 @@ +import React from 'react'; +import {connect} from 'react-redux'; + +class Avatar extends React.Component { + render() { + return ( + + ); + } +} + +let mapSateToProps = store => ({ + profile: store.profile +}); + +export default connect(mapSateToProps, undefined)(Avatar); From 385203c4609127ddb14e918b43d6cae85c0d59f2 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 11 Sep 2017 17:45:01 -0700 Subject: [PATCH 32/32] WTF --- front/src/action/auth-action.js | 1 + front/src/component/app/index.js | 1 + front/src/component/auth-form/index.js | 3 --- front/src/component/profile-form/index.js | 6 +++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/front/src/action/auth-action.js b/front/src/action/auth-action.js index 591edb2..750e426 100644 --- a/front/src/action/auth-action.js +++ b/front/src/action/auth-action.js @@ -10,6 +10,7 @@ export const tokenDelete = () => ({ }); export const signupRequest = user => dispatch => { + console.log('Bullshit') return superagent.post(`${__API_URL__}/signup`) .withCredentials() .send(user) diff --git a/front/src/component/app/index.js b/front/src/component/app/index.js index c3ca2be..71bd61b 100644 --- a/front/src/component/app/index.js +++ b/front/src/component/app/index.js @@ -10,6 +10,7 @@ let store = createAppStore() class App extends React.Component { render() { + return( diff --git a/front/src/component/auth-form/index.js b/front/src/component/auth-form/index.js index 30c5ea7..5b41cfa 100644 --- a/front/src/component/auth-form/index.js +++ b/front/src/component/auth-form/index.js @@ -46,9 +46,6 @@ class AuthForm extends React.Component { }) } - - - render() { let emailInput = ( diff --git a/front/src/component/profile-form/index.js b/front/src/component/profile-form/index.js index c8f850a..7707173 100644 --- a/front/src/component/profile-form/index.js +++ b/front/src/component/profile-form/index.js @@ -5,7 +5,7 @@ class ProfileForm extends React.Component { constructor(props) { super(props); this.state = props.profile ? - {...props.profile, bio: ''} : + {...this.props.profile, bio: ''} : {bio: '', avatar: null, preview: ''} this.onChange = this.onChange.bind(this); @@ -13,8 +13,8 @@ class ProfileForm extends React.Component { } componentWillReceiveProps(props) { - if(props.profile) { - this.setState(props.porfile); + if(this.props.profile) { + this.setState(this.props.profile); } }