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

code clean up

This commit is contained in:
fazo96 2014-06-05 17:03:10 +02:00
parent ccbae51ce5
commit 475181698e
5 changed files with 60 additions and 43 deletions

View File

@ -1,6 +1,6 @@
# Homework - Client Side
# Variables and utility stuff
homework_version = "1.0"
# Utilities
notes = new Meteor.Collection "notes"
getUser = -> Meteor.user()
deleteAccount = ->
@ -33,6 +33,7 @@ Router.configure
Router.map ->
@route 'home',
path: '/'
template: 'homepage'
action: -> @render 'homepage', to: 'outside'
onBeforeAction: ->
# Dispatch user to the right landing page based on his account status
@ -53,13 +54,6 @@ Router.map ->
path: '/archive/:_id?'
waitOn: -> Meteor.subscribe "archive"
onBeforeAction: -> if not getUser() then Router.go 'home'
###
@route 'note',
path: '/note/:_id'
waitOn: -> Meteor.subscribe "my-notes"
data: -> notes.findOne _id: @params._id
onBeforeAction: -> if not @data()? then Router.go 'home'
###
@route 'verifyEmail',
path: '/verify/:token?'
template: 'verifyEmail'
@ -82,7 +76,7 @@ Deps.autorun ->
# Client Templates
# Some utilities
# Some utility callbacks
logoutCallback = (err) ->
if err then errCallback err
else Router.go 'home'; Meteor.unsubscribe "my-notes"
@ -91,18 +85,18 @@ errCallback = (err) ->
showError msg: err.reason
else showErrror msg: err
# Menu
# 3 Buttons navigation Menu
Template.menu.events
'click .go-home': -> Router.go 'home'
'click .go-account': -> Router.go 'account'
'click .go-archive': -> Router.go 'archive'
# User Interface
# Account Page
Template.account.events
'click #btn-logout': (e,template) -> Meteor.logout logoutCallback
'click #btn-delete-me': -> deleteAccount()
# Notes template
# Notes list
Template.notelist.active = ->
return no unless Router.current() and Router.current().data()
return @_id is Router.current().data()._id
@ -157,13 +151,11 @@ saveCurrentNote = (t,e) ->
content: t.find('.area').value
date: t.find('.date').value
Template.editor.events
'click .close-editor': ->
Router.go 'notes'
#if Router.current().path.startsWith '/note' then Router.go 'notes'
'click .close-editor': -> Router.go 'notes'
'click .save-editor': (e,t) -> saveCurrentNote t
'keypress .title': (e,t) -> saveCurrentNote t, e
# Notifications
# Notifications (not used yet)
alerts = []
alertDep = new Deps.Dependency
# Show a notification
@ -191,7 +183,7 @@ clearError = -> shownError = undefined; errorDep.changed()
Template.error.error = -> errorDep.depend(); shownError
Template.error.events 'click .close': -> clearError()
# Verify Email
# Verify Email page
Template.verifyEmail.events
'click #btn-verify': (e,template) ->
t = template.find('#token-field').value; t = t.split("/")
@ -218,7 +210,7 @@ Template.login.events
'keypress .login': (e,template) -> loginRequest e,template
'click #login-btn': (e,template) -> loginRequest null,template
# Register
# New Account page
registerRequest = (e,template) ->
if e and e.keyCode isnt 13 then return
mail = template.find('#r-mail').value; pass = template.find('#r-pass').value

View File

