Created
March 22, 2016 11:52
-
-
Save balanza/3b62adb968e08c29007b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//navigation.js - centralized app navigation methods | |
function isLoggedIn(fn){ | |
return function() { | |
if( /* test if the user is logged in */ ){ | |
/* redirect to login page */ | |
} else { | |
var args = Array.prototype.slice.call(arguments); | |
return fn && fn.apply(this, args); | |
} | |
}; | |
} | |
function hasRole(role, fn){ | |
return function() { | |
if( /* test if the user has role */ ){ | |
/* redirect to 403 page */ | |
} else { | |
var args = Array.prototype.slice.call(arguments); | |
return fn && fn.apply(this, args); | |
} | |
}; | |
} | |
function hasVerifiedCreditCard(fn){ | |
return function() { | |
if( /* test if the user has a verified credit card */ ){ | |
/* redirect to the page in which he can verify his credit card */ | |
} else { | |
var args = Array.prototype.slice.call(arguments); | |
return fn && fn.apply(this, args); | |
} | |
}; | |
} | |
exports.openHomePage = function(){ /* code for opening the Home page */ }; | |
exports.openProfilePage = isLoggedIn(function(){ /* code for opening the Profile page */ }); | |
exports.openDashboardPage = isLoggedIn(function(){ /* code for opening Dashboard page */ }); | |
exports.openInsightsPage = isLoggedIn(hasRole('admin', function(){ /* code for opening Insights page */ })); | |
exports.openBillingPage = isLoggedIn(hasVerifiedCreditCard(function(){ /* code for opening the Billing page */ })); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment