@@ -1,11 +1,64 @@
import React from "react";
import { Redirect, Route, Link } from 'react-router-dom'
// const Nav = () => (
// <nav className="navbar navbar-expand-lg navbar-dark bg-primary">
// <a className="navbar-brand" href="/">
// React Reading List
// </a>
// </nav>
// );


const Nav = props => {
if (props.loggedIn) {
return (
<nav className="navbar">
<ul className="nav">
<li className="nav-item">
<Link to="/TeacherPortal" className="nav-link">
Teacher Portal
</Link>
</li>
<li>
<Link to="#" className="nav-link" onClick={props._logout}>
Logout
</Link>
</li>
</ul>
</nav>
)
} else {
return (
<nav className="navbar">
<ul className="nav">
<li className="nav-item">
<Link to="/login" className="nav-link">
Guardian Login
</Link>
</li>
<li className="nav-item">
<Link to="/teacherlogin" className="nav-link">
Teacher Login
</Link>
</li>
<li className="nav-item">
<Link to="/teacherSignup" className="nav-link">
Teacher Signup
</Link>
</li>
<li className="nav-item">
<Link to="/guardianSignup" className="nav-link">
Guardian Signup
</Link>
</li>
</ul>
</nav>
)
}
}




const Nav = () => (
<nav className="navbar navbar-expand-lg navbar-dark bg-primary">
<a className="navbar-brand" href="/">
React Reading List
</a>
</nav>
);

