UNPKG

kaizen-login

Version:

A default login using express and mongoose

49 lines (42 loc) 1.8 kB
var express = require('express'); var bodyParser = require('body-parser'); var cookieParser = require('cookie-parser'); var expressLayouts = require('express-ejs-layouts'); var authenticationCookie = require("../middleware/authenticationCookie"); var UserController = require('../controller/userPresentation'); var UserApplication = function() { this.application = express(); } UserApplication.prototype.getApplication = function() { this.setDependencyCollection(); this.application.on('mount', this.handleMount.bind(this)); return this.application; } UserApplication.prototype.setDependencyCollection = function() { this.application.set('view engine', 'ejs'); this.application.use(bodyParser.urlencoded({extended: true})); this.application.use(cookieParser()); this.application.use(authenticationCookie); this.application.use(expressLayouts); } UserApplication.prototype.handleMount = function handleMount(parent) { console.log('Login mounted on ' + this.application.mountpath); this.userPresentation = this.instantiateUserController(this.application.mountpath); this.setRouteCollection(); } UserApplication.prototype.setRouteCollection = function() { this.application.get('/', this.userPresentation.getLoginPage.bind(this.userPresentation)); this.application.get('/new', this.userPresentation.getCreatePage.bind(this.userPresentation)); this.application.post('/new', this.userPresentation.create.bind(this.userPresentation)); this.application.post('/', this.userPresentation.login.bind(this.userPresentation)); } UserApplication.prototype.instantiateUserController = function(mountPath) { return new UserController(this.application.mountpath); } module.exports = UserApplication;