| @@ -0,0 +1,96 @@ | ||
| import React, {Component} from "react"; | ||
| import Aux from "../../hoc/Aux"; | ||
| import SignUpInputs from "../../components/SignUpInputs/SignUpInputs"; | ||
| import axios from "axios"; | ||
|
|
||
| class SignUp extends Component { | ||
|
|
||
| state = { | ||
| signupForm: { | ||
| username: { | ||
| elementConfig: { | ||
| type: 'text', | ||
| placeholder: 'Your Username' | ||
| }, | ||
| value: '' | ||
| }, | ||
| password: { | ||
| elementConfig: { | ||
| type: 'text', | ||
| placeholder: 'Password' | ||
| }, | ||
| value: '' | ||
| }, | ||
| email: { | ||
| elementConfig: { | ||
| type: 'text', | ||
| placeholder: 'Email' | ||
| }, | ||
| value: '' | ||
| } | ||
| }, | ||
| loading: false | ||
| } | ||
|
|
||
| signupClick = () => { | ||
| const formData = {}; | ||
|
|
||
| for (let formElementIdentifier in this.state.signupForm) { | ||
| formData[formElementIdentifier] = this.state.signupForm[formElementIdentifier].value; | ||
| } | ||
|
|
||
|
|
||
| axios.post("/signup", formData) | ||
| .then(function (response) { | ||
| console.log(response); | ||
| }) | ||
| .catch(function (error) { | ||
| console.log(error); | ||
| }); | ||
| }; | ||
|
|
||
| inputChangedHandler = (event, inputIdentifier) => { | ||
| const updatedSignupForm = { | ||
| ...this.state.signupForm | ||
| }; | ||
| const updatedFormElement = { | ||
| ...updatedSignupForm[inputIdentifier] | ||
| }; | ||
| updatedFormElement.value = event.target.value; | ||
| updatedSignupForm[inputIdentifier] = updatedFormElement; | ||
| this.setState({signupForm: updatedSignupForm}); | ||
| } | ||
|
|
||
| handleOpen = () => { | ||
| this.setState({ openListingDetail: true }); | ||
| }; | ||
|
|
||
| handleClose = () => { | ||
| this.setState({ openListingDetail: false }); | ||
| }; | ||
|
|
||
|
|
||
| render () { | ||
|
|
||
| const formElementsArray = []; | ||
| for (let key in this.state.signupForm) { | ||
| formElementsArray.push({ | ||
| id: key, | ||
| config: this.state.signupForm[key] | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| return ( | ||
| <Aux> | ||
| <SignUpInputs | ||
| changed = {this.inputChangedHandler} | ||
| elements = {formElementsArray} | ||
| signup = {this.signupClick}/> | ||
| </Aux> | ||
| ); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| export default SignUp; |
| @@ -0,0 +1 @@ | ||
| export const SEARCH_BUSINESSES = "SEARCH_BUSINESSES"; |
| @@ -0,0 +1,11 @@ | ||
| import * as actionTypes from "./actions"; | ||
|
|
||
| const initialState = { | ||
| business: [] | ||
| } | ||
|
|
||
| const reducer = (state = initialState, action) => { | ||
|
|
||
| }; | ||
|
|
||
| export default reducer; |
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "development": { | ||
| "username": "root", | ||
| "password": "password", | ||
| "database": "exampledb", | ||
| "host": "localhost", | ||
| "dialect": "mysql" | ||
| }, | ||
| "test": { | ||
| "username": "root", | ||
| "password": "password", | ||
| "database": "testdb", | ||
| "host": "localhost", | ||
| "dialect": "mysql", | ||
| "logging": false | ||
| }, | ||
| "production": { | ||
| "use_env_variable": "JAWSDB_URL", | ||
| "dialect": "mysql" | ||
| } | ||
| } |
| @@ -0,0 +1,124 @@ | ||
| const bCrypt = require("bcrypt"); | ||
| module.exports = function(passport, userinfo) { | ||
| const Userinfo = userinfo; | ||
| const LocalStrategy = require("passport-local").Strategy; | ||
|
|
||
| passport.use( | ||
| "local-signup", | ||
| new LocalStrategy( | ||
| { | ||
| usernameField: "username", | ||
| passwordField: "password", | ||
| email: "email", | ||
| passReqToCallback: true // allows us to pass back the entire request to the callback | ||
| }, | ||
| function(req, username, password, done) { | ||
| const generateHash = function(password) { | ||
| return bCrypt.hashSync(password, bCrypt.genSaltSync(8), null); | ||
| }; | ||
| Userinfo.findOne({ | ||
| where: { | ||
| username: username | ||
| } | ||
| }).then(function(user) { | ||
| if (user) { | ||
| return done(null, false, { | ||
| message: "That username is already taken" | ||
| }); | ||
| } else { | ||
| const userPassword = generateHash(password); | ||
| const data = { | ||
| username: username, | ||
| password: userPassword, | ||
| email: req.body.email | ||
| }; | ||
| Userinfo.create(data).then(function(user) { | ||
| if (!user) { | ||
| return done(null, false); | ||
| } else { | ||
| user.get(); | ||
| console.log("HELLOOO FROM PASSPORT.JSSSSS >>>>>>>>>>", user); | ||
| return done(null, user); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| ) | ||
| ); | ||
|
|
||
| passport.serializeUser(function(user, done) { | ||
| done(null, user.id); | ||
| }); | ||
|
|
||
| passport.deserializeUser(function(id, done) { | ||
| Userinfo.findOne({ | ||
| where: { | ||
| id: id | ||
| } | ||
| }).then(function(user) { | ||
| if (user) { | ||
| done(null, user.get()); | ||
| } else { | ||
| done(user.errors, null); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| //LOCAL SIGNIN | ||
| passport.use( | ||
| "local-signin", | ||
| new LocalStrategy( | ||
| { | ||
| usernameField: "username", | ||
| passwordField: "password", | ||
| passReqToCallback: true | ||
| }, | ||
| function(req, username, password, done) { | ||
| const Userinfo = userinfo; | ||
| const isValidPassword = function(accountKey, password) { | ||
| return bCrypt.compareSync(password, accountKey); | ||
| }; | ||
| Userinfo.findOne({ | ||
| where: { | ||
| username: username | ||
| } | ||
| }) | ||
| .then(function(user) { | ||
| if (!user) { | ||
| return done(null, false, { | ||
| message: "Username does not exist" | ||
| }); | ||
| } | ||
| if (!isValidPassword(user.password, password)) { | ||
| return done(null, false, { | ||
| message: "Incorrect password." | ||
| }); | ||
| } else { | ||
| user.get(); | ||
| console.log("PASSPORT>>>>>>>", user.id); | ||
| return done(null, user); | ||
| } | ||
| }) | ||
| .catch(function(err) { | ||
| console.log("Error:", err); | ||
| return done(null, false, { | ||
| message: "Something went wrong with your Signin" | ||
| }); | ||
| }); | ||
| } | ||
| ) | ||
| ); | ||
| passport.serializeUser(function(user, done) { | ||
| done(null, user.id); | ||
| }); | ||
| passport.deserializeUser(function(id, done) { | ||
| Userinfo.findById(id).then(function(user) { | ||
| if (user) { | ||
| done(null, user.get()); | ||
| } else { | ||
| done(user.errors, null); | ||
| } | ||
| }); | ||
| }); | ||
| }; |