export default Nav;
@@ -44,7 +44,7 @@ class AddGuardCard extends Component {
event.preventDefault();
//create face token
API.detectFace({
face_token: this.state. face_token,
face_token: this.state.face_token,
})
.then(res => {
API.addGuard({
@@ -54,16 +54,6 @@ class AddGuardCard extends Component {
phone: this.state.phone,
face_Token: res.data
})
// .then(res => {
// for (let i = 0; i < this.state.coneCount; i++) {
// API.addCone({
// schoolName: this.state.schoolName,
// cone: {
// coneName: this.state.schoolName + "Cone" + (i + 1)
// }
// })
// }
// })
})
};

@@ -77,7 +67,6 @@ class AddGuardCard extends Component {
<AddImageCard
image_base64 = {this.state.image_base64}
/>

<div className="form-group">
<input
type="file"
@@ -0,0 +1,10 @@
import React from 'react';
import Webcam from 'react-webcam';

class Camera extends React.Component {
render() {
return <Webcam/>;
}
}

export default Camera;
@@ -0,0 +1 @@
export { default } from "./Camera.js";
@@ -11,16 +11,16 @@ class TeacherSignUp extends Component {


componentDidMount() {
this.loadSchools();
// this.loadSchools();
}

loadSchools = () => {
API.getSchool()
.then(res =>
this.setState( {schools: res.data})
)
.catch(err => console.log(err));
}
// loadSchools = () => {
// API.getSchool()
// .then(res =>
// this.setState( {schools: res.data})
// )
// .catch(err => console.log(err));
// }


handleInputChange = event => {
@@ -30,53 +30,53 @@ class TeacherSignUp extends Component {
});
};

toggleModal = () => {
this.setState({
isOpen: !this.state.isOpen
});
}

handleCreateFaceSet = event => {
event.preventDefault();

API.createFaceSet({
outer_id: this.state.create_outer_id,
display_name: this.state.create_display_name
})
.then(res => {
console.log(res.data);
this.setState({ faceset_token: res.data});
});
};

handleAddSchool = event => {
event.preventDefault();
// toggleModal = () => {
// this.setState({
// isOpen: !this.state.isOpen
// });
// }

// handleCreateFaceSet = event => {
// event.preventDefault();

// API.createFaceSet({
// outer_id: this.state.create_outer_id,
// display_name: this.state.create_display_name
// })
// .then(res => {
// console.log(res.data);
// this.setState({ faceset_token: res.data});
// });
// };

// handleAddSchool = event => {
// event.preventDefault();

API.createFaceSet({
outer_id: this.state.schoolName,
display_name: this.state.schoolName
})
.then(res => {
API.addSchool({
school_id: this.state.schoolName,
schoolName: this.state.schoolName,
schoolStreet: this.state.schoolStreet,
schoolCity: this.state.schoolCity,
schoolCounty: this.state.schoolCounty,
schoolState: this.state.schoolState,
schoolZip: this.state.schoolZip,
schoolPhone: this.state.schoolPhone,
schoolGrades: this.state.schoolGrades,
schoolImg: this.state.schoolImg,
teacherFirstName: this.state.teacherFirstName,
teacherLastName: this.state.teacherLastName,
teacherEmail: this.state.teacherEmail,
teacherPassword: this.state.teacherPassword,
teacherSchoolName: this.state.teacherSchoolName,
faceSetToken: res.data
})
})
};
// API.createFaceSet({
// outer_id: this.state.schoolName,
// display_name: this.state.schoolName
// })
// .then(res => {
// API.addSchool({
// school_id: this.state.schoolName,
// schoolName: this.state.schoolName,
// schoolStreet: this.state.schoolStreet,
// schoolCity: this.state.schoolCity,
// schoolCounty: this.state.schoolCounty,
// schoolState: this.state.schoolState,
// schoolZip: this.state.schoolZip,
// schoolPhone: this.state.schoolPhone,
// schoolGrades: this.state.schoolGrades,
// schoolImg: this.state.schoolImg,
// teacherFirstName: this.state.teacherFirstName,
// teacherLastName: this.state.teacherLastName,
// teacherEmail: this.state.teacherEmail,
// teacherPassword: this.state.teacherPassword,
// teacherSchoolName: this.state.teacherSchoolName,
// faceSetToken: res.data
// })
// })
// };



@@ -1,8 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import './index.css'
import { BrowserRouter } from 'react-router-dom'

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root')
)
@@ -1,41 +1,142 @@
import React, { Component } from "react";
import React, { Component } from 'react'
import { Redirect } from 'react-router-dom'

// import React, { Component } from "react";
import { Col, Row, Container } from "../../components/Grid";
import API from "../../utils/API";
import { Input, FormBtn} from "../../components/Form";

class Login extends Component {
constructor() {
super()
this.state = {
// username: '',
email: '',
password: '',
redirectTo: null
}

this.handleSubmit = this.handleSubmit.bind(this)
this.handleChange = this.handleChange.bind(this)
}

handleChange(event) {
this.setState({
[event.target.name]: event.target.value
})
}

handleSubmit(event) {
event.preventDefault()
console.log(this.state.email)
// console.log(this.state.redirectTo)
this.props._login(this.state.email, this.state.password)
this.setState({
redirectTo: '/Temp',
loggedIn: true,

})
// .then (<Redirect to={"/Temp"} />)

}

state = {
familyName: "",
name: ""
};
render() {

if (this.state.loggedIn) {
return <Redirect to="/Temp" />
console.log(this.state)
} else {
return (
<div className="Login">
<h1>Guardian Login</h1>
<form>
<label htmlFor="email">Email: </label>
<input
type="text"
name="email"
value={this.state.email}
onChange={this.handleChange}
/>
<label htmlFor="password">Password: </label>
<input
type="password"
name="password"
value={this.state.password}
onChange={this.handleChange}
/>
<button onClick={this.handleSubmit}>Login</button>
</form>

</div>
)
}
}
}
// state = {
// familyName: "",
// name: ""
// };

handleInputChange = event => {
const { name, value } = event.target;
this.setState({
[name]: value
});
};

handleAddFamily = event => {
event.preventDefault();
API.addFamily({
familyName: this.state.familyName
})
};
// handleInputChange = event => {
// const { name, value } = event.target;
// this.setState({
// [name]: value
// });
// };

// handleAddFamily = event => {
// event.preventDefault();
// API.addFamily({
// familyName: this.state.familyName
// })
// };


render() {

<<<<<<< HEAD
return (
<Container fluid>
<h1>Hello World</h1>
</Container>
)
}
};
=======
// render() {
>>>>>>> ef02c4f79c161b5548fe408cece6740cdf577713

// return (
// <Container fluid>
// <h1>Hello World</h1>
// <div className="panel panel-default">
// <div className="panel-body">
// <Row>
// <Col size="md-6">
// <div className="form-group">
// <Input className="form-control"
// value={this.state.familyName}
// onChange={this.handleInputChange}
// name="fName"
// placeholder="Enter Family Name"
// />
// </div>
// </Col>
// </Row>
// <Row>
// <Col size="md-6">
// <FormBtn
// onClick={this.handleAddFamily}
// >
// Input Family
// </FormBtn>
// </Col>
// </Row>
// </div>
// </div>
// </Container>
// )
// }
// };

