-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.js
More file actions
129 lines (120 loc) · 3.31 KB
/
shared.js
File metadata and controls
129 lines (120 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Collections
* @type {exports.Collection}
*/
Devices = new Meteor.Collection('devices');
Log = new Meteor.Collection('log');
Comments = new Meteor.Collection('comments');
/**
* Everything down is router logic
*/
Router.configure({
layoutTemplate: "mainLayout",
loadingTemplate: "loading",
notFoundTemplate: "missing"
});
/**
* Controllers
*/
// Admin only pages
AdminAccessController = RouteController.extend({
//On before action hook to check if the user is logged in and have the right privileges
onBeforeAction: function() {
var currentUser = Meteor.user();
if (!(Meteor.loggingIn() || currentUser) || !(Roles.userIsInRole(currentUser, ['admin']))) {
this.render("login");
}
// After IR > 1.* you need to call this.next() for better use of connection middleware
else{
// Subscriptions
Meteor.subscribe('devices');
Meteor.subscribe('users');
Meteor.subscribe('log');
Meteor.subscribe('comments');
// After IR > 1.* you need to use this.next()
// for better use of connection middleware
this.next();
}
}
});
// Pages require login
UserAccessController = RouteController.extend({
//On before action hook to check if the user is logged in
onBeforeAction: function(){
if (!(Meteor.loggingIn() || Meteor.user())) {
this.render("login");
} else{
// Subscriptions
Meteor.subscribe('devices');
Meteor.subscribe('users');
Meteor.subscribe('comments');
// After IR > 1.* you need to use this.next()
// for better use of connection middleware
this.next();
}
}
});
/**
* Routes definition
*/
Router.map(function() {
this.route('login', {
path: 'login',
waitOn: function() {
if(Meteor.user()) {
this.redirect("home");
}
}
});
// Routes requiring admin privileges
this.route('logs', {
path: 'logs',
template:'logs',
controller: AdminAccessController
});
this.route('users', {
path: 'users',
template:'users',
controller: AdminAccessController
});
this.route('stats', {
path: 'stats',
template:'stats',
controller: AdminAccessController
});
this.route('add-device', {
path: 'add-device',
controller: AdminAccessController
});
this.route('backup', {
path: 'backup',
controller: AdminAccessController
});
//Routes requiring login in
this.route('home', {
path: '/',
controller: UserAccessController
});
this.route('book', {
path: 'book/:_DeviceId',
data: function(){
return Devices.findOne({_id: this.params._DeviceId});
},
controller: UserAccessController
});
this.route('bookedByMe', {
path: 'booked-By-Me',
template: 'bookedByMe',
controller: UserAccessController
});
this.route('feedback', {
path: 'feedback',
template: 'feedback',
controller: UserAccessController
});
this.route('alerts', {
path: 'alerts',
template: 'alerts',
controller: UserAccessController
});
});