@@ -1,20 +1,64 @@
import React, {Component} from "react";
import Aux from "../../hoc/Aux";
import LoginInputs from "../../components/LoginInputs/LoginInputs"
import SignUpInputs from "../../components/SignUpInputs/SignUpInputs";
import axios from "axios";

class Login extends Component {

state = {
accounts: [
{
name: "tonyli",
password: "password"
signupForm: {
username: {
elementConfig: {
type: 'text',
placeholder: 'Your Username'
},
value: ''
},
{
name: "user1",
password: "password"
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 = () => {
@@ -28,11 +72,21 @@ class Login extends Component {

render () {

//const listings = [...this.state.businesses];
const formElementsArray = [];
for (let key in this.state.signupForm) {
formElementsArray.push({
id: key,
config: this.state.signupForm[key]
});
}


return (
<Aux>
<LoginInputs/>
<SignUpInputs
changed = {this.inputChangedHandler}
elements = {formElementsArray}
signup = {this.signupClick}/>
</Aux>
);
}
@@ -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;
@@ -1,14 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import {Provider} from "react-redux";
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

const app = (
<BrowserRouter>
<App/>
</BrowserRouter>
<Provider>
<BrowserRouter>
<App/>
</BrowserRouter>
</Provider>
);

ReactDOM.render(app, document.getElementById('root'));
@@ -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);
}
});
});
};