Skip to content

Commit

Permalink
Some added on menu permission, message for unavailable site in networ…
Browse files Browse the repository at this point in the history
…k and other
  • Loading branch information
anddimario committed Feb 14, 2013
1 parent 82477ed commit e26ef93
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
27 changes: 19 additions & 8 deletions config.js
Expand Up @@ -168,15 +168,22 @@ Config.prototype.Application = function(app) {
var domain = req.headers.host.split(':')[0];
// Set the parameters mapping
res.locals.mapping = parameters.vhost[domain];
res.locals.view_dir = __dirname + '/sites/' + res.locals.mapping + '/views';

next();
});

// Set favicon if is enabled in configuration parameters
if (parameters.favicon) {
app.use(express.favicon(__dirname + parameters.favicon));
}
// Check if site exists, otherwise send error
if(res.locals.mapping) {
// Set the view directory
res.locals.view_dir = __dirname + '/sites/' + res.locals.mapping + '/views';
// Set favicon if is enabled in configuration parameters
if (misc_params[res.locals.mapping].favicon) {
app.use(express.favicon(__dirname + '/sites/' + res.locals.mapping + misc_params[res.locals.mapping].favicon));
}
next();

} else {
utils.applog('error', "Requested and invalid site from: " + req.connection.remoteAddress);
res.send(parameters.server_error);
}
});

// maintenance mode middleware
app.use(function (req, res, next) {
Expand Down Expand Up @@ -236,6 +243,10 @@ Config.prototype.Application = function(app) {

// Set the default locals
app.use(function(req, res, next){
// Set guest role
if (!req.session.role) {
req.session.role = 1000;
}
res.locals.title = misc_params[res.locals.mapping].title;
res.locals.site_url = misc_params[res.locals.mapping].site_url;
res.locals.session = req.session;
Expand Down
13 changes: 11 additions & 2 deletions lib/hbs.js
@@ -1,3 +1,11 @@
/*
* MuContent
*
* This library is based on hbs library:
* Allow multisiste view system
*
*/


// builtin
var fs = require('fs');
Expand Down Expand Up @@ -77,8 +85,9 @@ exports.__express = function(filename, options, cb) {
if (options.layout !== undefined && !options.layout) {
return render_file(options, cb);
}
/*console.log(options.mapping);
console.log(options.settings);*/

// This allow the view path for multiste, in options you can find res.locals variable
// For example: options.mapping
var view_dir = options.settings.views;

var layout_filename = path.join(view_dir, options.layout || 'layout' + extension);
Expand Down
5 changes: 4 additions & 1 deletion params.js
Expand Up @@ -33,6 +33,9 @@ module.exports = {
// Mapping the vhost and sites: domain -> site name references
vhost: {
"localhost": 'default',
// "www.pinco.net": 'pinco'
"www.pinco.net": 'pinco'
},

// Error for site not found or other
server_error: "Sorry, server error, please contact: ",
};
1 change: 1 addition & 0 deletions sites/default/settings/menu.js
Expand Up @@ -14,6 +14,7 @@ module.exports = {
// title is the handler in the locales files to get the title based on language
// Examples:
// {title: "search", path: "/test", acl: {0: true, 1: false}}, // If you set acl, you resticted the role
// {title: "search", path: "/test", acl: {1000: true}}, // role 1000 identify guests
// {title: "you", path: "/you", icon: "icon-off"} // If you don't set acl, all can access
]

Expand Down
3 changes: 2 additions & 1 deletion sites/default/settings/route.js
Expand Up @@ -13,7 +13,8 @@ module.exports = {
/* Example:
{route: '/logout', acl: {0: true, 1: true}},
// Put in route the same route defined in express.js, for example, a route with params:
{route: '/objects/edit/:id', acl: {0: true, 1: true}, ajax: true},
*/
], // Role legend: 0 (admin), 1 (user), add other if you want and modify the defaults
], // Role legend: 0 (admin), 1 (user), 1000 (guest), add other if you want and modify the defaults

};

0 comments on commit e26ef93

Please sign in to comment.