From bf831540665eb8c6bf62470c49eb1be01f31fd8d Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Wed, 13 Nov 2013 16:13:31 -0500 Subject: [PATCH] removed middleware and passport --- public/index-async.html | 58 ------------ server.js | 203 +--------------------------------------- 2 files changed, 1 insertion(+), 260 deletions(-) delete mode 100755 public/index-async.html diff --git a/public/index-async.html b/public/index-async.html deleted file mode 100755 index fd3913a4f3f..00000000000 --- a/public/index-async.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - My AngularJS App - - - - - -
- -
Angular seed app: v
- - - diff --git a/server.js b/server.js index fc173186456..281061b7ed2 100755 --- a/server.js +++ b/server.js @@ -1,211 +1,10 @@ var express = require('express'), mongoose = require('mongoose'), fs = require('fs'), - config = require('./conf'), - passport = require('passport'); + config = require('./conf'); -/** - * Generic require login routing middleware - */ -var requiresLogin = function(req, res, next) { - if (!req.isAuthenticated()) { - return res.send(401, 'User is not authorized'); - } - next(); -}; -/** - * User authorizations routing middleware - */ -var hasAuthorization = function(req, res, next) { - if (req.profile.id != req.user.id) { - return res.send(401, 'User is not authorized'); - } - next(); -}; - -/** - * Article authorizations routing middleware - */ -var hasAuthorization = function(req, res, next) { - if (req.article.user.id != req.user.id) { - return res.send(401, 'User is not authorized'); - } - next(); -}; - -//Bootstrap db connection var db = mongoose.connect(config.db); - -/** - * 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: { - type: String, - unique: true - }, - 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); - -/** - * Article Schema - */ -var ArticleSchema = new Schema({ - created: { - type: Date, - default: Date.now - }, - title: { - type: String, - default: '', - trim: true - }, - content: { - type: String, - default: '', - trim: true - }, - user: { - type: Schema.ObjectId, - ref: 'User' - } -}); - -/** - * Validations - */ -ArticleSchema.path('title').validate(function(title) { - return title.length; -}, 'Title cannot be blank'); - -/** - * Statics - */ -ArticleSchema.statics = { - load: function(id, cb) { - this.findOne({ - _id: id - }).populate('user', 'name username').exec(cb); - } -}; - -mongoose.model('Article', ArticleSchema); - var app = express();