export default Login;
export default Login
@@ -1 +1 @@
export { default } from "./Login.js";
export { default } from "./Login.js";
@@ -0,0 +1,34 @@
import React from 'react';
import Webcam from 'react-webcam';

class TestWebCam extends React.Component {
setRef = (webcam) => {
this.webcam = webcam;
}

capture = () => {
console.log("I SAW A CLICK");
const imageSrc = this.webcam.getScreenshot();
console.log(imageSrc);
};

render() {
return (
<div>
<h1>I am here</h1>
<div>
<Webcam
audio={false}
height={350}
ref={this.setRef}
screenshotFormat="image/jpeg"
width={350}
/>
<button onClick={this.capture}>Capture photo</button>
</div>
</div>
);
}
}

export default TestWebCam;
@@ -0,0 +1 @@
export { default } from "./TestWebCam";
@@ -0,0 +1,103 @@
import React, { Component } from 'react'
import axios from 'axios'
import { Redirect } from 'react-router-dom'

class guardianSignup extends Component {
constructor() {
super()
this.state = {
fName: '',
lName: '',
email: '',
phone: '',
password: '',
confirmPassword: '',
redirectTo: null
}
this.handleSubmit = this.handleSubmit.bind(this)
this.handleChange = this.handleChange.bind(this)
}
handleChange(event) {
this.setState({
[event.target.name]: event.target.value
})
}
handleSubmit(event) {
event.preventDefault()
// TODO - validate!
axios
.post('/auth/signup', {
fName: this.state.fName,
lName: this.state.lName,
email: this.state.email,
phone: this.state.phone,
password: this.state.password
})
.then(response => {
console.log(response)
if (!response.data.errmsg) {
console.log('youre good')
this.setState({
redirectTo: '/Temp'
})
} else {
console.log('duplicate')
}
})
}
render() {
if (this.state.redirectTo) {
return <Redirect to={{ pathname: this.state.redirectTo }} />
}
return (
<div className="guardianSignup">
<h1>Guardian Signup Form</h1>
<label htmlFor="fName">Firstname: </label>
<input
type="text"
name="fName"
value={this.state.fName}
onChange={this.handleChange}
/>
<label htmlFor="lName">Lastname: </label>
<input
type="text"
name="lName"
value={this.state.lName}
onChange={this.handleChange}
/>
<label htmlFor="email">Email: </label>
<input
type="text"
name="email"
value={this.state.email}
onChange={this.handleChange}
/>
<label htmlFor="phone">Phone: </label>
<input
type="string"
name="phone"
value={this.state.phone}
onChange={this.handleChange}
/>
<label htmlFor="password">Password: </label>
<input
type="password"
name="password"
value={this.state.password}
onChange={this.handleChange}
/>
<label htmlFor="confirmPassword">Confirm Password: </label>
<input
type="password"
name="confirmPassword"
value={this.state.confirmPassword}
onChange={this.handleChange}
/>
<button onClick={this.handleSubmit}>Sign up</button>
</div>
)
}
}

export default guardianSignup
@@ -0,0 +1 @@
export { default } from "./guardianSignup.js";
@@ -0,0 +1 @@
export { default } from "./teacherLogin";
@@ -0,0 +1,72 @@
import React, { Component } from 'react'
import { Redirect } from 'react-router-dom'


class teacherLogin extends Component {
constructor() {
super()
this.state = {
// username: '',
email: '',
password: '',
redirectTo: null
}

this.handleSubmit = this.handleSubmit.bind(this)
this.handleChange = this.handleChange.bind(this)
}

handleChange(event) {
this.setState({
[event.target.name]: event.target.value
})
}

handleSubmit(event) {
event.preventDefault()
console.log('handleSubmit')
// console.log(this.state.redirectTo)
this.props._teacherlogin(this.state.email, this.state.password)
this.setState({
redirectTo: '/Temp',
loggedIn: true,

})
// .then (<Redirect to={"/Temp"} />)

}

render() {

if (this.state.loggedIn) {
return <Redirect to="/Temp" />
console.log(this.state)
} else {
return (
<div className="teacherLogin">
<h1>Teacher Login</h1>
<form>
<label htmlFor="email">Email: </label>
<input
type="text"
name="email"
value={this.state.email}
onChange={this.handleChange}
/>
<label htmlFor="password">Password: </label>
<input
type="password"
name="password"
value={this.state.password}
onChange={this.handleChange}
/>
<button onClick={this.handleSubmit}>Login</button>
</form>

</div>
)
}
}
}

