Blame view

client/routes/filters.coffee 856 Bytes
d1f4dbea8   Ryan Glover   Additional README...
1
  ###
5f6f6fbb0   Ryan Glover   Clean up spacing....
2
3
    Route Filters
    Filters for managing user access to application routes.
d1f4dbea8   Ryan Glover   Additional README...
4
5
6
  ###
  
  # Define Filters
98c57048b   Ryan Glover   Clean up comments...
7
  ###
5f6f6fbb0   Ryan Glover   Clean up spacing....
8
9
10
    Filter: Check if a User is Logged In
    If a user is not logged in and attempts to go to an authenticated route,
    re-route them to the login screen.
98c57048b   Ryan Glover   Clean up comments...
11
  ###
d1f4dbea8   Ryan Glover   Additional README...
12
  checkUserLoggedIn = ->
5f6f6fbb0   Ryan Glover   Clean up spacing....
13
14
15
    if not Meteor.loggingIn() and not Meteor.user()
      Router.go '/login'
      @pause
d1f4dbea8   Ryan Glover   Additional README...
16

98c57048b   Ryan Glover   Clean up comments...
17
  ###
5f6f6fbb0   Ryan Glover   Clean up spacing....
18
19
20
    Filter: Check if a User Exists
    If a user is logged in and attempts to go to a public route, re-route
    them to the main "logged in" screen.
98c57048b   Ryan Glover   Clean up comments...
21
  ###
d1f4dbea8   Ryan Glover   Additional README...
22
  userAuthenticated = ->
5f6f6fbb0   Ryan Glover   Clean up spacing....
23
24
    if not Meteor.loggingIn() and Meteor.user()
      Router.go '/'
d1f4dbea8   Ryan Glover   Additional README...
25

d1f4dbea8   Ryan Glover   Additional README...
26
27
28
  # Run Filters
  
  Router.onBeforeAction checkUserLoggedIn, except: [
5f6f6fbb0   Ryan Glover   Clean up spacing....
29
30
31
32
    'signup',
    'login',
    'recover-password',
    'reset-password'
d1f4dbea8   Ryan Glover   Additional README...
33
34
35
  ]
  
  Router.onBeforeAction userAuthenticated, only: [
5f6f6fbb0   Ryan Glover   Clean up spacing....
36
37
38
39
    'signup',
    'login',
    'recover-password',
    'reset-password'
d1f4dbea8   Ryan Glover   Additional README...
40
  ]