'use strict';

var express = require('express');
var flash = require('connect-flash');
var kraken = require('kraken-js');
var db = require('./lib/db');
var crypto = require('./lib/crypto');

var session = require('express-session'); //Run -> npm install
var easySession = require('easy-session'); //Run -> npm install
var passport = require('passport');

var signUpStrategy= require('./lib/registration');
var signInStrategy = require('./lib/login');
var access_rights = require('./lib/ac');

var options, app;

/*
 * Create and configure application. Also exports application instance for use by tests.
 * See https://github.com/krakenjs/kraken-js#options for additional configuration options.
 */


options = function spec(app){
	
	app.on('middleware:after:session', function configPassport(eventargs){
		
		app.use(easySession.main(session,{
			ipCheck: true,
			uaCheck: true,
			rbace: access_rights
		}));
		
		//
		signUpStrategy(passport); 
		signInStrategy(passport);
		
		//
		app.use(passport.initialize());
		app.use(passport.session());
		app.use(flash());
		
		//
		app.use(function(req, res, next) {
		  res.locals.messages = req.flash();
		  next();
		});
		
	});
	
	return {
	    onconfig: function (config, next) {
	        /*
	         * Add any additional config setup or overrides here. `config` is an initialized
	         * `confit` (https://github.com/krakenjs/confit/) configuration object.
	         */
		
		
			db.config(config.get('databaseConfig'));
			var cryptConfig = config.get('bcrypt');
			crypto.setCryptoLevel(cryptConfig.difficulty);
		

			next(null, config);
	    }
	};
    
};

app = module.exports = express();

app.use(kraken(options));

app.on('start', function () {
    console.log('Application ready to serve requests.');
    console.log('Environment: %s', app.kraken.get('env:env'));
});

@@ -46,46 +46,8 @@
 ');%0A
-var flash = require('connect-flash');%0A
 var 
@@ -187,37 +187,16 @@
 ssion');
- //Run -%3E npm install
 %0Avar eas
@@ -234,29 +234,8 @@
 n');
- //Run -%3E npm install
 %0Avar
@@ -266,16 +266,54 @@
 sport');
+%0Avar flash = require('connect-flash');
 %0A%0Avar si
@@ -408,27 +408,16 @@
 ;%0Avar ac
-cess_rights
  = requi
@@ -746,17 +746,18 @@
 args)%7B%0A%09
-%09
+/*
 %0A%09%09app.u
@@ -784,16 +784,17 @@
 session,
+ 
 %7B%0A%09%09%09ipC
@@ -839,19 +839,8 @@
 : ac
-cess_rights
 %0A%09%09%7D
@@ -840,25 +840,26 @@
  ac%0A%09%09%7D));%0A%09
-%09
+*/
 %0A%09%09//%0A%09%09sign
@@ -1001,24 +1001,122 @@
 lash());%0A%09%09%0A
+%09%09app.use(easySession.main(session, %7B%0A%09%09%09ipCheck: true,%0A%09%09%09uaCheck: true,%0A%09%09%09rbac: ac%0A%09%09%7D));%0A%09%09%0A%09%0A
 %09%09//%0A%09%09app.u
@@ -1203,17 +1203,16 @@
 %0A%09%09%7D);%0A%09
-%09
 %0A%09%7D);%0A%09%0A
@@ -1461,19 +1461,16 @@
   */%0A%09%09%0A
-%09%09%0A
 %09%09%09db.co
@@ -1702,16 +1702,21 @@
 (options
+(app)
 ));%0A%0Aapp

Add session object and access control rights.