1
0
mirror of https://github.com/fazo96/markcloud.git synced 2025-01-10 11:04:21 +01:00

verify email added

This commit is contained in:
fazo96 2014-10-07 12:36:39 +02:00
parent 3403d8a207
commit 27333f0296
3 changed files with 57 additions and 24 deletions

View File

@ -1,6 +1,11 @@
docs = new Meteor.Collection 'docs'
amIValid = ->
return no unless Meteor.user()
return yes for mail in Meteor.user().emails when mail.verified is yes; no
UI.registerHelper 'mail', -> Meteor.user().emails[0].address
UI.registerHelper 'amIValid', amIValid
Router.configure
layoutTemplate: 'layout'
@ -17,6 +22,9 @@ docController = RouteController.extend
loggedOutController = RouteController.extend
onBeforeAction: -> if Meteor.user() then Router.go 'profile'
action: ->
@render()
if Meteor.loggingIn() then @render 'spinner', to: 'outside'
loggedInController = RouteController.extend
action: -> if !Meteor.user() then @render '404' else @render()
@ -34,9 +42,10 @@ Router.map ->
controller: docController
@route 'verify',
path: '/verify/:token?'
template: 'loading'
onBeforeAction: ->
Accounts.verifyEmail @params.token, (err) ->
if err then errCallback err else Router.go 'home'
if err then errCallback err else Router.go 'profile'
@route 'edit',
path: '/edit/:_id'
template: 'editor'
@ -82,7 +91,8 @@ Template.notifications.events
Template.layout.notHome = -> Router.current().route.name isnt 'home'
Template.layout.showSpinner = ->
Meteor.status().connected is no or Router.current().ready() is no
Template.home.ndocs = -> docs.find().count()
Template.home.rendered = ->
$('.ttip').tooltip()
Template.editor.showTitleChecked = -> return "checked" unless @showTitle is no
Template.editor.events
'click #upload': (e,t) ->
@ -116,6 +126,10 @@ Template.profile.noDocs = -> docs.find(owner: @_id).count() is 0
Template.profile.documents = ->
docs.find {owner: @_id}, sort: dateCreated: -1
Template.profile.events
'click #resend': ->
Meteor.call 'sendVerificationEmail', (e,r) ->
if e then errCallback e
else notify msg: r, type:'success'
'click #logout': -> Meteor.logout(); Router.go 'home'
Template.delete.events
@ -170,6 +184,3 @@ Template.signup.events
password: t.find('#pw').value
}, (err) -> if err then errCallback err
else notify type: 'success', msg: 'check your email'
Template.verify.events
'click #sendmail': -> Meteor.call 'sendVerificationEmail'

View File

@ -10,14 +10,24 @@
<div class="container">
<h1>MarkCloud
{{#if currentUser}}
{{#if amIValid}}
<a class="pull-right" href="/u">
<small><i class="fa fa-chevron-right"></i></small>
</a>
{{else}}
<a class="pull-right ttip" href="/u" data-toggle="tooltip" data-placement="left" title="Need email verification">
<small><i class="fa fa-envelope"></i></small>
</a>
{{/if}}
{{else}}
{{#if notHome}}
<a class="pull-right" href="/">
<small><i class="fa fa-home"></i></small>
</a>
{{else}}
<a class="pull-right" href="/signup">
<small><i class="fa fa-user"></i></small>
</a>
{{/if}}
{{/if}}
</h1>
@ -175,7 +185,8 @@ You will be able to delete your account and all your data whenever you want.
<input type="text" class="form-control" id="name" placeholder="Username">
<input type="password" class="form-control" placeholder="Password" id="pw">
<input type="password" class="form-control" placeholder="Repeat Password" id="rpw">
<button class="btn btn-primary" id="signup">Sign Up</button>
<button class="btn btn-primary" id="signup">
<i class="fa fa-user"></i> Sign Up</button>
<hr>
<div class="text-center">Already have an account? <a href="/login">Sign in!</a></div>
</div>
@ -186,7 +197,8 @@ You will be able to delete your account and all your data whenever you want.
<h2>Sign In</h2>
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address or Username">
<input type="password" class="form-control" placeholder="Password" id="pw">
<button class="btn btn-primary" id="signin">Sign In</button>
<button class="btn btn-primary" id="signin">
<i class="fa fa-sign-in"></i> Sign In</button>
<hr>
<div class="text-center">Need an account? <a href="/signup">Sign Up!</a></div>
</div>
@ -199,12 +211,19 @@ You will be able to delete your account and all your data whenever you want.
{{#if noDocs}}
<p>You don't have any documents yet.</p>
{{/if}}
{{#unless amIValid}}
<p class="lead">You need to verify your email address. Click the link in the email you received.</p>
<button class="btn btn-primary" id="resend">
<i class="fa fa-envelope"></i> Resend</button>
{{/unless}}
</div>
<div class="text-center" id="profile-tools">
<a class="btn btn-primary" id="logout">
<i class="fa fa-sign-out"></i> Logout</a>
{{#if amIValid}}
<a class="btn btn-success" href="/new">
<i class="fa fa-file-text"></i> New Document</a>
{{/if}}
<a class="btn btn-danger" href="/delete">
<i class="fa fa-exclamation-circle"></i> Delete Account</a>
</div>
@ -237,8 +256,3 @@ You will be able to delete your account and all your data whenever you want.
<button class="btn btn-danger" id="del-account">
<i class="fa fa-exclamation-circle"></i> Confirm</button>
</template>
<template name="verify">
<p>If you didn't receive anything at <b>{{mail}}</b> address press the button below.</p>
<button id="sendmail" class="btn btn-primary">Resend</button>
</template>

View File

@ -14,8 +14,8 @@ Meteor.startup ->
Meteor.setInterval cleanDocuments, 3600000
validatedUser = (uid) ->
return no unless Meteor.users.findOne uid
u = Meteor.users.findOne uid
return no unless u
return yes for mail in u.emails when mail.verified is yes; no
Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
@ -26,10 +26,13 @@ Meteor.publish 'docs', (userId) ->
else docs.find {owner: userId, public: yes}, fields: text: 0
else docs.find {}, fields: text: 0
Meteor.publish 'user', (id) ->
Meteor.users.find id, fields: {username: 1}
if @userId is id
Meteor.users.find id, fields: {username: 1, emails: 1}
else Meteor.users.find id, fields: {username: 1}
docs.allow
insert: (uid,doc) ->
return no if uid and !validatedUser(uid)
if doc.text and doc.title
doc.dateCreated = moment().unix()
doc.showTitle ?= yes
@ -40,16 +43,21 @@ docs.allow
docs.allow
# Owners can update and remove their documents
update: (uid,doc) ->
return no if uid and !validatedUser(uid)
return no unless uid is doc.owner
docs.update doc._id, $set: lastModified: moment().unix()
return yes
remove: (uid,doc) -> doc.owner is uid
fetch: ['owner']
fetch: ['owner','emails']
Meteor.methods
'deleteMe': ->
if @userId
Meteor.users.remove @userId
docs.remove owner: @userId
'amIValid': -> validatedUser @userId
'sendVerificationEmail': ->
if @userId then Accounts.sendVerificationEmail @userId
if @userId and not validatedUser @userId
Accounts.sendVerificationEmail @userId
return 'email sent'
else return 'could not send email'