export default teacherLogin
@@ -0,0 +1 @@
export { default } from "./teacherSignup";
@@ -0,0 +1,111 @@
import React, { Component } from 'react'
import axios from 'axios'
import { Redirect } from 'react-router-dom'

class teacherSignup extends Component {
constructor() {
super()
this.state = {
fName: '',
lName: '',
email: '',
school: '',
password: '',
confirmPassword: '',
redirectTo: null
}
this.handleSubmit = this.handleSubmit.bind(this)
this.handleChange = this.handleChange.bind(this)
}
handleChange(event) {
this.setState({
[event.target.name]: event.target.value
})
}
handleSubmit(event) {
event.preventDefault()
// TODO - validate!
axios
.post('/auth/teachersignup', {
fName: this.state.fName,
lName: this.state.lName,
email: this.state.email,
school: this.state.school,
phone: this.state.phone,
password: this.state.password
})
.then(response => {
console.log(response)
if (!response.data.errmsg) {
console.log('youre good')
this.setState({
redirectTo: '/Temp'
})
} else {
console.log('duplicate')
}
})
}
render() {
if (this.state.redirectTo) {
return <Redirect to={{ pathname: this.state.redirectTo }} />
}
return (
<div className="teacherSignup">
<h1>Teacher Signup Form</h1>
<label htmlFor="fName">Firstname: </label>
<input
type="text"
name="fName"
value={this.state.fName}
onChange={this.handleChange}
/>
<label htmlFor="lName">Lastname: </label>
<input
type="text"
name="lName"
value={this.state.lName}
onChange={this.handleChange}
/>
<label htmlFor="email">Email: </label>
<input
type="text"
name="email"
value={this.state.email}
onChange={this.handleChange}
/>
<label htmlFor="school">School: </label>
<input
type="string"
name="school"
value={this.state.school}
onChange={this.handleChange}
/>
<label htmlFor="phone">Phone: </label>
<input
type="string"
name="phone"
value={this.state.phone}
onChange={this.handleChange}
/>
<label htmlFor="password">Password: </label>
<input
type="password"
name="password"
value={this.state.password}
onChange={this.handleChange}
/>
<label htmlFor="confirmPassword">Confirm Password: </label>
<input
type="password"
name="confirmPassword"
value={this.state.confirmPassword}
onChange={this.handleChange}
/>
<button onClick={this.handleSubmit}>Sign up</button>
</div>
)
}
}

export default teacherSignup
@@ -49,6 +49,13 @@ export default function register() {
registerValidSW(swUrl);
}
});

window.addEventListener('fetch', (event) => {
if ( event.request.url.match( '^.*(\/api\/).*$' ) ) {
return false;
}
});

}
}

@@ -5424,7 +5424,7 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.6.0:
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.0:
version "15.6.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.1.tgz#36644453564255ddda391191fb3a125cbdf654ca"
dependencies:
@@ -5657,6 +5657,12 @@ react-scripts@1.1.4:
optionalDependencies:
fsevents "^1.1.3"

react-webcam@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/react-webcam/-/react-webcam-0.5.0.tgz#ab272930381a2cf0fe02ab8b22df34b94953d191"
dependencies:
prop-types "^15.5.8"

