Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ config.js
public/lib
.c9revisions
.settings
public/css/*
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/cloud9hub.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/libraries/cloud9hub_node_modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

742 changes: 742 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"topcoat": "~0.8.0",
"angular-route": "~1.2.15",
"fontawesome": "~4.0.3",
"flat-ui-official": "~2.1.3"
"flat-ui": "latest"
}
}
21 changes: 21 additions & 0 deletions config/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

/**
* Route middleware to ensure user is authenticated.
*/
exports.ensureAuthenticated = function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
res.send(401);
}

/**
* Blog authorizations routing middleware
*/
exports.blog = {
hasAuthorization: function(req, res, next) {
if (req.blog.creator._id.toString() !== req.user._id.toString()) {
return res.send(403);
}
next();
}
};
File renamed without changes.
9 changes: 9 additions & 0 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Created by sreekanth on 1/3/15.
*/
// config/database.js
module.exports = {

'url': 'mongodb://localhost/autherization' // looks like mongodb://<user>:<pass>@mongo.onmodulus.net:27017/Mikha4ot

};
24 changes: 24 additions & 0 deletions config/pass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// config/auth.js

// expose our config directly to our application using module.exports
module.exports = {

'facebookAuth' : {
'clientID' : '1511163462453285', // your App ID
'clientSecret' : 'a469ebd9b3ee882cd1578d26ee91b491', // your App Secret
'callbackURL' : 'http://localhost:8080/auth/facebook/callback'
},

'twitterAuth' : {
'consumerKey' : 'I9YLv8c0FJIYPACU5eYGRbcGW',
'consumerSecret' : 'j9330GuivKIuwC3c8r3RfRNLycrDyZ2OfHFQEGW4h2zrLkdElY',
'callbackURL' : 'http://localhost:8080/auth/twitter/callback'
},

'googleAuth' : {
'clientID' : '233449258545-tura73svarjsatjmc13v4q6oojqknhbg.apps.googleusercontent.com',
'clientSecret' : 'Gmt7k6MzSWJ3ZSANiqU7OCAG',
'callbackURL' : 'http://localhost:8080/auth/google/callback'
}

};
111 changes: 111 additions & 0 deletions config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* Created by sreekanth on 1/3/15.
*/
// load all the things we need
var LocalStrategy = require('passport-local').Strategy;
// load up the user model
var User = require('../models/user');

// load the auth variables
var configAuth = require('./auth'); // use this one for testing

module.exports = function(passport) {

// =========================================================================
// LOCAL LOGIN =============================================================
// =========================================================================
passport.use('local-login', new LocalStrategy({
// by default, local strategy uses username and password, we will override with email
usernameField : 'email',
passwordField : 'password',
passReqToCallback : true // allows us to pass in the req from our route (lets us check if a user is logged in or not)
},
function(req, email, password, done) {
if (email)
email = email.toLowerCase(); // Use lower-case e-mails to avoid case-sensitive e-mail matching

// asynchronous
process.nextTick(function() {
User.findOne({ 'local.email' : email }, function(err, user) {
// if there are any errors, return the error
if (err)
return done(err);

// if no user is found, return the message
if (!user)
return done(null, false, req.flash('loginMessage', 'No user found.'));

if (!user.validPassword(password))
return done(null, false, req.flash('loginMessage', 'Oops! Wrong password.'));

// all is well, return user
else
return done(null, user);
});
});

}));

// =========================================================================
// LOCAL SIGNUP ============================================================
// =========================================================================
passport.use('local-signup', new LocalStrategy({
// by default, local strategy uses username and password, we will override with email
usernameField : 'email',
passwordField : 'password',
passReqToCallback : true // allows us to pass in the req from our route (lets us check if a user is logged in or not)
},
function(req, email, password, done) {
if (email)
email = email.toLowerCase(); // Use lower-case e-mails to avoid case-sensitive e-mail matching

// asynchronous
process.nextTick(function() {
// if the user is not already logged in:
if (!req.user) {
User.findOne({ 'local.email' : email }, function(err, user) {
// if there are any errors, return the error
if (err)
return done(err);

// check to see if theres already a user with that email
if (user) {
return done(null, false, req.flash('signupMessage', 'That email is already taken.'));
} else {

// create the user
var newUser = new User();

newUser.local.email = email;
newUser.local.password = newUser.generateHash(password);

newUser.save(function(err) {
if (err)
throw err;

return done(null, newUser);
});
}

});
// if the user is logged in but has no local account...
} else if ( !req.user.local.email ) {
// ...presumably they're trying to connect a local account
var user = req.user;
user.local.email = email;
user.local.password = user.generateHash(password);
user.save(function(err) {
if (err)
throw err;
return done(null, user);
});
} else {
// user is logged in and already has a local account. Ignore signup. (You should log out before trying to create a new account, user!)
return done(null, req.user);
}

});

}));
};

2 changes: 1 addition & 1 deletion controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
*/

exports.index = function(req, res){
res.render('index', { title: 'Express' });
res.render('index.html', { title: 'Express' });
};
Loading