diff --git a/client/controllers/authenticated/header.coffee b/client/controllers/authenticated/header.coffee deleted file mode 100644 index 790d855..0000000 --- a/client/controllers/authenticated/header.coffee +++ /dev/null @@ -1,26 +0,0 @@ -### - Controller: Header - Template: /client/includes/_header.html -### - -# Created -Template.header.created = -> - # Code to run when template is created goes here. - -# Rendered -Template.header.rendered = -> - # Code to run when template is rendered goes here. - -# Helpers -Template.header.helpers( - example: -> - # Code to run for helper function. -) - -# Events -Template.header.events( - 'click .logout': (e,t) -> - Meteor.logout((error)-> - alert error.reason if error - ) -) diff --git a/client/controllers/authenticated/header.js b/client/controllers/authenticated/header.js new file mode 100644 index 0000000..b05e0cf --- /dev/null +++ b/client/controllers/authenticated/header.js @@ -0,0 +1,44 @@ +/* +* Controller: Header +* Template: /client/includes/_header.html +*/ + +/* +* Created +*/ + +Template.header.created = function(){ + // Code to run when template is created goes here. +} + +/* +* Rendered +*/ + +Template.header.rendered = function() { + // Code to run when template is rendered goes here. +} + +/* +* Helpers +*/ + +Template.header.helpers({ + example: function(){ + // Code to run for helper function. + } +}); + +/* +* Events +*/ + +Template.header.events({ + 'click .logout': function(){ + Meteor.logout(function(error){ + if(error){ + alert(error.reason); + } + }); + } +}); diff --git a/client/controllers/public/login.coffee b/client/controllers/public/login.coffee deleted file mode 100644 index dd2dff4..0000000 --- a/client/controllers/public/login.coffee +++ /dev/null @@ -1,48 +0,0 @@ -### - Controller: Login - Template: /client/views/public/login.html -### - -# Created -Template.login.created = -> - # Code to run when template is created goes here. - -# Rendered -Template.login.rendered = -> - $('#application-login').validate( - rules: - emailAddress: - required: true - email: true - password: - required: true - messages: - emailAddress: - required: "Please enter your email address to login." - email: "Please enter a valid email address." - password: - required: "Please enter your password to login." - submitHandler: -> - # Grab the user's details. - user = - email: $('[name="emailAddress"]').val() - password: $('[name="password"]').val() - - # Log the user in. - Meteor.loginWithPassword(user.email, user.password, (error)-> - alert error.reason if error - ) - ) - -# Helpers -Template.login.helpers( - example: -> - # Code to run for helper function. -) - -# Events -Template.login.events( - 'submit form': (e,t) -> - # Prevent form from submitting. - e.preventDefault() -) diff --git a/client/controllers/public/login.js b/client/controllers/public/login.js new file mode 100644 index 0000000..e171458 --- /dev/null +++ b/client/controllers/public/login.js @@ -0,0 +1,74 @@ +/* +* Controller: Login +* Template: /client/views/public/login.html +*/ + +/* +* Created +*/ + +Template.login.created = function(){ + // Code to run when template is created goes here. +} + +/* +* Rendered +*/ + +Template.login.rendered = function(){ + $('#application-login').validate({ + rules: { + emailAddress: { + required: true, + email: true + }, + password: { + required: true + } + }, + messages: { + emailAddress: { + required: "Please enter your email address to login.", + email: "Please enter a valid email address." + }, + password: { + required: "Please enter your password to login." + } + }, + submitHandler: function(){ + // Grab the user's details. + user = { + email: $('[name="emailAddress"]').val(), + password: $('[name="password"]').val() + } + + // Log the user in. + Meteor.loginWithPassword(user.email, user.password, function(error){ + if(error){ + alert(error.reason); + } + }); + } + }); +} + +/* +* Helpers +*/ + +Template.login.helpers({ + example: function(){ + // Code to run for helper function. + } +}); + +/* +* Events +*/ + +Template.login.events({ + 'submit form': function(e){ + // Prevent form from submitting. + e.preventDefault(); + } +}); diff --git a/client/controllers/public/recover-password.coffee b/client/controllers/public/recover-password.coffee deleted file mode 100644 index cb6332b..0000000 --- a/client/controllers/public/recover-password.coffee +++ /dev/null @@ -1,42 +0,0 @@ -### - Controller: Recover Password - Template: /client/views/public/recover-password.html -### - -# Created -Template.recoverPassword.created = -> - # Code to run when template is created goes here. - -# Rendered -Template.recoverPassword.rendered = -> - $('#application-recover-password').validate( - rules: - emailAddress: - required: true - email: true - messages: - emailAddress: - required: "Please enter your email address to recover your password." - email: "Please enter a valid email address." - submitHandler: -> - # Grab the user's details. - email = $('[name="emailAddress"]').val() - - # Call the send reset password email method. - Accounts.forgotPassword(email: email, (error)-> - alert error.reason if error - ) - ) - -# Helpers -Template.recoverPassword.helpers( - example: -> - # Code to run for helper function. -) - -# Events -Template.recoverPassword.events( - 'submit form': (e) -> - # Prevent form from submitting. - e.preventDefault() -) diff --git a/client/controllers/public/recover-password.js b/client/controllers/public/recover-password.js new file mode 100644 index 0000000..c68db49 --- /dev/null +++ b/client/controllers/public/recover-password.js @@ -0,0 +1,66 @@ +/* +* Controller: Recover Password +* Template: /client/views/public/recover-password.html +*/ + +/* +* Created +*/ + +Template.recoverPassword.created = function(){ + // Code to run when template is created goes here. +} + +/* +* Rendered +*/ + + +Template.recoverPassword.rendered = function(){ + $('#application-recover-password').validate({ + rules: { + emailAddress: { + required: true, + email: true + } + }, + messages: { + emailAddress: { + required: "Please enter your email address to recover your password.", + email: "Please enter a valid email address." + } + }, + submitHandler: function(){ + // Grab the user's email address. + var email = $('[name="emailAddress"]').val(); + + // Call the send reset password email method. + Accounts.forgotPassword({email: email}, function(error){ + if(error){ + alert(error.reason); + } + }); + } + }); +} + +/* +* Helpers +*/ + +Template.recoverPassword.helpers({ + example: function(){ + // Code to run for helper function. + } +}); + +/* +* Events +*/ + +Template.recoverPassword.events({ + 'submit form': function(e){ + // Prevent form from submitting. + e.preventDefault(); + } +}); diff --git a/client/controllers/public/reset-password.coffee b/client/controllers/public/reset-password.coffee deleted file mode 100644 index 49333a8..0000000 --- a/client/controllers/public/reset-password.coffee +++ /dev/null @@ -1,55 +0,0 @@ -### - Controller: Reset Password - Template: /client/views/public/reset-password.html -### - -# Created -Template.resetPassword.created = -> - # Code to run when template is created goes here. - -# Rendered -Template.resetPassword.rendered = -> - $('#application-reset-password').validate( - rules: - newPassword: - required: true - minlength: 6 - repeatNewPassword: - required: true - minlength: 6 - equalTo: "[name='newPassword']" - messages: - newPassword: - required: "Please enter a new password." - minlength: "Please use at least six characters." - repeatNewPassword: - required: "Please repeat your new password." - equalTo: "Your password do not match. Please try again." - submitHandler: -> - # Grab the user's reset token and new password. - token = Session.get 'resetPasswordToken' - password = - newPassword: $('[name="newPassword"]').val() - repeatPassword: $('[name="repeatNewPassword"]').val() - - # Reset the user's password. - Accounts.resetPassword(token, password.newPassword, (error)-> - if error - alert error.reason - else - Session.set 'resetPasswordToken', null - ) - ) - -# Helpers -Template.resetPassword.helpers( - example: -> - # Code to run for helper function. -) - -# Events -Template.resetPassword.events( - 'submit form': (e) -> - # Prevent form from submitting. - e.preventDefault() -) diff --git a/client/controllers/public/reset-password.js b/client/controllers/public/reset-password.js new file mode 100644 index 0000000..c15a2fd --- /dev/null +++ b/client/controllers/public/reset-password.js @@ -0,0 +1,77 @@ +/* +* Controller: Reset Password +* Template: /client/views/public/reset-password.html +*/ + +/* +* Created +*/ + +Template.resetPassword.created = function(){ + // Code to run when template is created goes here. +} + +/* +* Rendered +*/ + +Template.resetPassword.rendered = function(){ + $('#application-reset-password').validate({ + rules: { + newPassword: { + required: true, + minlength: 6 + }, + repeatNewPassword: { + required: true, + minlength: 6, + equalTo: "[name='newPassword']" + } + }, + messages: { + newPassword: { + required: "Please enter a new password.", + minlength: "Please use at least six characters." + }, + repeatNewPassword: { + required: "Please repeat your new password.", + equalTo: "Your password do not match. Please try again." + } + }, + submitHandler: function(){ + // Grab the user's reset token and new password. + var token = Session.get('resetPasswordToken'), + password = $('[name="newPassword"]').val(); + + // Reset the user's password. + Accounts.resetPassword(token, password, function(error){ + if(error){ + alert(error.reason); + } else { + Session.set('resetPasswordToken', null); + } + }); + } + }); +} + +/* +* Helpers +*/ + +Template.resetPassword.helpers({ + example: function(){ + // Code to run for helper function. + } +}); + +/* +* Events +*/ + +Template.resetPassword.events({ + 'submit form': function(e){ + // Prevent form from submitting. + e.preventDefault(); + } +}); diff --git a/client/controllers/public/signup.coffee b/client/controllers/public/signup.coffee deleted file mode 100644 index 45cd10a..0000000 --- a/client/controllers/public/signup.coffee +++ /dev/null @@ -1,50 +0,0 @@ -### - Controller: Signup - Template: /client/views/public/signup.html -### - -# Created -Template.signup.created = -> - # Code to run when template is created goes here. - -# Rendered -Template.signup.rendered = -> - $('#application-signup').validate( - rules: - emailAddress: - required: true - email: true - password: - required: true - minlength: 6 - messages: - emailAddress: - required: "Please enter your email address to sign up." - email: "Please enter a valid email address." - password: - required: "Please enter a password to sign up." - minlength: "Please use at least six characters." - submitHandler: -> - # Grab the user's details. - user = - email: $('[name="emailAddress"]').val() - password: $('[name="password"]').val() - - # Create the user's account. - Accounts.createUser({email: user.email, password: user.password}, (error)-> - alert error.reason if error - ) - ) - -# Helpers -Template.signup.helpers( - example: -> - # Code to run for helper function. -) - -# Events -Template.signup.events( - 'submit form': (e) -> - # Prevent form from submitting. - e.preventDefault() -) diff --git a/client/controllers/public/signup.js b/client/controllers/public/signup.js new file mode 100644 index 0000000..0498a91 --- /dev/null +++ b/client/controllers/public/signup.js @@ -0,0 +1,76 @@ +/* +* Controller: Signup +* Template: /client/views/public/signup.html +*/ + +/* +* Created +*/ + +Template.signup.created = function(){ + // Code to run when template is created goes here. +} + +/* +* Rendered +*/ + +Template.signup.rendered = function(){ + $('#application-signup').validate({ + rules: { + emailAddress: { + required: true, + email: true + }, + password: { + required: true, + minlength: 6 + } + }, + messages: { + emailAddress: { + required: "Please enter your email address to sign up.", + email: "Please enter a valid email address." + }, + password: { + required: "Please enter a password to sign up.", + minlength: "Please use at least six characters." + } + }, + submitHandler: function(){ + // Grab the user's details. + user = { + email: $('[name="emailAddress"]').val(), + password: $('[name="password"]').val() + } + + // Create the user's account. + Accounts.createUser({email: user.email, password: user.password}, function(error){ + if(error){ + alert(error.reason); + } + }); + } + }); +} + +/* +* Helpers +*/ + +Template.signup.helpers({ + example: function(){ + // Code to run for helper function. + } +}); + +/* +* Events +*/ + +Template.signup.events({ + 'submit form': function(e){ + // Prevent form from submitting. + e.preventDefault(); + } +}); diff --git a/client/helpers/helpers-ui.coffee b/client/helpers/helpers-ui.coffee deleted file mode 100644 index 01a7881..0000000 --- a/client/helpers/helpers-ui.coffee +++ /dev/null @@ -1,13 +0,0 @@ -### - UI Helpers - Define UI helpers for common template functionality. -### - -# Current Route -# Return an active class if the currentRoute session variable name -# (set in the appropriate file in /client/routes/) is equal to the name passed -# to the helper in the template. - -UI.registerHelper('currentRoute', (route) -> - if Session.equals 'currentRoute', route then 'active' else '' -) diff --git a/client/helpers/helpers-ui.js b/client/helpers/helpers-ui.js new file mode 100644 index 0000000..7a3e6eb --- /dev/null +++ b/client/helpers/helpers-ui.js @@ -0,0 +1,15 @@ +/* +* UI Helpers +* Define UI helpers for common template functionality. +*/ + +/* +* Current Route +* Return an active class if the currentRoute session variable name +* (set in the appropriate file in /client/routes/) is equal to the name passed +* to the helper in the template. +*/ + +UI.registerHelper('currentRoute', function(route){ + Session.equals('currentRoute', route) ? 'active' : ''; +}); diff --git a/client/routes/filters.coffee b/client/routes/filters.coffee deleted file mode 100644 index d9d936c..0000000 --- a/client/routes/filters.coffee +++ /dev/null @@ -1,43 +0,0 @@ -### - Route Filters - Filters for managing user access to application routes. -### - -# Define Filters - -### - Filter: Check if a User is Logged In - If a user is not logged in and attempts to go to an authenticated route, - re-route them to the login screen. -### -checkUserLoggedIn = -> - if not Meteor.loggingIn() and not Meteor.user() - Router.go '/login' - else - @next() - -### - Filter: Check if a User Exists - If a user is logged in and attempts to go to a public route, re-route - them to the main "logged in" screen. -### -userAuthenticated = -> - if not Meteor.loggingIn() and Meteor.user() - Router.go '/' - else - @next() - -# Run Filters -Router.onBeforeAction checkUserLoggedIn, except: [ - 'signup', - 'login', - 'recover-password', - 'reset-password' -] - -Router.onBeforeAction userAuthenticated, only: [ - 'signup', - 'login', - 'recover-password', - 'reset-password' -] diff --git a/client/routes/filters.js b/client/routes/filters.js new file mode 100644 index 0000000..67fd089 --- /dev/null +++ b/client/routes/filters.js @@ -0,0 +1,58 @@ +/* +* Route Filters +* Filters for managing user access to application routes. +*/ + +/* +* Define Filters +*/ + +/* +* Filter: Check if a User is Logged In +* If a user is not logged in and attempts to go to an authenticated route, +* re-route them to the login screen. +*/ + +checkUserLoggedIn = function(){ + if( !Meteor.loggingIn() && !Meteor.user() ) { + Router.go('/login'); + } else { + this.next(); + } +} + +/* +* Filter: Check if a User Exists +* If a user is logged in and attempts to go to a public route, re-route +* them to the main "logged in" screen. +*/ + +userAuthenticated = function(){ + if( !Meteor.loggingIn() && Meteor.user() ){ + Router.go('/'); + } else { + this.next(); + } +} + +/* +* Run Filters +*/ + +Router.onBeforeAction(checkUserLoggedIn, { + except: [ + 'signup', + 'login', + 'recover-password', + 'reset-password' + ] +}); + +Router.onBeforeAction(userAuthenticated, { + only: [ + 'signup', + 'login', + 'recover-password', + 'reset-password' + ] +}); diff --git a/client/routes/routes-authenticated.coffee b/client/routes/routes-authenticated.coffee deleted file mode 100644 index 39f6f1f..0000000 --- a/client/routes/routes-authenticated.coffee +++ /dev/null @@ -1,7 +0,0 @@ -Router.route('index', - path: '/' - template: 'index' - onBeforeAction: -> - # Code to run before route goes here. - @next() -) diff --git a/client/routes/routes-authenticated.js b/client/routes/routes-authenticated.js new file mode 100644 index 0000000..3636a47 --- /dev/null +++ b/client/routes/routes-authenticated.js @@ -0,0 +1,13 @@ +/* +* Routes: Authenticated +* Routes that are only visible to authenticated users. +*/ + +Router.route('index', { + path: '/', + template: 'index', + onBeforeAction: function(){ + // Code to run before route goes here. + this.next(); + } +}); diff --git a/client/routes/routes-global.coffee b/client/routes/routes-global.coffee deleted file mode 100644 index f353f9c..0000000 --- a/client/routes/routes-global.coffee +++ /dev/null @@ -1,4 +0,0 @@ -Router.configure( - notFoundTemplate: 'notFound' - layoutTemplate: 'layoutDefault' -) diff --git a/client/routes/routes-global.js b/client/routes/routes-global.js new file mode 100644 index 0000000..0bac5a1 --- /dev/null +++ b/client/routes/routes-global.js @@ -0,0 +1,9 @@ +/* +* Routes: Global +* Global router configurations that apply to the entire application. +*/ + +Router.configure({ + notFoundTemplate: 'notFound', + layoutTemplate: 'layoutDefault' +}); diff --git a/client/routes/routes-public.coffee b/client/routes/routes-public.coffee deleted file mode 100644 index 1659363..0000000 --- a/client/routes/routes-public.coffee +++ /dev/null @@ -1,32 +0,0 @@ -Router.route('signup', - path: '/signup' - template: 'signup' - onBeforeAction: -> - Session.set 'currentRoute', 'signup' - @next() -) - -Router.route('login', - path: '/login' - template: 'login' - onBeforeAction: -> - Session.set 'currentRoute', 'login' - @next() -) - -Router.route('recover-password', - path: '/recover-password' - template: 'recoverPassword' - onBeforeAction: -> - Session.set 'currentRoute', 'recover-password' - @next() -) - -Router.route('reset-password', - path: '/reset-password/:token' - template: 'resetPassword' - onBeforeAction: -> - Session.set 'currentRoute', 'reset-password' - Session.set 'resetPasswordToken', @params.token - @next() -) diff --git a/client/routes/routes-public.js b/client/routes/routes-public.js new file mode 100644 index 0000000..b5340a1 --- /dev/null +++ b/client/routes/routes-public.js @@ -0,0 +1,41 @@ +/* +* Routes: Public +* Routes that are visible to all (public) users. +*/ + +Router.route('signup', { + path: '/signup', + template: 'signup', + onBeforeAction: function(){ + Session.set('currentRoute', 'signup'); + this.next(); + } +}); + +Router.route('login', { + path: '/login', + template: 'login', + onBeforeAction: function(){ + Session.set('currentRoute', 'login'); + this.next(); + } +}); + +Router.route('recover-password', { + path: '/recover-password', + template: 'recoverPassword', + onBeforeAction: function(){ + Session.set('currentRoute', 'recover-password'); + this.next(); + } +}); + +Router.route('reset-password', { + path: '/reset-password/:token', + template: 'resetPassword', + onBeforeAction: function() { + Session.set('currentRoute', 'reset-password'); + Session.set('resetPasswordToken', this.params.token); + this.next(); + } +}); diff --git a/collections/example.coffee b/collections/example.coffee deleted file mode 100644 index 4639784..0000000 --- a/collections/example.coffee +++ /dev/null @@ -1,25 +0,0 @@ -@Example = new Meteor.Collection 'example' - -# Allow -Example.allow - insert: (userId, doc) -> - # ... - update: (userId, doc, fields, modifier) -> - # ... - remove: (userId, doc) -> - # ... - fetch: ['owner'], - transform: () -> - # ... - -# Deny -Example.deny - insert: (userId, doc) -> - # ... - update: (userId, doc, fields, modifier) -> - # ... - remove: (userId, doc) -> - # ... - fetch: ['locked'] - transform: () -> - # ... diff --git a/collections/example.js b/collections/example.js new file mode 100644 index 0000000..5fcf99b --- /dev/null +++ b/collections/example.js @@ -0,0 +1,33 @@ +Example = new Meteor.Collection('example'); + +/* +* Allow +*/ + +Example.allow({ + insert: function(userId, doc){ + // Add your rules here. + }, + update: function(userId, doc, fields, modifier){ + // Add your rules here. + }, + remove: function(userId, doc){ + // Add your rules here. + } +}); + +/* +* Deny +*/ + +Example.deny({ + insert: function(userId, doc){ + // Add your rules here. + }, + update: function(userId, doc, fields, modifier){ + // Add your rules here. + }, + remove: function(userId, doc){ + // Add your rules here. + } +}); diff --git a/server/admin/startup.coffee b/server/admin/startup.coffee deleted file mode 100644 index 1b3994f..0000000 --- a/server/admin/startup.coffee +++ /dev/null @@ -1,29 +0,0 @@ -### - Startup - Collection of methods and functions to run on server startup. -### - -# Generate Test Accounts -# Creates a collection of test accounts automatically on startup. - -# Create an array of user accounts. -users = [ - { name: "Admin", email: "admin@admin.com", password: "password" } -] - -# Loop through array of user accounts. -for user in users - - # Check if the user already exists in the DB. - checkUser = Meteor.users.findOne({"emails.address": user.email}); - - # If an existing user is not found, create the account. - if not checkUser - - id = Accounts.createUser( - email: user.email - password: user.password - profile: - name: user.name - ) - diff --git a/server/admin/startup.js b/server/admin/startup.js new file mode 100644 index 0000000..63fd8c8 --- /dev/null +++ b/server/admin/startup.js @@ -0,0 +1,32 @@ +/* +* Startup +* Collection of methods and functions to run on server startup. +*/ + +/* +* Generate Test Accounts +* Creates a collection of test accounts automatically on startup. +*/ + +// Create an array of user accounts. +var users = [ + { name: "Admin", email: "admin@admin.com", password: "password" } +] + +// Loop through array of user accounts. +for(i=0; i < users.length; i++){ + // Check if the user already exists in the DB. + var userEmail = users[i].email, + checkUser = Meteor.users.findOne({"emails.address": userEmail}); + + // If an existing user is not found, create the account. + if( !checkUser ){ + Accounts.createUser({ + email: userEmail, + password: users[i].password, + profile: { + name: users[i].name + } + }); + } +} diff --git a/server/email/templates/reset-password.coffee b/server/email/templates/reset-password.coffee deleted file mode 100644 index f11cd44..0000000 --- a/server/email/templates/reset-password.coffee +++ /dev/null @@ -1,18 +0,0 @@ -### - Reset Password Email Template - Override Meteor defaults when sending a reset password email. -### - -# Set name and from email. -Accounts.emailTemplates.resetPassword.siteName = "Application Name" -Accounts.emailTemplates.resetPassword.from = "Application Admin Email " - -# Set a subject for the reset password email. -Accounts.emailTemplates.resetPassword.subject = (user) -> - "[Application Name] Reset Your Password" - -# Set the body of the reset password email. -Accounts.emailTemplates.resetPassword.text = (user, url) -> - email = user.emails[0].address - removeHash = url.replace('#/', '') - "A password reset has been requested for the account related to this address(#{email}). To reset the password, visit the following link:\n\n #{removeHash}\n\n If you did not request this reset, please ignore this email. If you feel something is wrong, please contact support: admin@application.com." diff --git a/server/email/templates/reset-password.js b/server/email/templates/reset-password.js new file mode 100644 index 0000000..77dd87d --- /dev/null +++ b/server/email/templates/reset-password.js @@ -0,0 +1,20 @@ +/* +* Reset Password Email Template +* Override Meteor defaults when sending a reset password email. +*/ + +// Set name and from email. +Accounts.emailTemplates.resetPassword.siteName = "Application Name"; +Accounts.emailTemplates.resetPassword.from = "Application Admin Email "; + +// Set a subject for the reset password email. +Accounts.emailTemplates.resetPassword.subject = function(user){ + return "[Application Name] Reset Your Password"; +} + +// Set the body of the reset password email. +Accounts.emailTemplates.resetPassword.text = function(user, url){ + var email = user.emails[0].address, + removeHash = url.replace('#/', ''); + return "A password reset has been requested for the account related to this address(" + email + "). To reset the password, visit the following link:\n\n" + removeHash + "\n\n If you did not request this reset, please ignore this email. If you feel something is wrong, please contact support: admin@application.com." +}