// redirect to "/app" on home route router.all('/', common.checkLogin, function (req, res, next){ res.redirect(req.app_context + '/app/'); });
// Pagination redirect to page 1 router.get('/app/:conn/:db/:coll/view/', function (req, res, next){ res.redirect(req.app_context + '/app/' + req.params.conn + '/' + req.params.db + '/' + req.params.coll + '/view/1'); });
// login page router.get('/app/login', function (req, res, next){ var passwordConf = req.nconf.app.get('app'); // if password is set then render the login page, else continue if(passwordConf && passwordConf.hasOwnProperty('password')){ res.render('login', { message: '', helpers: req.handlebars.helpers }); }else{ res.redirect(req.app_context + '/'); } });
// the home route router.get('/app/', function (req, res, next){ var connection_list = req.nconf.connections.get('connections'); if(connection_list){ if(Object.keys(connection_list).length > 0){ // we have a connection and redirect to the first var first_conn = Object.keys(connection_list)[0]; res.redirect(req.app_context + '/app/' + first_conn); return; } } // if no connections, go to connection setup res.redirect(req.app_context + '/app/connection_list'); return; });
// login page router.post('/app/login_action', function (req, res, next){ var passwordConf = req.nconf.app.get('app'); if(passwordConf && passwordConf.hasOwnProperty('password')){ if(req.body.inputPassword === passwordConf.password){ // password is ok, go to home req.session.loggedIn = true; res.redirect(req.app_context + '/'); }else{ // password is wrong. Show login form with a message res.render('login', { message: 'Password is incorrect', helpers: req.handlebars.helpers }); } }else{ res.redirect(req.app_context + '/'); } });
res.redirect(req.app_context + '/app'); return; res.redirect(req.app_context + '/app/' + req.params.conn + '/' + uri.database); return;
// logout router.get('/app/logout', function (req, res, next){ req.session.loggedIn = null; res.redirect(req.app_context + '/app'); });
// Pagination redirect to page 1 router.get('/app/:conn/:db/:coll/', function (req, res, next){ res.redirect(req.app_context + '/app/' + req.params.conn + '/' + req.params.db + '/' + req.params.coll + '/view/1'); });