Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DevendraThakare committed Oct 17, 2015
1 parent 82e0954 commit 0aceea4
Show file tree
Hide file tree
Showing 58 changed files with 906 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.pyc
*.pyc
login/node_modules
.DS_Store
**/.DS_Store
Binary file added login/._.DS_Store
Binary file not shown.
Binary file added login/._gulpfile.js
Binary file not shown.
Binary file added login/._sockets.js
Binary file not shown.
75 changes: 75 additions & 0 deletions login/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var dbConfig = require('./config/db.js');
var mongoose = require('mongoose');
var expressSession = require('express-session');
var passport = require('passport');

var routes = require('./routes/index');
var users = require('./routes/users');
var panel = require('./routes/panel');
var app = express();
app.io = require( "socket.io" )();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

mongoose.connect(dbConfig.url);
require('./config/passport')(passport);

app.use(passport.initialize());
app.use(passport.session());
app.use(expressSession({secret: 'mySecretKey'}));

require('./routes/routes.js')(app, passport);

app.use('/', routes);
app.use('/users', users);
app.use('/panel', panel);


// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});

module.exports = app;
Binary file added login/app/models/._user.js
Binary file not shown.
22 changes: 22 additions & 0 deletions login/app/models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var mongoose = require('mongoose');

module.exports = mongoose.model('User',{
facebook : {
id : String,
token : String,
name : String,
gender : String,
email : String,
profile_pic_url: String,
birthday: String
},
google : {
id : String,
token : String,
name : String,
gender : String,
email : String,
profile_pic_url: String,
birthday: String
}
});
Binary file added login/assets/css/._style.less
Binary file not shown.
18 changes: 18 additions & 0 deletions login/assets/css/style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

@tab-height: 48px;
.main-header, #create-survey .mdl-layout__tab-bar{
height: @tab-height;
min-height: @tab-height;
}
.logo{
pointer-events: none;
}
#create-survey{
.mdl-layout__tab-bar{
background-color: transparent;
}
.mdl-layout__tab{
color: #000;
}

}
Binary file added login/assets/js/._main.js.coffee
Binary file not shown.
3 changes: 3 additions & 0 deletions login/assets/js/main.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(document).ready(function(){
console.log('ready');
})
93 changes: 93 additions & 0 deletions login/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('login:server');
var http = require('http');
var sockets = require('../sockets');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

app.io.attach( server );
sockets.init(app.io);
/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
Binary file added login/config/._application.js
Binary file not shown.
Binary file added login/config/._auth.js
Binary file not shown.
Binary file added login/config/._db.js
Binary file not shown.
Binary file added login/config/._passport.js
Binary file not shown.
3 changes: 3 additions & 0 deletions login/config/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'api_base_url' : 'http://10.1.11.3:8090/'
}
14 changes: 14 additions & 0 deletions login/config/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {

'facebookAuth' : {
'clientID' : '1659265230957893', // your App ID
'clientSecret' : '8c0d1ecd678fce3a76b335bc249568c3', // your App Secret
'callbackURL' : 'http://devendravm.housing.com:3000/auth/facebook/callback'
},

'googleAuth' : {
'clientID' : '791478099215-nlc92i01idum8r44na3rbdk8vp11sm9l.apps.googleusercontent.com',
'clientSecret' : 'Ghn_d6L4XbuGCcd4B3qxzNz6',
'callbackURL' : 'http://devendravm.housing.com:3000/auth/facebook/callback'
}
};
3 changes: 3 additions & 0 deletions login/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'url' : 'mongodb://localhost/passport'
}
81 changes: 81 additions & 0 deletions login/config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
var configAuth = require('./auth.js');
var FacebookStrategy = require('passport-facebook').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuthStrategy;
var User = require('../app/models/user');
var request = require('request');
var appConfig =require('../config/application');


module.exports = function(passport) {

passport.serializeUser(function(user, done) {
done(null, user.id);
});

// used to deserialize the user
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});

passport.use(new FacebookStrategy({
clientID : configAuth.facebookAuth.clientID,
clientSecret : configAuth.facebookAuth.clientSecret,
callbackURL : configAuth.facebookAuth.callbackURL,
profileFields : ['id', 'displayName', 'gender','picture.type(large)', 'email', 'birthday', 'about']
},

function(token, refreshToken, profile, done) {
process.nextTick(function() {
User.findOne({ 'facebook.id' : profile.id }, function(err, user) {

// if there is an error, stop everything and return that
// ie an error connecting to the database
if (err)
return done(err);

// if the user is found, then log them in
if (user) {
return done(null, user); // user found, return that user
} else {
// if there is no user found with that facebook id, create them
var newUser = new User();
// set all of the facebook information in our user model
data = profile._json
newUser.facebook.token = token; // we will save the token that facebook provides to the user
newUser.facebook.id = data.id; // set the users facebook id
newUser.facebook.gender= data.gender
newUser.facebook.name = data.name; // look at the passport user profile to see how names are returned
if(data.email)
newUser.facebook.email = data.email; // facebook can return multiple emails so we'll take the first
if(data.picture)
newUser.facebook.profile_pic_url = data.picture.data.url;
if(data.birthday)
newUser.facebook.birthday = data.birthday

// save our user to the database
newUser.save(function(err) {
if (err)
throw err;
request.post(appConfig.api_base_url+'fetch_user_profile').form(newUser.toJSON().facebook);
// if successful, return the new user
return done(null, newUser);
});
}
});
});

}));

passport.use(new GoogleStrategy({
consumerKey: configAuth.googleAuth.clientID,
consumerSecret: configAuth.googleAuth.clientSecret,
callbackURL: configAuth.googleAuth.callbackURL
},
function(token, refreshToken, profile, done) {
process.nextTick(function() {
});

}));
};
Binary file added login/gulp/._changed-less.js
Binary file not shown.
Binary file added login/gulp/._gulp-css.js
Binary file not shown.
Loading

0 comments on commit 0aceea4

Please sign in to comment.