@ -1,3 +1,4 @@
/* Homework CSS File. I'm sorry it's a mess... */
/* Generics and bootstrap classes */
input {
text-align:center;

View File

@ -1,22 +1,6 @@
<!-- Homework UI Templates -->
<template name="layout">
<div class="container">
<div class="page-header">
<h1 id="title">Homework<br>
<small>management for students</small>
</h1>
</div>
{{> yield region='outside'}}
<div class="center-block" id="ui-container">
{{> yield}}
</div>
<hr>
<div class="center-block" align="center">{{> footer}}</div>
</div>
{{> ribbon}}
</template>
<!-- 3 buttons Navigation Menu -->
<template name="menu">
<div align="center" class="menu-container">
<div class="btn-group">
@ -32,15 +16,18 @@
</div></div>
</template>
<!-- /notes and /archive -->
<template name="notes">{{> error }} {{> editor }} {{> notelist }} {{> menu}}</template>
<template name="archive">{{> error}} {{> archivedlist }} {{> menu }}</template>
<!-- Note Adder -->
<template name="noteadder">
<div align="center">
<input type="text" id="newNote" class="form-control" placeholder="Add new note">
</div>
</template>
<!-- Note List (seen at /notes) -->
<template name="notelist">
<div class="list-group">
{{#each notelist}}
@ -62,6 +49,7 @@
{{> noteadder }}
</template>
<!-- Archive List (seen at /archive) -->
<template name="archivedlist">
{{#unless empty}}
<p align="center" class="lead">This is your archive.</p>
@ -88,6 +76,7 @@
{{/if}}
</template>
<!-- Note Editor (seen at /notes/:_id) -->
<template name="editor">
{{#if _id}}
<div class="panel panel-info">
@ -108,6 +97,7 @@
{{/if}}
</template>
<!-- /login -->
<template name="login">
<div align="center">
<h3 class="cool-header"><i class="fa fa-sign-in fa-2x"></i><br>Sign In</h3>
@ -129,6 +119,7 @@
</div>
</template>
<!-- /register -->
<template name="register">
<div align="center">
<h3 class="cool-header"><i class="fa fa-user fa-2x"></i><br>New Account</h3>
@ -148,6 +139,7 @@
</div>
</template>
<!-- /account -->
<template name="account">
<div align="center">
<h3 class="cool-header"><i class="fa fa-user fa-2x"></i><br>{{email}}</h3>
@ -163,6 +155,7 @@
</div>
</template>
<!-- /verify -->
<template name="verifyEmail">
<div align="center">
<h3 class="cool-header"><i class="fa fa-envelope fa-2x"></i><br>
@ -183,6 +176,7 @@
</div>
</template>
<!-- Notification list. It doesn't show anything unless there are notifications -->
<template name="notifications">
{{#each notification}}
<div class="alert alert-{{type}} notification">
@ -192,6 +186,7 @@
{{/each}}
</template>
<!-- Shows an Error if there is one. It's dismissable -->
<template name="error">
{{#if error}}
<div align="center"><div class="alert alert-{{error.type}} error">
@ -201,6 +196,7 @@
{{/if}}
</template>
<!-- Shows the "fork me on github" ribbon -->
<template name="ribbon">
<div class="github-fork-ribbon-wrapper right">
<div class="github-fork-ribbon">
@ -209,12 +205,14 @@
</div>
</template>
<!-- Shows a spinning gear -->
<template name="loading">
<div align="center" class="spinning-cog">
<i class="fa fa-cog fa-spin fa-3x"></i>
</div>
</template>
<!-- Footer (used in 'template') -->
<template name="footer">
<p>This app is <a href="https://en.wikipedia.org/wiki/Free_software">Free Software</a>, under the <a href="http://opensource.org/licenses/MIT">MIT License</a></p>
<p>Built by Enrico Fasoli</p>
@ -223,6 +221,7 @@
<a class="custom-link" href="http://github.com/fazo96"><i class="fa fa-github fa-2x"></i></a>
</template>
<!-- 404 -->
<template name="404">
<div align="center">
<h1><i class="fa fa-exclamation-triangle fa-2x"></i><br>
@ -233,6 +232,7 @@
</div>
</template>
<!-- Homepage -->
<template name="homepage">
<div align="center"><i class="fa fa-book fa-5x"></i></div>
<p align="center" style="margin-top: 20px" class="lead">A fast, free, organized way to manage your school tasks.</p>
@ -264,3 +264,21 @@
</div>
{{/unless}}
</template>
<!-- Layout for all the pages -->
<template name="layout">
<div class="container">
<div class="page-header">
<h1 id="title">Homework<br>
<small>management for students</small>
</h1>
</div>
{{> yield region='outside'}}
<div class="center-block" id="ui-container">
{{> yield}}
</div>
<hr>
<div class="center-block" align="center">{{> footer}}</div>
</div>
{{> ribbon}}
</template>

View File

@ -1,20 +1,23 @@
# Homework - Server side accounts code
# Regular Expression to see if an email can be valid
validateEmail = (email) ->
x = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
x.test email
Accounts.validateNewUser (user) ->
mail = user.emails[0].address
if Match.test(mail,String) is no or validateEmail(mail) is no
throw new Meteor.Error 403, "Invalid Email"
return yes
Accounts.config {
sendVerificationEmail: true
loginExpirationInDays: 1
}
# Code that checks if a new user request is valid
Accounts.validateNewUser (user) ->
mail = user.emails[0].address
if Match.test(mail,String) is no or validateEmail(mail) is no
throw new Meteor.Error 403, "Invalid Email"
return yes
# Email configuration code
Accounts.emailTemplates.siteName = "Homework App"
Accounts.emailTemplates.verifyEmail.text = (user,url) ->
urlist = url.split('/'); token = urlist[urlist.length-1]

View File

@ -29,6 +29,7 @@ notes.allow insert: isUsers, update: isUsers, remove: isUsers
# Methods that the clients can invoke
Meteor.methods
# Request another confirmation email.
resendConfirmEmail: ->
u = getUser(@userId)
if not u
@ -40,6 +41,7 @@ Meteor.methods
else
console.log "User "+u.emails[0].address+" already validated."
return no
# Request user's account to be deleted
deleteMe: ->
if @userId
Meteor.users.remove @userId
@ -47,4 +49,5 @@ Meteor.methods
Meteor.users.update {_id: @userId},
{$set : { "resume.loginTokens" : [] } }, { multi: yes }
return yes
else no
no
version: -> "1.0" # Request server version number.