This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
1,628 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: ./node_modules/.bin/forever -m 5 server.js |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var mongoose = require('mongoose') | ||
, async = require('async') | ||
, _ = require('underscore') | ||
|
||
|
||
exports.render = function(req, res){ | ||
res.render('index', { | ||
user: req.user ? JSON.stringify(req.user) : "null" | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var mongoose = require('mongoose') | ||
, User = mongoose.model('User') | ||
|
||
//exports.signin = function (req, res) {} | ||
|
||
/** | ||
* Auth callback | ||
*/ | ||
|
||
exports.authCallback = function (req, res, next) { | ||
res.redirect('/') | ||
} | ||
|
||
/** | ||
* Show login form | ||
*/ | ||
|
||
exports.signin = function (req, res) { | ||
res.render('users/signin', { | ||
title: 'Signin', | ||
message: req.flash('error') | ||
}) | ||
} | ||
|
||
/** | ||
* Show sign up form | ||
*/ | ||
|
||
exports.signup = function (req, res) { | ||
res.render('users/signup', { | ||
title: 'Sign up', | ||
user: new User() | ||
}) | ||
} | ||
|
||
/** | ||
* Logout | ||
*/ | ||
|
||
exports.signout = function (req, res) { | ||
req.logout() | ||
res.redirect('/') | ||
} | ||
|
||
/** | ||
* Session | ||
*/ | ||
|
||
exports.session = function (req, res) { | ||
res.redirect('/') | ||
} | ||
|
||
/** | ||
* Create user | ||
*/ | ||
|
||
exports.create = function (req, res) { | ||
var user = new User(req.body) | ||
user.provider = 'local' | ||
user.save(function (err) { | ||
if (err) { | ||
return res.render('users/signup', { errors: err.errors, user: user }) | ||
} | ||
req.logIn(user, function(err) { | ||
if (err) return next(err) | ||
return res.redirect('/') | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* Show profile | ||
*/ | ||
|
||
exports.show = function (req, res) { | ||
var user = req.profile | ||
res.render('users/show', { | ||
title: user.name, | ||
user: user | ||
}) | ||
} | ||
|
||
exports.me = function (req, res) { | ||
res.jsonp(req.user || null); | ||
} | ||
|
||
/** | ||
* Find user by id | ||
*/ | ||
|
||
exports.user = function (req, res, next, id) { | ||
User | ||
.findOne({ _id : id }) | ||
.exec(function (err, user) { | ||
if (err) return next(err) | ||
if (!user) return next(new Error('Failed to load User ' + id)) | ||
req.profile = user | ||
next() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var mongoose = require('mongoose') | ||
, Notifier = require('notifier') | ||
, env = process.env.NODE_ENV || 'development' | ||
, config = require('../../config/config')[env] | ||
|
||
/** | ||
* Notification methods | ||
*/ | ||
|
||
var Notify = { | ||
|
||
/** | ||
* Comment notification | ||
* | ||
* @param {Object} options | ||
* @param {Function} cb | ||
* @api public | ||
*/ | ||
|
||
comment: function (options, cb) { | ||
var article = options.article | ||
var author = article.user | ||
var user = options.currentUser | ||
var notifier = new Notifier(config.notifier) | ||
|
||
var obj = { | ||
to: author.email, | ||
from: '[email protected]', | ||
subject: user.name + ' added a comment on your article ' + article.title, | ||
alert: user.name + ' says: "' + options.comment, | ||
locals: { | ||
to: author.name, | ||
from: user.name, | ||
body: options.comment, | ||
article: article.name | ||
} | ||
} | ||
|
||
// for apple push notifications | ||
/*notifier.use({ | ||
APN: true | ||
parseChannels: ['USER_' + author._id.toString()] | ||
})*/ | ||
|
||
notifier.send('comment', obj, cb) | ||
} | ||
} | ||
|
||
/** | ||
* Expose | ||
*/ | ||
|
||
module.exports = Notify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
p Hello #{to} | ||
|
||
p #{from} has added a comment "#{body}" on your article #{article} | ||
|
||
p Cheers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var mongoose = require('mongoose') | ||
, Schema = mongoose.Schema | ||
, crypto = require('crypto') | ||
, _ = require('underscore') | ||
, authTypes = ['github', 'twitter', 'facebook', 'google'] | ||
|
||
/** | ||
* User Schema | ||
*/ | ||
|
||
var UserSchema = new Schema({ | ||
name: String, | ||
email: String, | ||
username: String, | ||
provider: String, | ||
hashed_password: String, | ||
salt: String, | ||
facebook: {}, | ||
twitter: {}, | ||
github: {}, | ||
google: {} | ||
}) | ||
|
||
/** | ||
* Virtuals | ||
*/ | ||
|
||
UserSchema | ||
.virtual('password') | ||
.set(function(password) { | ||
this._password = password | ||
this.salt = this.makeSalt() | ||
this.hashed_password = this.encryptPassword(password) | ||
}) | ||
.get(function() { return this._password }) | ||
|
||
/** | ||
* Validations | ||
*/ | ||
|
||
var validatePresenceOf = function (value) { | ||
return value && value.length | ||
} | ||
|
||
// the below 4 validations only apply if you are signing up traditionally | ||
|
||
UserSchema.path('name').validate(function (name) { | ||
// if you are authenticating by any of the oauth strategies, don't validate | ||
if (authTypes.indexOf(this.provider) !== -1) return true | ||
return name.length | ||
}, 'Name cannot be blank') | ||
|
||
UserSchema.path('email').validate(function (email) { | ||
// if you are authenticating by any of the oauth strategies, don't validate | ||
if (authTypes.indexOf(this.provider) !== -1) return true | ||
return email.length | ||
}, 'Email cannot be blank') | ||
|
||
UserSchema.path('username').validate(function (username) { | ||
// if you are authenticating by any of the oauth strategies, don't validate | ||
if (authTypes.indexOf(this.provider) !== -1) return true | ||
return username.length | ||
}, 'Username cannot be blank') | ||
|
||
UserSchema.path('hashed_password').validate(function (hashed_password) { | ||
// if you are authenticating by any of the oauth strategies, don't validate | ||
if (authTypes.indexOf(this.provider) !== -1) return true | ||
return hashed_password.length | ||
}, 'Password cannot be blank') | ||
|
||
|
||
/** | ||
* Pre-save hook | ||
*/ | ||
|
||
UserSchema.pre('save', function(next) { | ||
if (!this.isNew) return next() | ||
|
||
if (!validatePresenceOf(this.password) | ||
&& authTypes.indexOf(this.provider) === -1) | ||
next(new Error('Invalid password')) | ||
else | ||
next() | ||
}) | ||
|
||
/** | ||
* Methods | ||
*/ | ||
|
||
UserSchema.methods = { | ||
|
||
/** | ||
* Authenticate - check if the passwords are the same | ||
* | ||
* @param {String} plainText | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
|
||
authenticate: function(plainText) { | ||
return this.encryptPassword(plainText) === this.hashed_password | ||
}, | ||
|
||
/** | ||
* Make salt | ||
* | ||
* @return {String} | ||
* @api public | ||
*/ | ||
|
||
makeSalt: function() { | ||
return Math.round((new Date().valueOf() * Math.random())) + '' | ||
}, | ||
|
||
/** | ||
* Encrypt password | ||
* | ||
* @param {String} password | ||
* @return {String} | ||
* @api public | ||
*/ | ||
|
||
encryptPassword: function(password) { | ||
if (!password) return '' | ||
return crypto.createHmac('sha1', this.salt).update(password).digest('hex') | ||
} | ||
} | ||
|
||
mongoose.model('User', UserSchema) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
extends layouts/default | ||
|
||
block main | ||
h1 Oops something went wrong | ||
br | ||
span 404 | ||
|
||
block content | ||
#error-message-box | ||
#error-stack-trace | ||
pre | ||
code!= error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
extends layouts/default | ||
|
||
block main | ||
h1 Oops something went wrong | ||
br | ||
span 500 | ||
|
||
block content | ||
#error-message-box | ||
#error-stack-trace | ||
pre | ||
code!= error |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js') | ||
|
||
script(type='text/javascript', src='js/lib/bootstrap.min.js') | ||
script(type='text/javascript', src='js/lib/angular.min.js') | ||
script(type='text/javascript', src='js/lib/angular-cookies.min.js') | ||
script(type='text/javascript', src='js/lib/angular-resource.min.js') | ||
|
||
script(type='text/javascript', src='js/app.js') | ||
script(type='text/javascript', src='js/config.js') | ||
script(type='text/javascript', src='js/directives.js') | ||
script(type='text/javascript', src='js/filters.js') | ||
|
||
script(type='text/javascript', src='js/services/global.js') | ||
|
||
script(type='text/javascript', src='js/controllers/index.js') | ||
script(type='text/javascript', src='js/controllers/header.js') | ||
script(type='text/javascript', src='js/init.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
head | ||
meta(charset='utf-8') | ||
meta(http-equiv='X-UA-Compatible', content='IE=edge,chrome=1') | ||
meta(name='viewport', content='width=device-width,initial-scale=1') | ||
|
||
title= appName+' - '+title | ||
meta(http-equiv='Content-type', content='text/html;charset=UTF-8') | ||
meta(name="keywords", content="node.js, express, mongoose, mongodb, angularjs") | ||
meta(name="description", content="MEAN - A Modern Stack: MongoDB, ExpressJS, AngularJS, NodeJS. (BONUS: Passport User Support).") | ||
|
||
link(href='/img/icons/favicon.ico', rel='shortcut icon', type='image/x-icon') | ||
|
||
meta(property='fb:app_id', content='APP_ID') | ||
meta(property='og:title', content='#{appName} - #{title}') | ||
meta(property='og:description', content='MEAN - A Modern Stack: MongoDB, ExpressJS, AngularJS, NodeJS. (BONUS: Passport User Support).') | ||
meta(property='og:type', content='website') | ||
meta(property='og:url', content='APP_URL') | ||
meta(property='og:image', content='APP_LOGO') | ||
meta(property='og:site_name', content='MEAN - A Modern Stack') | ||
meta(property='fb:admins', content='APP_ADMIN') | ||
|
||
link(rel='stylesheet', href='/css/lib/bootstrap.min.css') | ||
link(rel='stylesheet', href='/css/lib/bootstrap-responsive.min.css') | ||
link(rel='stylesheet', href='/css/common.css') | ||
|
||
link(rel='stylesheet', href='/css/views/index.css') | ||
|
||
//if lt IE 9 | ||
script(src='http://html5shim.googlecode.com/svn/trunk/html5.js') |
Oops, something went wrong.