react@^16.3.2:
version "16.3.2"
resolved "https://registry.yarnpkg.com/react/-/react-16.3.2.tgz#fdc8420398533a1e58872f59091b272ce2f91ea9"
@@ -10,7 +10,6 @@ module.exports = {
.catch(err => res.status(422).json(err));
},
getSchool: function(req, res) {
console.log("getSchool", req.body.schoolName);
db.School
.find(req.body)
.populate("cone")
@@ -133,5 +132,22 @@ module.exports = {
.findOneAndUpdate({_id: req.body._id}, {$push: {queueData: {face_token: req.body.face_token, confidence: req.body.confidence}}}, {new: true})
.then(dbModel => res.json(dbModel))
.catch(err => res.status(422).json(err));
},
addPickup: function(req, res) {
db.Pickup.create(req.body.pickup)
.then(function(dbPickup) {
return db.Family.findOneAndUpdate({_id: familyId}, {$push: {pickup: dbPickup._id}}, {new: true });
})
.then(dbModel => res.json(dbModel))
.catch(err => res.status(422).json(err));
},

addStudent: function(req, res) {
db.Student.create(req.body.student)
.then(function(dbStudent) {
return db.Family.findOneAndUpdate({_id: familyId}, {$push: {student: dbStudent._id}}, {new: true})
})
.then(dbModal => res.json(dbModel))
.catch(err => res.status(422).json(err));
}
};
@@ -0,0 +1,28 @@
/* Mongo Database
* - this is where we set up our connection to the mongo database
*/
const mongoose = require('mongoose')
mongoose.Promise = global.Promise
let MONGO_URL
// const MONGO_LOCAL_URL = 'mongodb://localhost/carpoolGuardian'

// if (process.env.MONGODB_URI) {
// mongoose.connect(process.env.MONGODB_URI)
// MONGO_URL = process.env.MONGODB_URI
// } else {
// mongoose.connect(MONGO_LOCAL_URL) // local mongo url
// MONGO_URL = MONGO_LOCAL_URL
// }

// // should mongoose.connection be put in the call back of mongoose.connect???
// const db = mongoose.connection
// db.on('error', err => {
// console.log(`There was an error connecting to the database: ${err}`)
// })
// db.once('open', () => {
// console.log(
// `You have successfully connected to your mongo database: ${MONGO_URL}`
// )
// })

// module.exports = db
@@ -0,0 +1,44 @@
// const mongoose = require('mongoose')
// const Schema = mongoose.Schema
// const bcrypt = require('bcryptjs')
// mongoose.promise = Promise

// // Define userSchema
// const teacherSchema = new Schema({
// firstName: { type: String, unique: false },
// lastName: { type: String, unique: false },
// email: {type: String,
// unique: true,
// match: [/.+@.+\..+/, "Please enter a valid e-mail address"]
// },
// school: {type: String, unique: false, required: false },
// password: { type: String, unique: false, required: false },
// photos: []

// })

// // Define schema methods
// teacherSchema.methods = {
// checkPassword: function(inputPassword) {
// return bcrypt.compareSync(inputPassword, this.password)
// },
// hashPassword: plainTextPassword => {
// return bcrypt.hashSync(plainTextPassword, 10)
// }
// }

// // Define hooks for pre-saving
// teacherSchema.pre('save', function(next) {
// if (!this.password) {
// console.log('=======NO PASSWORD PROVIDED=======')
// next()
// } else {
// this.password = this.hashPassword(this.password)
// next()
// }

// })

// // Create reference to User & export
// const Teacher = mongoose.model('Teacher', teacherSchema)
// module.exports = Teacher
@@ -0,0 +1,45 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const bcrypt = require('bcryptjs')
mongoose.promise = Promise

// Define userSchema
const userSchema = new Schema({
firstName: { type: String, unique: false },
lastName: { type: String, unique: false },
email: {type: String,
unique: true,
match: [/.+@.+\..+/, "Please enter a valid e-mail address"]
},
password: { type: String, unique: false, required: false },

photos: []

})

// Define schema methods
userSchema.methods = {
checkPassword: function(inputPassword) {
return bcrypt.compareSync(inputPassword, this.password)
},
hashPassword: plainTextPassword => {
return bcrypt.hashSync(plainTextPassword, 10)
}
}

// Define hooks for pre-saving
userSchema.pre('save', function(next) {
if (!this.password) {
console.log('=======NO PASSWORD PROVIDED=======')
next()
} else {
this.password = this.hashPassword(this.password)
next()
}
// this.password = this.hashPassword(this.password)
// next()
})

// Create reference to User & export
const User = mongoose.model('User', userSchema)
module.exports = User
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,5 +1,7 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const bcrypt = require('bcryptjs')
mongoose.promise = Promise

