Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project 2 #36

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 82 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,96 @@
# Your Project Name
# ArtyCraftyCourses

#Get messy here at! https://artycraftycourses.herokuapp.com/

## OverView

Platform for Artsy & Crafty people to find and share their art skills with others like-minded people.

Allows experienced people to have an opportunity to start their very own art class that they are skilled in. The platform allows people to apply for an instructor position, having this position allows them to create art courses online. Only when there is enough demand for the course, then course will be passed on to allow the student users to enrol in them. The platform also allows student users to register to apply for any current course and vote for a course that they would like to attend.

Instructor :
Needs an Admin Code for Registration.
Must prove to be well knowledge in the field of Art course pending creation.
Must have a space for students to comfortably attend the course.
Able to show a certain level of competency for teaching.
Must have a PayPal Account.

Student :
Free registration.
Must have a PayPal Account.

Art platform :
Collects the transaction from students.
Students can get cancelation fee only till 5 days before course begins.
Teacher is paid when course is done.


## Site Navigation

Home Page :
* Available art genres for sign up.
* Updates and Current relevant news.
---
Register Page :
* Student - Requires Username, password and email.
* Instructor = Requires **ADMIN CODE**, username, password and email.
---
Login page :
* Selection of student or Instructor.
email and password require.
---
Profile page:
* Student - Basic Profile : name, email, about, current course, completed course
Able to update, edit profile.
* Instructor - Advance Profile : name, email, about, current course, completed course, currently teaching.
Able to update, edit profile.
---
Current Course page:
* View current available courses here.
* Instructor is able to edit & update own's current course.
* Each available course can be recommended by students who completed it.
* Each available course can be reviewed students who completed it.
* Each available course has it's own details.
---
Pending Course page:
* View pending courses available here.
* Pending courses can be voted up / down once per user.
* Instructor can create new course in this page.
* When pending course reaches a certain number of Up votes, it goes to current courses.
* Each pending course can be questioned by users.
* Each pending course can be updated by Instructor who created it.
* Each pending course has its own details.

## Codes

This is the starter code for WDI projects. Please update this README file with information specific to your project. Replace this paragraph for instance, with a short description of your project. Then update the sections below. Refer to your project specificaion for instructions on how to submit your projects.

## Getting Started

Provide instructions here about how to get your project running on our local machine. Do we just need to clone and open a certain file or do we need to install anything first.

### Prerequisites

What is needed to install and run the project, how do we install them

```
Code example
```

### How to Use

A step by step guide on how to install and use the project, for example if this is a game, how do we play it.


```
Code example
```

More steps...

```
until finished
```


## Tests

Did you write automated tests? If so, how do we run them.


```
Code example
```

## Live Version

Where is this deployed online (github pages, heroku etc), give us the link and any access details we need.
HEROKU : https://artycraftycourses.herokuapp.com/

## Built With
GITHUB : https://github.com/sillyadventures/project-2

What did you use to build it, list the technologies, plugins, gems, packages etc.
## Built With

* [jQuery](http://jquery.com/) - jQuery for example is something you likely used
* [Materalize](http://materializecss.com/)
* [jQuery](http://jquery.com/)
* [herokuapp](https://www.heroku.com/)
* [Robo 3T](https://robomongo.org/)
* [mlab](https://mlab.com/)
* [google maps API](https://developers.google.com/maps/)
* [Unsplash (images)](https://unsplash.com/)
* [handlebars](http://handlebarsjs.com/)

## Workflow

Did you write user stories, draw wireframes, use task tracking, produce ERDs? Did you use source control, with regular commits? Include links to them here.

## Authors
![ERD](/public/assets/readmeimages/erdflow.png "ERD")
![site flow](/public/assets/readmeimages/siteflow.png "site")

Did you collaborate with others on this project, list them here

* **John McClain** - *Responsible for keeping vests white* - [GithubUserName](https://github.com/GithubUserName)

## Acknowledgments

* Hat tip to anyone who's code was used, for example [this was a useful starting point for creating this template](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2).

* Little Hazel
* Superman Joseph
* Einstein Soh Min
* Old man William
* Teaching Assistant Master Alex Min
58 changes: 58 additions & 0 deletions config/ppConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const passport = require('passport')
const LocalStrategy = require('passport-local').Strategy
const User = require('../models/user')
const Student = require('../models/student')

passport.serializeUser((user, next) => {
next(null, user.id) // this user with specific id. has logged in before
})

passport.deserializeUser((id, next) => {
User.findById(id, function (err, admin) {
// console.log('deserializeUser user :', admin)
if (admin) next(err, admin)
})
Student.findById(id, function (err, student) {
// console.log('deserializeUser user :', student)
if (student) next(err, student)
})
})

passport.use(new LocalStrategy({
usernameField: 'user[email]',
passwordField: 'user[password]',
passReqToCallback: true
}, (req, email, password, next) => {
const Collection = req.body.user.type === 'admin' ? User : Student

Collection.findOne({email: email})
.then(user => {
if (!user) return next(null, false)
user.validPassword(password, (err, isMatch) => {
if (err) return next(err)
if (isMatch) return next(null, user)
return next(null, false, { message: 'mismatched'})
})
})
.catch(err => next(err))
}))

// passport.use(new LocalStrategy({
// usernameField: 'student[email]',
// passwordField: 'student[password]'
// }, (email, password, next) => {
// console.log(email, password)
// Student.findOne({email: email})
// .then(student => {
// console.log(student)
// if (!student) return next(null, false)
// student.validPassword(password, (err, isMatch) => {
// if (err) return next(err)
// if (isMatch) return next (null, student)
// return next(null, false, { message: 'mismatched'})
// })
// })
// .catch(err => next(err))
// }))

module.exports = passport
1 change: 1 addition & 0 deletions express-geocode-maps-example
Submodule express-geocode-maps-example added at 5c7704
39 changes: 39 additions & 0 deletions helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const isLoggedIn = (req, res, next) => {
if (req.user) {
res.redirect('/')
} else {
next()
}
}

// the opposite of the function above
const hasLoggedOut = (req, res, next) => {
if (req.user) {
next()
} else {
res.redirect('/')
}
}

const Logged = (req, res, next) => {
if (req.student) {
res.redirect('/')
} else {
next()
}
}

const LoggedOut = (req, res, next) => {
if (req.student) {
next()
} else {
res.redirect('/')
}
}

module.exports = {
hasLoggedOut,
isLoggedIn,
Logged,
LoggedOut
}
117 changes: 117 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
require('dotenv').config({silent: true})

const dbUrl = process.env.NODE_ENV === 'production' ? process.env.MONGODB_URI : 'mongodb://localhost/projecttwo'
const port = process.env.PORT || 5000 // this is for our express server

const express = require('express')
const path = require('path')
const mongoose = require('mongoose')
const exphbs = require('express-handlebars')
const bodyParser = require('body-parser')
const methodOverride = require('method-override')
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const passport = require('./config/ppConfig')
const { hasLoggedOut, isLoggedIn } = require('./helpers')
const { LoggedOut, Logged } = require('./helpers')

const User = require('./models/user')
const Course = require('./models/course')
const Student = require('./models/student')
const Review = require('./models/review')

const login_routes = require('./routes/login_routes')
const register_routes = require('./routes/register_routes')
const classes_routes = require('./routes/classes_routes')
const pending_routes = require('./routes/pending_routes')
const show_routes = require('./routes/show_routes')
const course_routes = require('./routes/course_routes')
const student_register_routes = require('./routes/student_register_routes')
const student_login_routes = require('./routes/student_login_routes')
const student_show_routes = require('./routes/student_show_routes')
const course_update_routes = require('./routes/course_update_routes')

const app = express()

app.engine('handlebars', exphbs({ defaultLayout: 'main'}))
app.set('view engine', 'handlebars')

app.use(express.static(path.join(__dirname, 'public')))
app.use(function (req, res, next) {
console.log('Method: ' + req.method + ' Path: ' + req.url)
next()
})

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}))

app.use(methodOverride('_method'))

mongoose.Promise = global.Promise
mongoose.connect(dbUrl, {

useMongoClient: true
})
.then(
() => { console.log('db is connected') },
(err) => { console.log(err) }
)

app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true,
store: new MongoStore({ mongooseConnection: mongoose.connection })
}))

app.use(passport.initialize())
app.use(passport.session())

app.use((req, res, next) => {
app.locals.user = req.user
app.locals.course = req.course
app.locals.student = req.student
if (req.user) {
app.locals.admin = req.user.type === 'admin' ? req.user : null
}
next()
})

app.get('/', (req, res) => {
res.render('courses/home')
})

app.get('/profile', hasLoggedOut, (req, res) => {
res.send(req.user)
})

app.get('/logout', hasLoggedOut, (req, res) => {
req.logout()
res.redirect('/')
})

app.get('/profile', LoggedOut, (req, res) => {
res.send(req.student)
})

app.get('/logout', LoggedOut, (req, res) => {
req.logout()
res.redirect('/')
})

app.use('/courseupdate', course_update_routes)
app.use('/studentshow', student_show_routes)
app.use('/studentlogin', student_login_routes)
app.use('/studentregister', student_register_routes)
app.use('/course', course_routes)
app.use('/pending', pending_routes)
app.use('/classes', classes_routes)
app.use('/show', show_routes)
app.use('/register', isLoggedIn, register_routes)
app.use('/login', isLoggedIn, login_routes)

app.listen(port, () => {
console.log(`Server is running on ${port}`)
})
23 changes: 23 additions & 0 deletions models/course.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const User = require('../models/user')

const courseSchema = new Schema({
google: String,
name: String,
description: String,
currentStudents: Number,
duration: String,
date: String,
time: String,
price: String,
teacher: {
type: Schema.Types.ObjectId,
ref: 'User'
},
slug: String
})

const Course = mongoose.model('Course', courseSchema)

module.exports = Course
Loading