archive/hourglass/lib/router.js
Yaman Qalieh e23398999a fix #76
2016-09-01 00:13:17 -04:00

71 lines
2.0 KiB
JavaScript

Router.route('/', {
waitOn: function() {
if (!Meteor.userId() || !Meteor.user().profile.school) {
this.redirect('/login');
} else {
return [
Meteor.subscribe('classes',this.params._id),
Meteor.subscribe('schools',this.params._id),
Meteor.subscribe('work',this.params._id),
Meteor.subscribe('requests',this.params._id),
Meteor.subscribe('users',this.params._id)
];
}
},
action: function() {
this.render("main");
}
});
Router.route('/login', function() {
if (!Meteor.userId()) {
this.render("login");
} else if (!Meteor.user().profile.school) {
this.redirect('/profile');
} else {
this.redirect('/');
}
});
Router.route('/profile', {
waitOn: function() {
if (!Meteor.userId()) {
this.redirect('/login');
} else {
return [
Meteor.subscribe('classes',this.params._id),
Meteor.subscribe('schools',this.params._id),
Meteor.subscribe('work',this.params._id),
Meteor.subscribe('requests',this.params._id),
Meteor.subscribe('users',this.params._id)
];
}
},
action: function() {
this.render("profile");
}
});
Router.route('/admin', {
waitOn: function() {
if (Roles.userIsInRole(Meteor.userId(), ['admin', 'superadmin'])) {
return [
Meteor.subscribe('classes',this.params._id),
Meteor.subscribe('schools',this.params._id),
Meteor.subscribe('work',this.params._id),
Meteor.subscribe('requests',this.params._id),
Meteor.subscribe('users',this.params._id)
];
} else {
this.render('NotFound');
}
},
action: function() {
this.render("admin");
}
});
Router.configure({
notFoundTemplate: "NotFound"
});