mirror of
https://github.com/fazo96/homework.git
synced 2025-01-09 12:10:08 +01:00
added a router. fixes #9
This commit is contained in:
parent
2d92401442
commit
ce8442a6ab
@ -10,3 +10,4 @@ bootstrap-3
|
||||
font-awesome
|
||||
accounts-base
|
||||
accounts-password
|
||||
iron-router
|
||||
|
@ -6,29 +6,55 @@ getUser = -> Meteor.user()
|
||||
amIValid = ->
|
||||
return no unless getUser()
|
||||
return yes for mail in getUser().emails when mail.verified is yes; no
|
||||
logoutCallback = (err) -> if err then errCallback err else Router.go 'home'
|
||||
loginCallback = (err) -> if err then errCallback err else Router.go 'notes'
|
||||
|
||||
# Common Helpers
|
||||
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
||||
UI.registerHelper "mail", -> getUser().emails[0].address
|
||||
UI.registerHelper "email", -> getUser().emails[0].address
|
||||
UI.registerHelper "verified", -> amIValid()
|
||||
|
||||
# Router
|
||||
Router.configure
|
||||
layoutTemplate: 'layout'
|
||||
loadingTemplate: 'loading'
|
||||
Router.map ->
|
||||
@route 'home',
|
||||
onBeforeAction: -> if getUser() then Router.go 'notes'
|
||||
path: '/'
|
||||
template: 'auth'
|
||||
@route 'notes',
|
||||
onBeforeAction: ->
|
||||
if not getUser() then Router.go 'home'
|
||||
if amIValid() is no then Router.go 'verifyEmail'
|
||||
@route 'note',
|
||||
path: '/note/:_id'
|
||||
data: -> notes.findOne _id: @params._id
|
||||
onBeforeAction: ->
|
||||
if not getUser() then Router.go 'home'
|
||||
if amIValid() is no then Router.go 'verifyEmail'
|
||||
if not @data() then Router.go 'notes'
|
||||
@route 'verifyEmail',
|
||||
template: 'verifyEmail'
|
||||
onBeforeAction: ->
|
||||
if not getUser() then Router.go 'home'
|
||||
if amIValid() is yes then Router.go 'notes'
|
||||
|
||||
# Client Templates
|
||||
|
||||
# User Interface
|
||||
Template.userInfo.events
|
||||
'click #logout': (e,template) -> Meteor.logout()
|
||||
Template.account.events
|
||||
'click #logout': (e,template) -> Meteor.logout logoutCallback
|
||||
|
||||
# Notes template
|
||||
Template.notes.truncateNoteDesc = (s) -> s
|
||||
#if s.length > 52 then s.slice(0,48)+"..." else s
|
||||
Template.notes.notes = ->
|
||||
Template.notelist.empty = -> notes.find().count() is 0
|
||||
Template.notelist.notes = ->
|
||||
d = notes.find().fetch()
|
||||
Template.notes.events
|
||||
Template.notelist.events
|
||||
'click .close-note': ->
|
||||
if Session.get('note') and Session.get('note')._id is @_id
|
||||
Session.set 'note', undefined
|
||||
notes.remove @_id
|
||||
'click .edit-note': -> Session.set 'note', this
|
||||
'click .edit-note': ->
|
||||
Router.go 'note', {_id: @_id}
|
||||
'keypress #newNote': (e,template) ->
|
||||
if e.keyCode is 13 and template.find('#newNote').value isnt ""
|
||||
notes.insert
|
||||
@ -38,15 +64,15 @@ Template.notes.events
|
||||
template.find('#newNote').value = ""
|
||||
|
||||
# Note Editor
|
||||
Template.editor.note = -> Session.get 'note'
|
||||
Template.editor.note = -> Router.current.data()
|
||||
saveCurrentNote = (t,e) ->
|
||||
if e and e.keyCode isnt 13 then return;
|
||||
notes.update Session.get('note')._id,
|
||||
notes.update Router.current().data()._id,
|
||||
$set:
|
||||
title: t.find('.editor-title').value
|
||||
content: t.find('.area').value
|
||||
Template.editor.events
|
||||
'click .close-editor': -> Session.set 'note', undefined
|
||||
'click .close-editor': -> Router.go 'notes'
|
||||
'click .save-editor': (e,t) -> saveCurrentNote t
|
||||
'keypress .title': (e,t) -> saveCurrentNote t, e
|
||||
|
||||
@ -82,22 +108,24 @@ clearError = -> shownError = undefined; errorDep.changed()
|
||||
Template.error.error = -> errorDep.depend(); shownError
|
||||
Template.error.events 'click .close': -> clearError()
|
||||
|
||||
# "Loading" template
|
||||
Template.loading.status = -> Meteor.status()
|
||||
|
||||
# Verify Email
|
||||
Template.verifyEmail.events
|
||||
'click #btn-verify': (e,template) ->
|
||||
Accounts.verifyEmail template.find('#token-field').value, errCallback
|
||||
Accounts.verifyEmail template.find('#token-field').value, (err) ->
|
||||
if err then errCallback err else Router.go 'notes'
|
||||
'click #btn-resend': ->
|
||||
Meteor.call 'resendConfirmEmail', errCallback
|
||||
'click #btn-delete': -> Meteor.call 'deleteMe'
|
||||
'click #btn-logout': -> Meteor.logout()
|
||||
Meteor.call 'resendConfirmEmail', (err) ->
|
||||
if err
|
||||
errCallback err
|
||||
else showError { type:"success", msg: "Confirmation email sent" }
|
||||
'click #btn-delete': ->
|
||||
Meteor.call 'deleteMe', (r) -> if r is yes then Router.go 'home'
|
||||
'click #btn-logout': -> Meteor.logout logoutCallback
|
||||
|
||||
# Login and Register
|
||||
pressLogin = (template) ->
|
||||
mail = template.find('#mail').value; pass = template.find('#pass').value
|
||||
Meteor.loginWithPassword mail, pass, errCallback
|
||||
Meteor.loginWithPassword mail, pass, loginCallback
|
||||
|
||||
Template.auth.events
|
||||
# Login
|
||||
@ -117,6 +145,6 @@ Template.auth.events
|
||||
Accounts.createUser {
|
||||
email: mail,
|
||||
password: pass
|
||||
}, errCallback
|
||||
}, (err) -> if err then errCallback err else Router.go 'confirmEmail'
|
||||
catch err
|
||||
showError msg: err
|
||||
|
5
client/view/head.html
Normal file
5
client/view/head.html
Normal file
@ -0,0 +1,5 @@
|
||||
<!-- Homework HTML page -->
|
||||
<head>
|
||||
<title>Homework</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
</head>
|
@ -1,9 +1,5 @@
|
||||
<head>
|
||||
<title>Homework</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
</head>
|
||||
<body>
|
||||
{{> ribbon}}
|
||||
<!-- Homework UI Templates -->
|
||||
<template name="layout">
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1 id="title">Homework<br>
|
||||
@ -12,21 +8,27 @@
|
||||
</div>
|
||||
<div class="center-block" id="ui-container">
|
||||
{{> error}}
|
||||
{{#if currentUser}}
|
||||
{{#if verified}}
|
||||
{{> editor}} {{> notes}} {{> userInfo}}
|
||||
{{else}}
|
||||
{{> verifyEmail}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{> auth}}
|
||||
{{/if}}
|
||||
{{> yield}}
|
||||
</div>
|
||||
<div class="center-block" align="center">{{> footer}}</div>
|
||||
</div>
|
||||
</body>
|
||||
{{> ribbon}}
|
||||
</template>
|
||||
|
||||
<template name="notes">
|
||||
{{> notelist }} <hr> {{> account }}
|
||||
</template>
|
||||
<template name="note">
|
||||
{{> editor }} {{> notelist }} <hr> {{> account }}
|
||||
</template>
|
||||
|
||||
<template name="noteadder">
|
||||
<div align="center">
|
||||
<input type="text" id="newNote" class="form-control" placeholder="Add new note">
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template name="notelist">
|
||||
<ul class="list-group">
|
||||
{{#each notes}}
|
||||
<li class="note list-group-item">
|
||||
@ -40,9 +42,10 @@
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
<div align="center">
|
||||
<input type="text" id="newNote" class="form-control" placeholder="Add new note">
|
||||
</div>
|
||||
{{#if empty}}
|
||||
<p align="center">You don't have any notes, try adding a new one</p>
|
||||
{{/if}}
|
||||
{{> noteadder }}
|
||||
</template>
|
||||
|
||||
<template name="auth">
|
||||
@ -56,14 +59,14 @@
|
||||
<br>
|
||||
{{/if}}
|
||||
<p>Password must be at least 8 characters. Email must be a valid email</p>
|
||||
{{#unless working}}
|
||||
{{#unless loggingIn}}
|
||||
<button type="button" id="register" class="btn-auth btn btn-success">Register</button>
|
||||
<button type="button" id="login" class="btn-auth btn btn-primary">Login</button>
|
||||
{{/unless}}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template name="userInfo"><hr>
|
||||
<template name="account">
|
||||
{{#if loggingIn}} {{> loading}} {{/if}}
|
||||
<div align="center">
|
||||
<p>{{email}}</p>
|
||||
@ -86,18 +89,18 @@
|
||||
|
||||
<template name="editor">
|
||||
<div align="center">{{> error }}</div>
|
||||
{{#if note}}
|
||||
{{#if _id}}
|
||||
<div class="panel panel-info">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">
|
||||
<div align="center">
|
||||
<input type="text" class="form-control editor-title" value="{{note.title}}" placeholder="Title">
|
||||
<input type="text" class="form-control editor-title" value="{{title}}" placeholder="Title">
|
||||
<button type="button" class="close close-editor">×</button>
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
<div align="center" class="panel-body">
|
||||
<textarea class="area form-control" rows="3" placeholder="...">{{note.content}}</textarea>
|
||||
<textarea class="area form-control" rows="3" placeholder="...">{{content}}</textarea>
|
||||
<button type="button" class="btn btn-info save-editor">Save</button>
|
||||
</div>
|
||||
</div>
|
2
packages/.gitignore
vendored
2
packages/.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
/bootstrap-3
|
||||
/font-awesome
|
||||
/iron-router
|
||||
/blaze-layout
|
||||
|
@ -1,4 +1,9 @@
|
||||
# Homework - Server Side
|
||||
|
||||
validateEmail = (email) ->
|
||||
expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
|
||||
expr.test email
|
||||
|
||||
console.log "Started Homework server!"
|
||||
if process.env.MAIL_URL
|
||||
console.log "Sending emails using "+process.env.MAIL_URL
|
||||
@ -8,9 +13,6 @@ else
|
||||
notes = new Meteor.Collection "notes"
|
||||
|
||||
getUser = (id) -> Meteor.users.findOne { _id: id }
|
||||
validateEmail = (email) ->
|
||||
expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
|
||||
expr.test email
|
||||
|
||||
Accounts.config {
|
||||
sendVerificationEmail: true
|
||||
@ -47,7 +49,7 @@ Meteor.methods
|
||||
resendConfirmEmail: ->
|
||||
u = getUser(@userId)
|
||||
if not u
|
||||
console.log "Validating nonexisting user!!"; return no
|
||||
console.log "Validating nonexisting user!"; return no
|
||||
if userValidated(u) is no
|
||||
Accounts.sendVerificationEmail @userId
|
||||
console.log "Sent verification email to "+u.emails[0].address
|
||||
@ -61,3 +63,5 @@ Meteor.methods
|
||||
# Automagically log out the user by invalidating every token he has
|
||||
Meteor.users.update {_id: @userId},
|
||||
{$set : { "resume.loginTokens" : [] } }, { multi: yes }
|
||||
return yes
|
||||
else no
|
||||
|
@ -1,5 +0,0 @@
|
||||
# Utility functions for client and server - Homework
|
||||
|
||||
validateEmail = (email) ->
|
||||
expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
|
||||
expr.test email
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"packages": {
|
||||
"bootstrap-3": {},
|
||||
"font-awesome": {}
|
||||
"font-awesome": {},
|
||||
"iron-router": {}
|
||||
}
|
||||
}
|
||||
|
13
smart.lock
13
smart.lock
@ -3,7 +3,8 @@
|
||||
"dependencies": {
|
||||
"basePackages": {
|
||||
"bootstrap-3": {},
|
||||
"font-awesome": {}
|
||||
"font-awesome": {},
|
||||
"iron-router": {}
|
||||
},
|
||||
"packages": {
|
||||
"bootstrap-3": {
|
||||
@ -15,6 +16,16 @@
|
||||
"git": "https://github.com/nate-strauser/meteor-font-awesome.git",
|
||||
"tag": "v4.1.0",
|
||||
"commit": "ce6b1e92715d1938babc5d69c655c17e387f5926"
|
||||
},
|
||||
"iron-router": {
|
||||
"git": "https://github.com/EventedMind/iron-router.git",
|
||||
"tag": "v0.7.1",
|
||||
"commit": "d1ffb3f06ea4c112132b030f2eb1a70b81675ecb"
|
||||
},
|
||||
"blaze-layout": {
|
||||
"git": "https://github.com/EventedMind/blaze-layout.git",
|
||||
"tag": "v0.2.4",
|
||||
"commit": "b40e9b0612329288d75cf52ad14a7da64bb8618f"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user