Skip to content

Commit

Permalink
migrated from homegrown to passport.js authentication framewor, curre…
Browse files Browse the repository at this point in the history
…ntly with Local strategy
  • Loading branch information
cactus committed Mar 11, 2015
1 parent e3d346f commit f678dba
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 39 deletions.
66 changes: 49 additions & 17 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
var express = require('express');
var express = require('express')

var path = require('path');
var favicon = require('serve-favicon');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session')
var mongojs = require("mongojs");
var fs = require('fs')
var config = require('config');

var app = express();

// passport stuff
var passport = require('passport'),
LocalStrategy = require('passport-local');
var flash = require('connect-flash')



// routes
var routes = require('./routes/index');
var users = require('./routes/users');
var api = require('./routes/api');
Expand All @@ -17,21 +28,15 @@ var portfolio = require('./routes/portfolio');
var upload = require('./routes/upload');
var targets = require('./routes/targets');

var fs = require('fs')

// environment specific configurations
var config = require('config');


var config = require('config');
// db
var DB=config.database.db;
var HOST = config.database.host;
var connection_string = HOST+'/'+DB;
var db = mongojs(connection_string, [DB]);




// logger
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
Expand All @@ -43,13 +48,11 @@ logger.level='debug';

// load build number
var build = JSON.parse(fs.readFileSync('./space.build', 'utf8'));

if (config.env==="PRODUCTION") config.build=build.build;

var app = express();

// create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'})
//var accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'})

// view engine setup
app.set('views', path.join(__dirname, 'views'));
Expand All @@ -60,31 +63,56 @@ app.locals.title="s p a c e ";


// get all org instance dates for the menu
// ** this should go somewhere else ;-)
_getOrgDates(function(data){
app.locals.organizationDates=data;
console.log("** data: "+data);
});

app.use(favicon(path.join(__dirname,'public','images','favicon.ico')));
app.use(bodyParser.json());

// limit 50m is for large svg POST data needed for transcoder
app.use(bodyParser.urlencoded({ extended: false ,limit: '50mb'}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));


app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true
}))


app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash());


// http://thenitai.com/2013/11/25/how-to-access-sessions-in-jade-template/
app.use(function(req,res,next){
res.locals.session = req.session;
next();
});

// Session-persisted message middleware
app.use(function(req, res, next){
var err = req.session.error,
msg = req.session.notice,
success = req.session.success;

delete req.session.error;
delete req.session.success;
delete req.session.notice;

if (err) res.locals.error = err;
if (msg) res.locals.notice = msg;
if (success) res.locals.success = success;

next();
});


// get access to URL of running app
app.use(function(req, res, next) {
req.getBaseUrl = function() {
Expand All @@ -94,7 +122,6 @@ app.use(function(req, res, next) {
});



// adds config object to all responses
var addconfig = require('./services/middleware/addconfig.js');
app.use(addconfig());
Expand All @@ -104,6 +131,8 @@ logger.info(path.join(__dirname,'public','images','favicon.ico'));
logger.debug("[CONFIG] "+JSON.stringify(config));



// should also go into some service class
// schedule v1sync
var schedule = require('node-schedule');
var rule = new schedule.RecurrenceRule();
Expand All @@ -119,6 +148,7 @@ if (config.v1.syncEpics.mode!="off"){
}



app.use('/', routes);
app.use('/api', api);
app.use('/org', org);
Expand All @@ -130,7 +160,6 @@ app.use('/targets', targets);




// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
Expand All @@ -157,7 +186,6 @@ if (app.get('env') === 'development') {
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {

logger.error(err.status+" "+err.messag);

res.status(err.status || 500);
Expand All @@ -168,6 +196,8 @@ app.use(function(err, req, res, next) {
});




/**
* organization snapsho dates
* => should be moved in a service class ;-)
Expand Down Expand Up @@ -203,4 +233,6 @@ function _syncV1(url){
});
}



module.exports = app;
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
},
"dependencies": {
"app-root-path": "^1.0.0",
"bcryptjs": "^2.1.0",
"body-parser": "~1.10.1",
"config": "^1.10.0",
"connect-flash": "^0.1.1",
"cookie-parser": "~1.3.3",
"cookie-session": "^1.1.0",
"debug": "~2.1.1",
"emailjs": "~0.3.12",
"excel-export": "0.3.11",
Expand All @@ -22,15 +25,17 @@
"jsondiffpatch": "*",
"lodash": "^3.1.0",
"moment": "^2.9.0",
"moment-duration-format": "^1.3.0",
"mongodb": "~2.0",
"mongojs": "*",
"morgan": "~1.5.1",
"multer": "~0.1.6",
"node-rest-client": "^1.4.4",
"node-schedule": "^0.1.15",
"npmlog": "^1.0.0",
"passport": "^0.2.1",
"passport-local": "^1.0.0",
"phantom": "^0.7.2",
"q": "^1.2.0",
"serve-favicon": "~2.2.0",
"sha1": "*",
"tablesorter": "^2.20.1",
Expand Down
15 changes: 15 additions & 0 deletions public/javascripts/kanban/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function getConfig(collection){
case "organization/2015-02-17": return getOrganizationConfig();
case "productcatalog": return getProductCatalogConfig();
case "roadmaps": return getRoadmapConfig();
case "availability": return getAvailabilityConfig();

}
}
Expand Down Expand Up @@ -180,6 +181,20 @@ function getProductCatalogConfig(){
}


function getAvailabilityConfig(){
var _availability = [
{ id:"id", name: "id", field: "_id",sortable:true,cssClass:"onKanbanImmutable" },
{ id: "year", name: "year", field: "year",sortable:true, cssClass: "cell-standard" },
{ id: "week", name: "week", field: "week" ,width:200,sortable:true, editor: Slick.Editors.Text, cssClass: "cell-standard"},
{ id: "unplannedYTD", name: "unplannedYTD", field: "unplannedYTD" ,sortable:true,width:200, editor: Slick.Editors.Text, cssClass: "cell-standard"},
{ id: "plannedYTD", name: "plannedYTD", field: "plannedYTD",sortable:true,width:200, editor: Slick.Editors.Text, cssClass: "cell-standard" },
{ id: "totalYTD", name: "totalYTD", field: "totalYTD",width:200,sortable:true,editor:Slick.Editors.Text, cssClass: "cell-standard"}];
var _config ={};
_config.mode="editable";
_config.fields = _availability;
return _config;
}

function getBoardConfig(){
//lanetext
var _boards = [
Expand Down
26 changes: 24 additions & 2 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var PATH = {
REST_COMPETITORS : BASE+'/space/rest/competitors',
REST_PRODUCTCATALOG : BASE+'/space/rest/productcatalog',
REST_ROADMAPS : BASE+'/space/rest/roadmaps',

REST_AVAILABILITY : BASE+'/space/rest/availability',

REST_INITIATIVES_DIFF_TRAIL : BASE+'/space/rest/initiatives_diff_trail',
REST_ORGANIZATION : BASE+'/space/rest/organization/:date',
Expand All @@ -73,7 +73,7 @@ var PATH = {
EXPORT_ORGANIZATION : BASE+'/space/export/xlsx/organization',
EXPORT_PRODUCTCATALOG : BASE+'/space/export/xlsx/productcatalog',
EXPORT_ROADMAPS : BASE+'/space/export/xlsx/roadmaps',

EXPORT_AVAILABILITY : BASE+'/space/export/xlsx/availability',



Expand Down Expand Up @@ -137,6 +137,11 @@ router.get(PATH.REST_ROADMAPS, function(req, res, next) {findAllByName(req,res,n
router.post(PATH.REST_ROADMAPS, function(req, res, next) {save(req,res,next); });
router.delete(PATH.REST_ROADMAPS, function(req, res, next) {remove(req,res,next); });

router.get(PATH.REST_AVAILABILITY, function(req, res, next) {findAllByName(req,res,next);});
router.post(PATH.REST_AVAILABILITY, function(req, res, next) {save(req,res,next); });
router.delete(PATH.REST_AVAILABILITY, function(req, res, next) {remove(req,res,next); });


router.post(PATH.REST_MAIL, function(req, res, next) {mail(req,res,next); });


Expand Down Expand Up @@ -762,6 +767,23 @@ function excelLabels(req, res , next){
_generateAndSendExcel("labels",conf,req,res,next);
}

/**
* generate availability excel
*/
function excelAvailability(req, res , next){
var conf ={};
conf.stylesXmlFile = "views/excel_export/styles.xml";
conf.cols = [
{caption:'_id',type:'string',width:20,captionStyleIndex:2,beforeCellWrite:_formatCell},
{caption:'year',type:'string',width:20,captionStyleIndex:2,beforeCellWrite:_formatCell},
{caption:'week',type:'string',width:20,captionStyleIndex:2,beforeCellWrite:_formatCell},
{caption:'unplannedYTD',type:'string',width:20,captionStyleIndex:2,beforeCellWrite:_formatCell},
{caption:'plannedYTD',type:'string',width:20,captionStyleIndex:2,beforeCellWrite:_formatCell},
{caption:'totalYTD',type:'string',width:20,captionStyleIndex:2,beforeCellWrite:_formatCell}
];

_generateAndSendExcel("availability",conf,req,res,next);
}


/**
Expand Down
Loading

0 comments on commit f678dba

Please sign in to comment.