Last active
August 29, 2015 14:06
-
-
Save digilord/9ca5672d4356447f88c8 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
Router.configure | |
layoutTemplate: 'layout' | |
notFoundTemplate: 'notFound' | |
loadingTemplate: 'loading' | |
onBeforeAction: (pause) -> | |
except = ['_login','logout'] | |
route = this.route.name | |
# console.log 'Checking to see if we have a user.' | |
# console.log except.none(route) | |
# console.log this.route.name | |
if except.none(route) | |
mustBeSignedIn(pause) | |
return | |
Router.map -> | |
@route 'home', | |
path: '/' | |
@route '_login', | |
path: '/login' | |
@route 'logout', | |
path: '/logout', | |
onBeforeAction: -> | |
Meteor.logout() | |
@route 'admin', | |
path: '/admin' | |
onBeforeAction: -> | |
_user = Meteor.user() | |
if not _user | |
return | |
if Roles.userIsInRole(_user, 'admin') | |
this.subscribe('activityreports', {}).wait() | |
else | |
for role in Roles.getAllRoles().fetch() | |
roleName = role.name | |
if not roleName.startsWith('manage') | |
if routeByRole(_user._id, role.name) isnt false | |
break | |
mustBeSignedIn = (pause) -> | |
# console.log 'Inside mustBeSignedIn' | |
if Meteor.loggingIn() | |
return | |
if Meteor.user() is null | |
console.log 'No user - Redirecting to login' | |
Router.go('/login') | |
pause() | |
class @AuthorizedController extends RouteController | |
onBeforeAction: (pause) -> | |
mustBeSignedIn(pause) | |
class @HomeController extends AuthorizedController | |
onBeforeAction: (pause) -> | |
user = Meteor.user() | |
roles = [] | |
for role in Roles.getAllRoles().fetch() | |
roleName = role.name | |
if not roleName.startsWith('manage') | |
if routeByRole(user._id, role.name) isnt false | |
break | |
class @Editarrest extends AuthorizedController | |
#pass | |
class @LogoutController extends AuthorizedController | |
# Pass | |
routeByRole = (user, role) -> | |
if Roles.userIsInRole user, role | |
return Router.go("/#{role}") | |
return false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment