mirror of
https://github.com/fazo96/homework.git
synced 2025-01-10 12:14:22 +01:00
fixed big bugs in last commit
This commit is contained in:
parent
6b42e24e57
commit
398eca2a41
@ -11,7 +11,8 @@ amIValid = ->
|
||||
|
||||
# Common Helpers for the Templates
|
||||
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
||||
UI.registerHelper "email", -> getUser().emails[0].address
|
||||
UI.registerHelper "email", ->
|
||||
if getUser() then return getUser().emails[0].address
|
||||
UI.registerHelper "verified", -> amIValid()
|
||||
|
||||
# Router
|
||||
@ -29,12 +30,12 @@ Router.configure
|
||||
notFoundTemplate: '404'
|
||||
Router.map ->
|
||||
@route 'home',
|
||||
path: '/'
|
||||
onBeforeAction: ->
|
||||
# Dispatch user to the right landing page based on his account status
|
||||
if getUser()
|
||||
if amIValid() is yes then Router.go 'notes' else Router.go 'verifyEmail'
|
||||
else Router.go 'login'
|
||||
path: '/'
|
||||
@route 'login',
|
||||
onBeforeAction: -> Router.go 'home' if getUser()
|
||||
@route 'register',
|
||||
@ -55,11 +56,19 @@ Router.map ->
|
||||
path: '/verify/:token?'
|
||||
template: 'verifyEmail'
|
||||
onBeforeAction: ->
|
||||
if @params.token?
|
||||
if @params.token? and @params.token isnt ""
|
||||
Accounts.verifyEmail @params.token, (err) ->
|
||||
if err then errCallback err else Router.go 'home'
|
||||
if err
|
||||
errCallback err; Router.go 'verifyEmail'
|
||||
else Router.go 'home'
|
||||
@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 t and t.lookupTemplate
|
||||
if getUser() and t.lookupTemplate() is 'login' then Router.go 'home'
|
||||
|
||||
# Client Templates
|
||||
|
||||
# Some utilities
|
||||
@ -78,6 +87,7 @@ Template.menu.events
|
||||
# User Interface
|
||||
Template.account.events
|
||||
'click #btn-logout': (e,template) -> Meteor.logout logoutCallback
|
||||
'click #btn-delete-me': -> deleteAccount()
|
||||
|
||||
# Notes template
|
||||
Template.notelist.empty = -> notes.find().count() is 0
|
||||
@ -138,7 +148,10 @@ Template.error.events 'click .close': -> clearError()
|
||||
# Verify Email
|
||||
Template.verifyEmail.events
|
||||
'click #btn-verify': (e,template) ->
|
||||
Accounts.verifyEmail template.find('#token-field').value, (err) ->
|
||||
t = template.find('#token-field').value; t = t.split("/")
|
||||
t = t[t.length-1] # Remove all the part before the last "/"
|
||||
console.log "Email ver. using token: "+template.find('#token-field').value
|
||||
Accounts.verifyEmail t, (err) ->
|
||||
if err then errCallback err else Router.go 'notes'
|
||||
'click #btn-resend': ->
|
||||
Meteor.call 'resendConfirmEmail', (err) ->
|
||||
@ -153,7 +166,7 @@ loginRequest = (e,template) ->
|
||||
if e and e.keyCode isnt 13 then return
|
||||
mail = template.find('#l-mail').value; pass = template.find('#l-pass').value
|
||||
Meteor.loginWithPassword mail, pass, (err) ->
|
||||
if err then errCallback err else Router.go 'home'
|
||||
if err then errCallback err else Router.go 'notes'
|
||||
|
||||
Template.login.events
|
||||
'keypress .login': (e,template) -> loginRequest e,template
|
||||
|
@ -19,7 +19,7 @@
|
||||
<template name="menu">
|
||||
<div align="center" class="menu-container">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-success go-archive">
|
||||
<button type="button" disabled="disabled" class="btn btn-success go-archive">
|
||||
<i class="fa fa-book fa-inverse"></i> Archive
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary go-home">
|
||||
@ -111,12 +111,14 @@
|
||||
|
||||
<template name="verifyEmail">
|
||||
<div align="center">
|
||||
<p>Insert the token you received by email at the address {{email}} here, or click the link in the email we sent you.</p>
|
||||
<h3 class="cool-header"><i class="fa fa-envelope fa-2x"></i><br>
|
||||
Please verify your Email Address<br><small>{{email}}</small></h3>
|
||||
<p>Click the link inside the email we sent you or paste it here:</p>
|
||||
{{> error}}
|
||||
<input type="text" id="token-field" class="form-control" placeholder="Token">
|
||||
<div align="center" class="buttons">
|
||||
<button type="button" class="btn btn-warning btn-ver" id="btn-resend">Resend Email</button>
|
||||
<button type="button" class="btn btn-success btn-ver" id="btn-verify">Verify Email</button>
|
||||
<button type="button" class="btn btn-success btn-ver" id="btn-verify">Verify Token</button>
|
||||
<button type="button" class="btn btn-danger btn-ver" id="btn-delete">Delete Account</button>
|
||||
<br><button type="button" class="btn btn-primary btn-ver" id="btn-logout">Logout</button>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user