const GuardSchema = new Schema({
fName: { type: String, required: true, trim: true },
@@ -42,6 +44,37 @@ const GuardSchema = new Schema({
}
});

// Define schema methods
GuardSchema.methods = {
checkPassword: function(inputPassword) {
return bcrypt.compareSync(inputPassword, this.password)
},
hashPassword: plainTextPassword => {
return bcrypt.hashSync(plainTextPassword, 10)
}
}

// Define hooks for pre-saving
GuardSchema.pre('save', function(next) {
if (!this.password) {
console.log('=======NO PASSWORD PROVIDED=======')
next()
} else {
this.password = this.hashPassword(this.password)
next()
}
// this.password = this.hashPassword(this.password)
// next()
})

const Guardian = mongoose.model("Guardian", GuardSchema);

module.exports = Guardian;
module.exports = Guardian;








@@ -1,4 +1,44 @@
module.exports = {
// module.exports = {
// // path to the guardians db
// Guardian: require("./guardian"),
// School: require("./school"),
// Teacher: require("./teacher"),
// Family: require("./family"),
// Cone: require("./cone")
// };

/* Mongo Database
* - this is where we set up our connection to the mongo database
*/
const mongoose = require('mongoose')
mongoose.Promise = global.Promise
let MONGO_URL
const MONGO_LOCAL_URL = 'mongodb://localhost/carpoolGuardian'

if (process.env.MONGODB_URI) {
mongoose.connect(process.env.MONGODB_URI)
MONGO_URL = process.env.MONGODB_URI
} else {
mongoose.connect(MONGO_LOCAL_URL) // local mongo url
MONGO_URL = MONGO_LOCAL_URL
}

// should mongoose.connection be put in the call back of mongoose.connect???
const db = mongoose.connection
db.on('error', err => {
console.log(`There was an error connecting to the database: ${err}`)
})
db.once('open', () => {
console.log(
`You have successfully connected to your mongo database: ${MONGO_URL}`
)
})

// module.exports = db
module.exports = db, {

// path to the guardians db
// module.exports = {
// path to the guardians db
Family: require("./family"),
Guardian: require("./guardian"),
@@ -7,5 +47,4 @@ module.exports = {
School: require("./school"),
Teacher: require("./teacher"),
Cone: require("./cone")
};

};
@@ -1,5 +1,9 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const bcrypt = require('bcryptjs')
mongoose.promise = Promise



const teacherSchema = new Schema({
fName: { type: String, required: true, trim: true },
@@ -10,6 +14,7 @@ const teacherSchema = new Schema({
minlength: 2,
maxLength: 15
},
school: { type: String, required: true, trim: true },
img_base64: { data: Buffer, type: String, required: false },
date: { type: Date, default: Date.now },
email: {
@@ -41,5 +46,48 @@ const teacherSchema = new Schema({
}
});

const Teacher = mongoose.model("Teacher", teacherSchema);
module.exports = Teacher;
// const Teacher = mongoose.model("Teacher", teacherSchema);
// module.exports = Teacher;




// Define userSchema
// const teacherSchema = new Schema({
// firstName: { type: String, unique: false },
// lastName: { type: String, unique: false },
// email: {type: String,
// unique: true,
// match: [/.+@.+\..+/, "Please enter a valid e-mail address"]
// },
// school: {type: String, unique: false, required: false },
// password: { type: String, unique: false, required: false },
// photos: []

// })

// Define schema methods
teacherSchema.methods = {
checkPassword: function(inputPassword) {
return bcrypt.compareSync(inputPassword, this.password)
},
hashPassword: plainTextPassword => {
return bcrypt.hashSync(plainTextPassword, 10)
}
}

// Define hooks for pre-saving
teacherSchema.pre('save', function(next) {
if (!this.password) {
console.log('=======NO PASSWORD PROVIDED=======')
next()
} else {
this.password = this.hashPassword(this.password)
next()
}

})

// Create reference to User & export
const Teacher = mongoose.model('Teacher', teacherSchema)
module.exports = Teacher
@@ -17,13 +17,35 @@
},
"dependencies": {
"axios": "^0.18.0",
"bcrypt": "^1.0.2",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"connect-mongo": "^1.3.2",
"dotenv": "^4.0.0",
"express": "^4.16.3",
"express-session": "^1.15.4",
"form-data": "^2.3.2",
"mongoose": "^5.0.17",
<<<<<<< HEAD
"morgan": "^1.8.2",
"passport": "^0.3.2",
"passport-google-oauth": "^1.0.0",
"passport-google-oauth20": "^1.0.0",
"passport-local": "^1.0.0",
"qs": "^6.5.2",
"react": "^15.5.4",
"react-bootstrap": "^0.32.1",
"react-dom": "^15.5.4",
"react-router-dom": "^4.2.2",
"react-scripts": "^1.1.4"
=======
"prop-types": "^15.6.1",
"qs": "^6.5.2",
"react-scripts": "^1.1.4",
"react-webcam": "^0.5.0"
>>>>>>> 83ff705573ec6b1efc669d81271fc491ccd51402
},
"proxy": "http://localhost:8080",
"author": "",
"license": "ISC"
}
@@ -0,0 +1,48 @@
const passport = require('passport')
const LocalStrategy = require('./localStrategy')
const teacherStrategy = require('./teacherstrategy')
// const GoogleStratgey = require('./googleStrategy')
const Guardian = require('../models/guardian')
const Teacher = require('../models/teacher');

passport.serializeUser((user, done) => {
console.log('=== serialize ... called ===')
console.log(user) // the whole raw user object!
console.log('---------')
done(null, { _id: user._id })
})

passport.deserializeUser((id, done) => {
(Guardian.findOne(
{ _id: id } === null)) ?
Teacher.findOne(
{ _id: id },
'fName lName school email',
(err, user) => {
console.log('======= DESERIALIZE USER CALLED ======')
console.log(user)
console.log('--------------')
done(null, user)
}
) :
Guardian.findOne(
{ _id: id },
'fName lName phone email',
(err, user) => {
console.log('======= DESERIALIZE USER CALLED ======')
console.log(user)
console.log('--------------')
done(null, user)
}
)

})



// ==== Register Strategies ====
passport.use('local', LocalStrategy)
passport.use('local.teacher', teacherStrategy)
// passport.use(GoogleStratgey)

module.exports = passport
@@ -0,0 +1,27 @@
const Guardian = require('../models/guardian')

const LocalStrategy = require('passport-local').Strategy

const strategy = new LocalStrategy(
{
usernameField: 'email' // not necessary, DEFAULT
},
function(email, password, done) {
Guardian.findOne({ 'email': email }, (err, userMatch) => {
if (err) {
return done(err)
}
if (!userMatch) {
return done(null, false, { message: 'Incorrect username' })
}
if (!userMatch.checkPassword(password)) {
return done(null, false, { message: 'Incorrect password' })
}
return done(null, userMatch)
})
}
)



module.exports = strategy
@@ -0,0 +1,25 @@
const Teacher = require('../models/teacher');

const LocalStrategy = require('passport-local').Strategy

const teacherstrategy = new LocalStrategy(
{
usernameField: 'email' // not necessary, DEFAULT
},
function(email, password, done) {
Teacher.findOne({ 'email': email }, (err, teacherMatch) => {
if (err) {
return done(err)
}
if (!teacherMatch) {
return done(null, false, { message: 'Incorrect username' })
}
if (!teacherMatch.checkPassword(password)) {
return done(null, false, { message: 'Incorrect password' })
}
return done(null, teacherMatch)
})
}
)

module.exports = teacherstrategy
@@ -0,0 +1,124 @@
const express = require('express');
const router = express.Router();
const Guardian = require('../../models/guardian');
const Teacher = require('../../models/teacher');
const passport = require('../../passport');


// this route is just used to get the user basic info
router.get('/user', (req, res, next) => {
console.log('===== user!!======')
console.log(req.user)
if (req.user) {
return res.json({ user: req.user })
} else {
return res.json({ user: null })
}
})

router.post(
'/login',
function(req, res, next) {
console.log(req.body)
// console.log('=====testing===========')
next()
},
passport.authenticate('local'),
(req, res) => {
// console.log('POST to /login')
const user = JSON.parse(JSON.stringify(req.user)) // hack
const cleanUser = Object.assign({}, user)
if (cleanUser) {
console.log(`Deleting ${cleanUser.password}`)
delete cleanUser.password
}
res.json({ user: cleanUser })
// res.redirect('/Temp');

}
)

router.post(
'/teacherlogin',
function(req, res, next) {
console.log(req.body)
// console.log('=====testing===========')
next()
},
passport.authenticate('local.teacher'),
(req, res) => {
// console.log('POST to /login')
const user = JSON.parse(JSON.stringify(req.user)) // hack
const cleanUser = Object.assign({}, user)
if (cleanUser) {
console.log(`Deleting ${cleanUser.password}`)
delete cleanUser.password
}
res.json({ user: cleanUser })
// res.redirect('/Temp');

}
)

router.post('/logout', (req, res) => {
if (req.user) {
req.session.destroy()
res.clearCookie('connect.sid') // clean up!
return res.json({ msg: 'logging you out' })
} else {
return res.json({ msg: 'no user to log out!' })
}
})

router.post('/signup', (req, res) => {
const { fName, lName, email, phone, password } = req.body
console.log(req.body);
// ADD VALIDATION
Guardian.findOne({ 'email': email }, (err, userMatch) => {
if (userMatch) {
res.json({
error: `Sorry, already a user with the email: ${email}`
})
}
const newGuardian = new Guardian({
'fName': fName,
'lName': lName,
'email': email,
'phone': phone,
'password': password
})
newGuardian.save((err, savedUser) => {
console.log(savedUser);
if (err) throw err;
res.json(savedUser)
})
})
})

router.post('/teachersignup', (req, res) => {
const { fName, lName, email, school, phone, password } = req.body
console.log(req.body);
// ADD VALIDATION
Teacher.findOne({ 'email': email }, (err, teacherMatch) => {
if (teacherMatch) {
return res.json({
error: `Sorry, already a teacher with the email: ${email}`
})
}
const newTeacher = new Teacher({
'fName': fName,
'lName': lName,
'email': email,
'school': school,
'phone': phone,
'password': password
})
newTeacher.save((err, savedTeacher) => {
console.log(savedTeacher);
if (err) throw err;
res.json(savedTeacher)
})
})
})

module.exports = router
@@ -1,13 +1,16 @@
const path = require("path");
// const path = require("path");
const router = require("express").Router();
const apiRoutes = require("./api");
const authRoutes = require("./auth");

// API Routes
router.use("/api", apiRoutes);
// auth Routes
router.use("/auth", authRoutes);

// If no API routes are hit, send the React app
router.use(function(req, res) {
res.sendFile(path.join(__dirname, "../client/public/index.html"));
});
// // If no API routes are hit, send the React app
// router.use(function(req, res) {
// res.sendFile(path.join(__dirname, "../client/public/index.html"));
// });

module.exports = router;
@@ -2,8 +2,34 @@ const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const routes = require("./routes");
const morgan = require("morgan");
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);
const dbConnection = require("./models"); // loads our connection to the mongo database
const passport = require("./passport");
const app = express();
const PORT = process.env.PORT || 3001;
const PORT = process.env.PORT || 8080;

// ===== Middleware ====
app.use(morgan('dev'))
app.use(
bodyParser.urlencoded({
extended: false
})
)
app.use(bodyParser.json())
app.use(
session({
secret: process.env.APP_SECRET || 'this is the default passphrase',
store: new MongoStore({ mongooseConnection: dbConnection }),
resave: false,
saveUninitialized: false
})
)

// ===== Passport ====
app.use(passport.initialize())
app.use(passport.session()) // will call the deserializeUser

// Configure body parser for AJAX requests
app.use(bodyParser.urlencoded({ extended: true, limit: '3mb', parameterLimit: 3000 }));
@@ -13,8 +39,8 @@ app.use(express.static("client/public"));
// Add routes, both API and view
app.use(routes);

// Connect to the Mongo DB
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/carpoolGuardian");
// // Connect to the Mongo DB
// mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/carpoolGuardian");

app.get("/", function(req, res) {
res.sendFile(path.join(__dirname, "apitemp.html"));
@@ -24,6 +50,8 @@ app.post("/createFaceSet", function(req, res) {
console.log(req.body);
});



// Start the API server
app.listen(PORT, function() {
console.log(`🌎 ==> API Server now listening on PORT ${PORT}!`);
6,117 yarn.lock

Large diffs are not rendered by default.