forked from Differential/accounts-entry
-
Notifications
You must be signed in to change notification settings - Fork 2
/
router.coffee
106 lines (89 loc) · 3.21 KB
/
router.coffee
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
Router.map ->
@route "entrySignIn",
path: "/sign-in"
onBeforeAction: ->
Session.set('entryError', undefined)
Session.set('buttonText', 'in')
@next()
onRun: ->
if Meteor.userId()
Router.go AccountsEntry.settings.dashboardRoute
if AccountsEntry.settings.signInTemplate
@template = AccountsEntry.settings.signInTemplate
# If the user has a custom template, and not using the helper, then
# maintain the package Javascript so that OpenGraph tags and share
# buttons still work.
pkgRendered= Template.entrySignIn.rendered
userRendered = Template[@template].rendered
if userRendered
Template[@template].rendered = ->
pkgRendered.call(@)
userRendered.call(@)
else
Template[@template].rendered = pkgRendered
Template[@template].events(AccountsEntry.entrySignInEvents)
Template[@template].helpers(AccountsEntry.entrySignInHelpers)
@next()
@route "entrySignUp",
path: "/sign-up"
onBeforeAction: ->
Session.set('entryError', undefined)
Session.set('buttonText', 'up')
@next()
onRun: ->
if AccountsEntry.settings.signUpTemplate
@template = AccountsEntry.settings.signUpTemplate
# If the user has a custom template, and not using the helper, then
# maintain the package Javascript so that OpenGraph tags and share
# buttons still work.
pkgRendered= Template.entrySignUp.rendered
userRendered = Template[@template].rendered
if userRendered
Template[@template].rendered = ->
pkgRendered.call(@)
userRendered.call(@)
else
Template[@template].rendered = pkgRendered
Template[@template].events(AccountsEntry.entrySignUpEvents)
Template[@template].helpers(AccountsEntry.entrySignUpHelpers)
@next()
@route "entryForgotPassword",
path: "/forgot-password"
onBeforeAction: ->
Session.set('entryError', undefined)
@next()
@route 'entrySignOut',
path: '/sign-out'
onBeforeAction: ()->
Session.set('entryError', undefined)
if not AccountsEntry.settings.homeRoute
@next()
else
Meteor.logout () ->
Router.go AccountsEntry.settings.homeRoute
@route 'entryVerificationPending',
path: '/verification-pending'
onBeforeAction: ->
Session.set('entryError', undefined)
@next()
@route 'entryResetPassword',
path: 'reset-password/:resetToken'
onBeforeAction: ->
Session.set('entryError', undefined)
Session.set('resetToken', @params.resetToken)
@next()
@route 'entryEnrollAccount',
path: 'enroll-account/:resetToken'
onBeforeAction: ->
Session.set('entryError', undefined)
Session.set('resetToken', @params.resetToken)
@next()
# Get all the accounts-entry routes one time
exclusions = []
_.each Router.routes, (route)->
exclusions.push route.name
# Change the fromWhere session variable when you leave a path
Router.onStop ->
# If the route is an entry route, no need to save it
if (!_.contains(exclusions, Router.current().route?.getName()))
Session.set('fromWhere', Router.current().path)