Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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();
}
};
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 = {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

facbook, twitter, google may not be required.


'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' });
};
28 changes: 18 additions & 10 deletions controllers/workspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var fs = require('fs'),
_ = require('lodash'),
spawn = require('child_process').spawn;



var respondInvalidWorkspace = function(res) {
res.status(400);
res.json({msg: "Invalid workspace name"});
Expand Down Expand Up @@ -53,20 +55,26 @@ exports.create = function(req, res) {
* GET workspaces listing.
*/
exports.list = function(req, res){

console.log("User : " + req.user);
fs.readdir(__dirname + '/../workspaces/' + req.user, function(err, files) {
if(err) {
res.status(500);
res.json({error: err});
} else {
//console.log("Error in listing workspaces. Workspace Directory : " + __dirname + '/../workspaces/');

var workspaces = [];
for(var i=0; i< files.length; i++) {
// Skip hidden files
if(files[i][0] === '.') continue;

workspaces.push({name: files[i]})
if (files != null || files != undefined) {
for (var i = 0; i < files.length; i++) {
// Skip hidden files
if (files[i][0] === '.') continue;

workspaces.push({name: files[i]})
}
}
else {
workspaces.push({name: files[0]})
}
res.json({workspaces: workspaces});
}

});
};

Expand Down Expand Up @@ -146,7 +154,7 @@ exports.destroy = function(req, res) {

if(typeof req.app.get('runningWorkspaces')[req.user + '/' + workspaceName] === 'undefined'){
getNextAvailablePort(function(nextFreePort){
console.log("Starting " + __dirname + '/../../c9/bin/cloud9.sh for workspace ' + workspaceName + " on port " + nextFreePort);
console.log("Starting " + __dirname + ' together /../../c9/server.js for workspace ' + workspaceName + " on port " + nextFreePort);

var workspace = spawn(__dirname + '/../../c9/bin/cloud9.sh', ['-w', __dirname + '/../workspaces/' + req.user + '/' + workspaceName, '-l', '0.0.0.0', '-p', nextFreePort], {detached: true});
workspace.stderr.on('data', function (data) {
Expand Down
44 changes: 44 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// load the things we need
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');

// define the schema for our user model
var userSchema = mongoose.Schema({

local : {
email : String,
password : String,
},
facebook : {
id : String,
token : String,
email : String,
name : String
},
twitter : {
id : String,
token : String,
displayName : String,
username : String
},
google : {
id : String,
token : String,
email : String,
name : String
}

});

// generating a hash
userSchema.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};

// checking if password is valid
userSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
};

// create the model for users and expose it to our app
module.exports = mongoose.model('User', userSchema);
27 changes: 26 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@
"rimraf": "2.1.4",
"stylus": "*",
"swig": "^1.3.2",
"view-helpers": "^0.1.4"
"view-helpers": "^0.1.4",
"mongoose": "~3.5.5",
"ejs": "~0.8.4",
"underscore": "~1.5.2",
"mongoose" : "~3.8.1",
"passport" : "0.1.17",
"passport-local" : "~0.1.6",
"passport-github" : "0.1.5",
"connect-flash" : "~0.1.1",
"bcrypt-nodejs" : "latest",
"morgan": "~1.0.0",
"body-parser": "~1.0.0",
"cookie-parser": "~1.0.0",
"method-override": "~1.0.0",
"express-session": "~1.0.0",
"ejs-locals": "*",
"angular" : "*",
"foundation" : "*",
"jquery" : "*",
"bootstrap" : "*",
"consolidate": "^0.10.0",
"forever": "~0.10.11",
"jade": "*",
"lodash": "^2.4.1",
"connect-mongo": "~0.4.0"

}
}
Binary file added public/images/pcb-small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('c9hub', ['workspace', 'ngRoute']).config(function($routeProvider) {
$routeProvider.when('/', {templateUrl: "/partials/login.html"});
$routeProvider.when('/', {templateUrl: "/partials/login.ejs"});
$routeProvider.when('/dashboard', {controller: WorkspaceCtrl, templateUrl: "/partials/workspace.html"});
});
Loading