1
0
mirror of https://github.com/fazo96/homework.git synced 2025-01-10 12:14:22 +01:00

fix new user registration, redirects and disc management on the homepage

This commit is contained in:
fazo96 2014-09-29 12:26:37 +02:00
parent d3a17dd93b
commit b38370581e

View File

@ -13,7 +13,7 @@ amIValid = ->
return yes for mail in getUser().emails when mail.verified is yes; no return yes for mail in getUser().emails when mail.verified is yes; no
# Common Helpers for the Templates # Common Helpers for the Templates
UI.registerHelper "version", -> "1.1.1" UI.registerHelper "version", -> "1.1.2"
UI.registerHelper "status", -> Meteor.status() UI.registerHelper "status", -> Meteor.status()
UI.registerHelper "loading", -> Meteor.loggingIn() or !Meteor.status().connected UI.registerHelper "loading", -> Meteor.loggingIn() or !Meteor.status().connected
UI.registerHelper "email", -> UI.registerHelper "email", ->
@ -47,7 +47,8 @@ loggedInController = RouteController.extend
else @render() else @render()
onBeforeAction: -> onBeforeAction: ->
if not getUser() then Router.go 'home' if not getUser() then Router.go 'home'
if not amIValid() then Router.go 'verifyEmail' else if not amIValid() then Router.go 'verifyEmail'
guestController = RouteController.extend guestController = RouteController.extend
action: -> action: ->
if Meteor.status().connected is no if Meteor.status().connected is no
@ -55,13 +56,17 @@ guestController = RouteController.extend
else @render() else @render()
onBeforeAction: -> onBeforeAction: ->
if getUser() if getUser()
if not amIValid() then Router.go 'verifyEmail' else Router.go 'home' if amIValid() is no then Router.go 'verifyEmail' else Router.go 'notes'
Router.map -> Router.map ->
@route 'home', @route 'home',
path: '/' path: '/'
template: 'homepage' template: 'homepage'
action: -> @render 'homepage', to: 'outside' action: ->
if Meteor.status().connected is no
@render 'reconnect'
else @render 'homepage', to: 'outside'
onBeforeAction: -> onBeforeAction: ->
# Dispatch user to the right landing page based on his account status # Dispatch user to the right landing page based on his account status
if getUser() if getUser()
@ -82,26 +87,26 @@ Router.map ->
@route 'verifyEmail', @route 'verifyEmail',
path: '/verify/:token?' path: '/verify/:token?'
template: 'verifyEmail' template: 'verifyEmail'
controller: guestController action: ->
if Meteor.status().connected is no
@render 'reconnect'
else @render()
onBeforeAction: -> onBeforeAction: ->
if getUser()
if amIValid() then Router.go 'home'
else Router.go 'home'
# Automatic verification # Automatic verification
if @params.token? and @params.token isnt "" if @params.token? and @params.token isnt ""
@render 'loading' @render 'loading'
Accounts.verifyEmail @params.token, (err) -> Accounts.verifyEmail @params.token, (err) ->
if err if err
errCallback err; Router.go 'verifyEmail', token: @params.token errCallback err; Router.go 'verifyEmail', token: @params.token
else Router.go 'home' else
showErr type:'success', msg:'Verification complete'
Router.go 'home'
@route 'homepage', action: -> @render '404' @route 'homepage', action: -> @render '404'
@route '404', path: '*' @route '404', path: '*'
# You can't set a callback for when the user logs in using a cookie so...
# Cheap ass work around for routing the user after he logs in with a token
Deps.autorun ->
t = Router.current(); return unless getUser() and t and t.lookupTemplate
temp = t.lookupTemplate()
if temp is 'login' or temp is 'homepage' or temp is 'try'
Router.go 'home'
# Client Templates # Client Templates
# Some utility callbacks # Some utility callbacks