From 0ccda777550836bc605835b2289dc62e04c2e66f Mon Sep 17 00:00:00 2001 From: Ryan Glover Date: Sat, 26 Sep 2015 17:47:55 -0500 Subject: [PATCH] add support for ES2015 and refactor existing code - Refactor all ES5 code to use ES2015 patterns. - Refactor functionality of accounts functionality to use module patterns. - Clean up template markup. --- .jshintrc | 3 + .meteor/packages | 4 +- .meteor/versions | 2 + both/methods/insert/collection.js | 12 ++++ both/methods/insert/example.js | 20 ------ both/methods/read/collection.js | 13 ++++ both/methods/read/example.js | 22 ------ both/methods/remove/collection.js | 11 +++ both/methods/remove/example.js | 20 ------ both/methods/update/collection.js | 14 ++++ both/methods/update/example.js | 24 ------- both/modules/startup.js | 2 +- both/startup.js | 2 +- client/helpers/template.js | 16 +---- client/modules/login.js | 46 +++++++++++++ client/modules/recover-password.js | 39 +++++++++++ client/modules/reset-password.js | 49 ++++++++++++++ client/modules/signup.js | 50 ++++++++++++++ client/modules/startup.js | 2 +- client/startup.js | 2 +- client/stylesheets/application.scss | 2 + client/stylesheets/objects/_forms.scss | 6 ++ client/templates/authenticated/index.html | 2 +- client/templates/authenticated/index.js | 3 + .../globals/authenticated-navigation.html | 10 +++ client/templates/globals/header.html | 22 ++---- client/templates/globals/header.js | 45 ++----------- client/templates/globals/loading.html | 18 +++++ client/templates/globals/public-navigation.html | 6 ++ client/templates/public/loading.html | 3 - client/templates/public/login.html | 14 ++-- client/templates/public/login.js | 75 +-------------------- client/templates/public/recover-password.html | 14 ++-- client/templates/public/recover-password.js | 68 ++----------------- client/templates/public/reset-password.html | 16 ++--- client/templates/public/reset-password.js | 78 ++-------------------- client/templates/public/signup.html | 14 ++-- client/templates/public/signup.js | 78 ++-------------------- collections/collection.js | 13 ++++ collections/example.js | 39 ----------- collections/users.js | 38 ++--------- server/admin/reset-password.js | 12 ++++ server/admin/startup-functions/browser-policies.js | 9 --- server/admin/startup-functions/test-accounts.js | 29 -------- server/admin/startup.js | 15 ----- server/email/templates/reset-password.js | 20 ------ server/modules/generate-accounts.js | 63 +++++++++++++++++ server/modules/startup.js | 9 ++- server/publications/example.js | 17 ----- server/publications/template.js | 3 + server/startup.js | 2 +- 51 files changed, 458 insertions(+), 638 deletions(-) create mode 100644 .jshintrc create mode 100644 both/methods/insert/collection.js delete mode 100644 both/methods/insert/example.js create mode 100644 both/methods/read/collection.js delete mode 100644 both/methods/read/example.js create mode 100644 both/methods/remove/collection.js delete mode 100644 both/methods/remove/example.js create mode 100644 both/methods/update/collection.js delete mode 100644 both/methods/update/example.js create mode 100644 client/modules/login.js create mode 100644 client/modules/recover-password.js create mode 100644 client/modules/reset-password.js create mode 100644 client/modules/signup.js create mode 100644 client/stylesheets/objects/_forms.scss create mode 100644 client/templates/authenticated/index.js create mode 100644 client/templates/globals/authenticated-navigation.html create mode 100644 client/templates/globals/loading.html create mode 100644 client/templates/globals/public-navigation.html delete mode 100644 client/templates/public/loading.html create mode 100644 collections/collection.js delete mode 100644 collections/example.js create mode 100644 server/admin/reset-password.js delete mode 100644 server/admin/startup-functions/browser-policies.js delete mode 100644 server/admin/startup-functions/test-accounts.js delete mode 100644 server/admin/startup.js delete mode 100644 server/email/templates/reset-password.js create mode 100644 server/modules/generate-accounts.js delete mode 100644 server/publications/example.js create mode 100644 server/publications/template.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..a5aaaed --- /dev/null +++ b/.jshintrc @@ -0,0 +1,3 @@ +{ + "esnext": true +} diff --git a/.meteor/packages b/.meteor/packages index e966eab..d0084ab 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -23,4 +23,6 @@ fourseven:scss standard-minifiers -npm-container \ No newline at end of file +npm-container +ecmascript +digilord:faker diff --git a/.meteor/versions b/.meteor/versions index e12c85d..8f70e51 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -17,6 +17,7 @@ caching-compiler@1.0.0 caching-html-compiler@1.0.1 callback-hook@1.0.4 check@1.0.6 +coffeescript@1.0.9 ddp@1.2.2 ddp-client@1.2.1 ddp-common@1.2.1 @@ -24,6 +25,7 @@ ddp-rate-limiter@1.0.0 ddp-server@1.2.1 deps@1.0.9 diff-sequence@1.0.1 +digilord:faker@1.0.7 ecmascript@0.1.4 ecmascript-collections@0.1.6 ejson@1.0.7 diff --git a/both/methods/insert/collection.js b/both/methods/insert/collection.js new file mode 100644 index 0000000..85224ed --- /dev/null +++ b/both/methods/insert/collection.js @@ -0,0 +1,12 @@ +Meteor.methods({ + insertMethod( argument ) { + check( argument, Object ); + + try { + var documentId = Collection.insert( argument ); + return documentId; + } catch( exception ) { + return exception; + } + } +}); diff --git a/both/methods/insert/example.js b/both/methods/insert/example.js deleted file mode 100644 index 1bc32d0..0000000 --- a/both/methods/insert/example.js +++ /dev/null @@ -1,20 +0,0 @@ -/* -* Methods: Insert - Example -* Example of a method used for inserting into the database. -*/ - -Meteor.methods({ - exampleInsertMethod: function(argument){ - // Check the argument. Assuming an Object type here. - check(argument, Object); - - // Perform the insert. - try { - var exampleId = Example.insert(argument); - return exampleId; - } catch(exception) { - // If an error occurs, return it to the client. - return exception; - } - } -}); diff --git a/both/methods/read/collection.js b/both/methods/read/collection.js new file mode 100644 index 0000000..9450a51 --- /dev/null +++ b/both/methods/read/collection.js @@ -0,0 +1,13 @@ +Meteor.methods({ + readMethod( argument ) { + check( argument, String ); + + var document = Collection.findOne( argument ); + + if ( !document ) { + throw new Meteor.Error( 'document-not-found', 'No documents found matching this query.' ); + } + + return document; + } +}); diff --git a/both/methods/read/example.js b/both/methods/read/example.js deleted file mode 100644 index 1c54af7..0000000 --- a/both/methods/read/example.js +++ /dev/null @@ -1,22 +0,0 @@ -/* -* Methods: Read - Example -* Example of a method used for reading from the database. -*/ - -Meteor.methods({ - exampleReadMethod: function(argument){ - // Check the argument. Assuming a String type here. - check(argument, String); - - // Perform the read. - var exampleItem = Example.findOne(argument); - - // If the read fails (no documents found), throw an error. - if (!exampleItem) { - throw new Meteor.Error(500, 'Error 500: Not Found', 'No documents found.'); - } - - // Return either the result or the error. - return exampleItem; - } -}); diff --git a/both/methods/remove/collection.js b/both/methods/remove/collection.js new file mode 100644 index 0000000..8e1f377 --- /dev/null +++ b/both/methods/remove/collection.js @@ -0,0 +1,11 @@ +Meteor.methods({ + removeMethod( argument ) { + check( argument, String ); + + try { + Collection.remove( argument ); + } catch( exception ) { + return exception; + } + } +}); diff --git a/both/methods/remove/example.js b/both/methods/remove/example.js deleted file mode 100644 index 9c8058e..0000000 --- a/both/methods/remove/example.js +++ /dev/null @@ -1,20 +0,0 @@ -/* -* Methods: Remove - Example -* Example of a method used for removing a document from the database. -*/ - -Meteor.methods({ - exampleRemoveMethod: function(argument){ - // Check the argument. Assuming a String type here. - check(argument, String); - - // Perform the remove. - try { - var exampleId = Example.remove(argument); - return exampleId; - } catch(exception) { - // If an error occurs, return it to the client. - return exception; - } - } -}); diff --git a/both/methods/update/collection.js b/both/methods/update/collection.js new file mode 100644 index 0000000..d392721 --- /dev/null +++ b/both/methods/update/collection.js @@ -0,0 +1,14 @@ +Meteor.methods({ + updateMethod( argument ) { + check( argument, Object ); + + try { + var documentId = Collection.update( argument._id, { + $set: { 'key': argument.key } + }); + return documentId; + } catch( exception ) { + return exception; + } + } +}); diff --git a/both/methods/update/example.js b/both/methods/update/example.js deleted file mode 100644 index a7cacd3..0000000 --- a/both/methods/update/example.js +++ /dev/null @@ -1,24 +0,0 @@ -/* -* Methods: Update - Example -* Example of a method used for updating a document in the database. -*/ - -Meteor.methods({ - exampleUpdateMethod: function(argument){ - // Check the argument. Assuming an Object type here. - check(argument, Object); - - // Perform the update. - try { - var exampleId = Example.update(argument._id, { - $set: { - "someKey": argument.someKey - } - }); - return exampleId; - } catch(exception) { - // If an error occurs, return it to the client. - return exception; - } - } -}); diff --git a/both/modules/startup.js b/both/modules/startup.js index adbe072..34a2173 100644 --- a/both/modules/startup.js +++ b/both/modules/startup.js @@ -1,3 +1,3 @@ -var startup = function() {}; +let startup = () => {}; Modules.both.startup = startup; diff --git a/both/startup.js b/both/startup.js index dce5dec..4555fab 100644 --- a/both/startup.js +++ b/both/startup.js @@ -1 +1 @@ -Meteor.startup( function() { Modules.both.startup(); } ); +Meteor.startup( () => Modules.both.startup() ); diff --git a/client/helpers/template.js b/client/helpers/template.js index 89a83cf..efa4026 100644 --- a/client/helpers/template.js +++ b/client/helpers/template.js @@ -1,15 +1,3 @@ -/* -* 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){ - return Session.equals('currentRoute', route) ? 'active' : ''; +Template.registerHelper( 'currentRoute', ( route ) => { + return Session.equals( 'currentRoute', route ) ? 'active' : ''; }); diff --git a/client/modules/login.js b/client/modules/login.js new file mode 100644 index 0000000..c2acba4 --- /dev/null +++ b/client/modules/login.js @@ -0,0 +1,46 @@ +let login = ( options ) => { + _validate( options.form, options.template ); +}; + +let _validate = ( form, template ) => { + $( form ).validate( validation( template ) ); +}; + +let validation = ( template ) => { + return { + rules: { + emailAddress: { + required: true, + email: true + }, + password: { + required: true + } + }, + messages: { + emailAddress: { + required: 'Need an email address here.', + email: 'Is this email address legit?' + }, + password: { + required: 'Need a password here.' + } + }, + submitHandler() { _handleLogin( template ); } + }; +}; + +let _handleLogin = ( template ) => { + let email = template.find( '[name="emailAddress"]' ).value, + password = template.find( '[name="password"]' ).value; + + Meteor.loginWithPassword( email, password, ( error ) => { + if ( error ) { + Bert.alert( error.reason, 'warning' ); + } else { + Bert.alert( 'Logged in!', 'success' ); + } + }); +}; + +Modules.client.login = login; diff --git a/client/modules/recover-password.js b/client/modules/recover-password.js new file mode 100644 index 0000000..831af9d --- /dev/null +++ b/client/modules/recover-password.js @@ -0,0 +1,39 @@ +let recoverPassword = ( options ) => { + _validate( options.form, options.template ); +}; + +let _validate = ( form, template ) => { + $( form ).validate( validation( template ) ); +}; + +let validation = ( template ) => { + return { + rules: { + emailAddress: { + required: true, + email: true + } + }, + messages: { + emailAddress: { + required: 'Need an email address here.', + email: 'Is this email address legit?' + } + }, + submitHandler() { _handleRecovery( template ); } + }; +}; + +let _handleRecovery = ( template ) => { + let email = template.find( '[name="emailAddress"]' ).value; + + Accounts.forgotPassword( { email: email }, ( error ) => { + if ( error ) { + Bert.alert( error.reason, 'warning' ); + } else { + Bert.alert( 'Check your inbox for a reset link!', 'success' ); + } + }); +}; + +Modules.client.recoverPassword = recoverPassword; diff --git a/client/modules/reset-password.js b/client/modules/reset-password.js new file mode 100644 index 0000000..5e7af58 --- /dev/null +++ b/client/modules/reset-password.js @@ -0,0 +1,49 @@ +let resetPassword = ( options ) => { + _validate( options.form, options.template ); +}; + +let _validate = ( form, template ) => { + $( form ).validate( validation( template ) ); +}; + +let validation = ( template ) => { + return { + rules: { + newPassword: { + required: true, + minlength: 6 + }, + repeatNewPassword: { + required: true, + minlength: 6, + equalTo: '[name="newPassword"]' + } + }, + messages: { + newPassword: { + required: "Enter a new password, please.", + minlength: "Use at least six characters, please." + }, + repeatNewPassword: { + required: "Repeat your new password, please.", + equalTo: "Hmm, your passwords don't match. Try again?" + } + }, + submitHandler() { _handleReset( template ); } + }; +}; + +let _handleReset = ( template ) => { + var token = "Test", + password = template.find( '[name="newPassword"]' ).value; + + Accounts.resetPassword( token, password, ( error ) => { + if ( error ) { + Bert.alert( error.reason, 'danger' ); + } else { + Bert.alert( 'Password reset!', 'success' ); + } + }); +}; + +Modules.client.resetPassword = resetPassword; diff --git a/client/modules/signup.js b/client/modules/signup.js new file mode 100644 index 0000000..6834973 --- /dev/null +++ b/client/modules/signup.js @@ -0,0 +1,50 @@ +let signup = ( options ) => { + _validate( options.form, options.template ); +}; + +let _validate = ( form, template ) => { + $( form ).validate( validation( template ) ); +}; + +let validation = ( template ) => { + return { + rules: { + emailAddress: { + required: true, + email: true + }, + password: { + required: true, + minlength: 6 + } + }, + messages: { + emailAddress: { + required: 'Need an email address here.', + email: 'Is this email address legit?' + }, + password: { + required: 'Need a password here.', + minlength: 'Use at least six characters, please.' + } + }, + submitHandler() { _handleSignup( template ); } + }; +}; + +let _handleSignup = ( template ) => { + let user = { + email: template.find( '[name="emailAddress"]' ).value, + password: template.find( '[name="password"]' ).value + }; + + Accounts.createUser( user, ( error ) => { + if ( error ) { + Bert.alert( error.reason, 'danger' ); + } else { + Bert.alert( 'Welcome!', 'success' ); + } + }); +}; + +Modules.client.signup = signup; diff --git a/client/modules/startup.js b/client/modules/startup.js index 5d737f4..68db501 100644 --- a/client/modules/startup.js +++ b/client/modules/startup.js @@ -1,3 +1,3 @@ -var startup = function() {}; +let startup = () => {}; Modules.client.startup = startup; diff --git a/client/startup.js b/client/startup.js index 4db56b0..552c183 100644 --- a/client/startup.js +++ b/client/startup.js @@ -1 +1 @@ -Meteor.startup( function() { Modules.client.startup(); } ); +Meteor.startup( () => Modules.client.startup() ); diff --git a/client/stylesheets/application.scss b/client/stylesheets/application.scss index 5fbade7..08d4bdf 100644 --- a/client/stylesheets/application.scss +++ b/client/stylesheets/application.scss @@ -1,3 +1,5 @@ @import "tools/extends"; +@import "objects/forms"; + @import "components/login"; diff --git a/client/stylesheets/objects/_forms.scss b/client/stylesheets/objects/_forms.scss new file mode 100644 index 0000000..860f974 --- /dev/null +++ b/client/stylesheets/objects/_forms.scss @@ -0,0 +1,6 @@ +label.error { + display: block; + margin-top: 10px; + font-weight: normal; + color: lighten( red, 20% ); +} diff --git a/client/templates/authenticated/index.html b/client/templates/authenticated/index.html index d62b919..7124bdf 100644 --- a/client/templates/authenticated/index.html +++ b/client/templates/authenticated/index.html @@ -1,3 +1,3 @@ diff --git a/client/templates/authenticated/index.js b/client/templates/authenticated/index.js new file mode 100644 index 0000000..c6fea9b --- /dev/null +++ b/client/templates/authenticated/index.js @@ -0,0 +1,3 @@ +Template.index.onCreated( () => { + Template.instance().subscribe( 'template', () => console.log( "Subscribed!" ) ); +}); diff --git a/client/templates/globals/authenticated-navigation.html b/client/templates/globals/authenticated-navigation.html new file mode 100644 index 0000000..612d937 --- /dev/null +++ b/client/templates/globals/authenticated-navigation.html @@ -0,0 +1,10 @@ + diff --git a/client/templates/globals/header.html b/client/templates/globals/header.html index 5ecd284..c582689 100644 --- a/client/templates/globals/header.html +++ b/client/templates/globals/header.html @@ -2,7 +2,7 @@ diff --git a/client/templates/globals/header.js b/client/templates/globals/header.js index 0bd86f7..c000a9d 100644 --- a/client/templates/globals/header.js +++ b/client/templates/globals/header.js @@ -1,45 +1,10 @@ -/* -* Controller: Header -* Template: /client/includes/_header.html -*/ - -/* -* Created -*/ - -Template.header.onCreated(function(){ - // Code to run when template is created goes here. -}); - -/* -* Rendered -*/ - -Template.header.onRendered(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){ - Bert.alert(error.reason, 'danger'); + 'click .logout' () { + Meteor.logout( ( error ) => { + if ( error ) { + Bert.alert( error.reason, 'warning' ); } else { - Bert.alert('Succesfully logged out!', 'success'); + Bert.alert( 'Logged out!', 'success' ); } }); } diff --git a/client/templates/globals/loading.html b/client/templates/globals/loading.html new file mode 100644 index 0000000..e7f7d5d --- /dev/null +++ b/client/templates/globals/loading.html @@ -0,0 +1,18 @@ + diff --git a/client/templates/globals/public-navigation.html b/client/templates/globals/public-navigation.html new file mode 100644 index 0000000..ae15cad --- /dev/null +++ b/client/templates/globals/public-navigation.html @@ -0,0 +1,6 @@ + diff --git a/client/templates/public/loading.html b/client/templates/public/loading.html deleted file mode 100644 index effbcbc..0000000 --- a/client/templates/public/loading.html +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/client/templates/public/login.html b/client/templates/public/login.html index 744999c..33edd66 100644 --- a/client/templates/public/login.html +++ b/client/templates/public/login.html @@ -1,21 +1,21 @@ diff --git a/client/templates/public/login.js b/client/templates/public/login.js index e3e5ec3..412891c 100644 --- a/client/templates/public/login.js +++ b/client/templates/public/login.js @@ -1,76 +1,7 @@ -/* -* Controller: Login -* Template: /client/views/public/login.html -*/ - -/* -* Created -*/ - -Template.login.onCreated(function(){ - // Code to run when template is created goes here. -}); - -/* -* Rendered -*/ - -Template.login.onRendered(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){ - Bert.alert(error.reason, 'danger'); - } else { - Bert.alert('Logged in!', 'success'); - } - }); - } - }); +Template.login.onRendered( () => { + Modules.client.login( { form: "#login", template: Template.instance() } ); }); -/* -* 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(); - } + 'submit form': ( event ) => event.preventDefault() }); diff --git a/client/templates/public/recover-password.html b/client/templates/public/recover-password.html index f6c6e9d..bf118fa 100644 --- a/client/templates/public/recover-password.html +++ b/client/templates/public/recover-password.html @@ -1,17 +1,17 @@ diff --git a/client/templates/public/recover-password.js b/client/templates/public/recover-password.js index c388491..0843e4a 100644 --- a/client/templates/public/recover-password.js +++ b/client/templates/public/recover-password.js @@ -1,68 +1,10 @@ -/* -* Controller: Recover Password -* Template: /client/views/public/recover-password.html -*/ - -/* -* Created -*/ - -Template.recoverPassword.onCreated(function(){ - // Code to run when template is created goes here. -}); - -/* -* Rendered -*/ - - -Template.recoverPassword.onRendered(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){ - Bert.alert(error.reason, 'danger'); - } else { - Bert.alert('Check your inbox for a reset link!', 'success'); - } - }); - } +Template.recoverPassword.onRendered( () => { + Modules.client.recoverPassword({ + form: "#recover-password", + template: Template.instance() }); }); -/* -* 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(); - } + 'submit form': ( event ) => event.preventDefault() }); diff --git a/client/templates/public/reset-password.html b/client/templates/public/reset-password.html index c5c8ded..efbadff 100644 --- a/client/templates/public/reset-password.html +++ b/client/templates/public/reset-password.html @@ -1,21 +1,21 @@ diff --git a/client/templates/public/reset-password.js b/client/templates/public/reset-password.js index e17c7be..a45dc34 100644 --- a/client/templates/public/reset-password.js +++ b/client/templates/public/reset-password.js @@ -1,78 +1,10 @@ -/* -* Controller: Reset Password -* Template: /client/views/public/reset-password.html -*/ - -/* -* Created -*/ - -Template.resetPassword.onCreated(function(){ - // Code to run when template is created goes here. -}); - -/* -* Rendered -*/ - -Template.resetPassword.onRendered(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){ - Bert.alert(error.reason, 'danger'); - } else { - Bert.alert('Password successfully reset!', 'success'); - Session.set('resetPasswordToken', null); - } - }); - } +Template.resetPassword.onRendered( () => { + Modules.client.resetPassword({ + form: "#reset-password", + template: Template.instance() }); }); -/* -* 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(); - } + 'submit form': ( event ) => event.preventDefault() }); diff --git a/client/templates/public/signup.html b/client/templates/public/signup.html index 5a7e961..881729a 100644 --- a/client/templates/public/signup.html +++ b/client/templates/public/signup.html @@ -1,21 +1,21 @@ diff --git a/client/templates/public/signup.js b/client/templates/public/signup.js index 60c3ad1..4aa2ae1 100644 --- a/client/templates/public/signup.js +++ b/client/templates/public/signup.js @@ -1,78 +1,10 @@ -/* -* Controller: Signup -* Template: /client/views/public/signup.html -*/ - -/* -* Created -*/ - -Template.signup.onCreated(function(){ - // Code to run when template is created goes here. -}); - -/* -* Rendered -*/ - -Template.signup.onRendered(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){ - Bert.alert(error.reason, 'danger'); - } else { - Bert.alert('Welcome!', 'success'); - } - }); - } +Template.signup.onRendered( () => { + Modules.client.signup({ + form: "#signup", + template: Template.instance() }); }); -/* -* 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(); - } + 'submit form': ( event ) => event.preventDefault() }); diff --git a/collections/collection.js b/collections/collection.js new file mode 100644 index 0000000..f87337a --- /dev/null +++ b/collections/collection.js @@ -0,0 +1,13 @@ +Collection = new Meteor.Collection( 'collection' ); + +Collection.allow({ + insert: () => false, + update: () => false, + remove: () => false +}); + +Collection.deny({ + insert: () => true, + update: () => true, + remove: () => true +}); diff --git a/collections/example.js b/collections/example.js deleted file mode 100644 index 7dd8f6d..0000000 --- a/collections/example.js +++ /dev/null @@ -1,39 +0,0 @@ -Example = new Meteor.Collection('example'); - -/* -* Allow -*/ - -Example.allow({ - insert: function(){ - // Disallow inserts on the client by default. - return false; - }, - update: function(){ - // Disallow updates on the client by default. - return false; - }, - remove: function(){ - // Disallow removes on the client by default. - return false; - } -}); - -/* -* Deny -*/ - -Example.deny({ - insert: function(){ - // Deny inserts on the client by default. - return true; - }, - update: function(){ - // Deny updates on the client by default. - return true; - }, - remove: function(){ - // Deny removes on the client by default. - return true; - } -}); diff --git a/collections/users.js b/collections/users.js index 1960f10..3c7ca6c 100644 --- a/collections/users.js +++ b/collections/users.js @@ -1,37 +1,11 @@ -/* -* Allow -*/ - Meteor.users.allow({ - insert: function(){ - // Disallow user inserts on the client by default. - return false; - }, - update: function(){ - // Disallow user updates on the client by default. - return false; - }, - remove: function(){ - // Disallow user removes on the client by default. - return false; - } + insert: () => false, + update: () => false, + remove: () => false }); -/* -* Deny -*/ - Meteor.users.deny({ - insert: function(){ - // Deny user inserts on the client by default. - return true; - }, - update: function(){ - // Deny user updates on the client by default. - return true; - }, - remove: function(){ - // Deny user removes on the client by default. - return true; - } + insert: () => true, + update: () => true, + remove: () => true }); diff --git a/server/admin/reset-password.js b/server/admin/reset-password.js new file mode 100644 index 0000000..0846b6b --- /dev/null +++ b/server/admin/reset-password.js @@ -0,0 +1,12 @@ +Accounts.emailTemplates.resetPassword.siteName = () => "Application Name"; +Accounts.emailTemplates.resetPassword.from = () => "Application Name "; +Accounts.emailTemplates.resetPassword.subject = () => "[Application Name] Reset Your Password"; + +Accounts.emailTemplates.resetPassword.text = ( user, url ) => { + let emailAddress = user.emails[0].address, + urlWithoutHash = url.replace( '#/', '' ), + supportEmail = "support@application.com", + emailBody = `A password reset has been requested for the account related to this address (${emailAddress}). To reset the password, visit the following link:\n\n${urlWithoutHash}\n\n If you did not request this reset, please ignore this email. If you feel something is wrong, please contact our support team: ${supportEmail}.`; + + return emailBody; +}; diff --git a/server/admin/startup-functions/browser-policies.js b/server/admin/startup-functions/browser-policies.js deleted file mode 100644 index 55f9e23..0000000 --- a/server/admin/startup-functions/browser-policies.js +++ /dev/null @@ -1,9 +0,0 @@ -/* -* Browser Policies -* Browser policy customizations. -* Documentation: https://atmospherejs.com/meteor/browser-policy -*/ - -customBrowserPolicies = function(){ - // Define any custom browser policies here. -} diff --git a/server/admin/startup-functions/test-accounts.js b/server/admin/startup-functions/test-accounts.js deleted file mode 100644 index c9e516a..0000000 --- a/server/admin/startup-functions/test-accounts.js +++ /dev/null @@ -1,29 +0,0 @@ -/* -* Generate Test Accounts -* Creates a collection of test accounts automatically on startup. -*/ - -generateTestAccounts = function(){ - // 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/admin/startup.js b/server/admin/startup.js deleted file mode 100644 index b920f02..0000000 --- a/server/admin/startup.js +++ /dev/null @@ -1,15 +0,0 @@ -/* -* Startup -* Functions to run on server startup. Note: this file is for calling functions -* only. Define functions in /server/admin/startup-functions. -*/ - -Meteor.startup(function(){ - - // Custom Browser Policies - customBrowserPolicies(); - - // Generate Test Accounts - generateTestAccounts(); - -}); diff --git a/server/email/templates/reset-password.js b/server/email/templates/reset-password.js deleted file mode 100644 index 77dd87d..0000000 --- a/server/email/templates/reset-password.js +++ /dev/null @@ -1,20 +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 = 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." -} diff --git a/server/modules/generate-accounts.js b/server/modules/generate-accounts.js new file mode 100644 index 0000000..3eb6d09 --- /dev/null +++ b/server/modules/generate-accounts.js @@ -0,0 +1,63 @@ +let administrators = [ + { + name: { first: 'Admin', last: 'McAdmin' }, + email: 'admin@admin.com', + password: 'password' + } +]; + +let generateAccounts = () => { + let fakeUserCount = 5, + usersExist = _checkIfAccountsExist( administrators.length + fakeUserCount ); + + if ( !usersExist ) { + _createUsers( administrators ); + _createUsers( _generateFakeUsers( fakeUserCount ) ); + } +}; + +let _checkIfAccountsExist = ( count ) => { + let userCount = Meteor.users.find().count(); + return userCount < count ? false : true; +}; + +let _createUsers = ( users ) => { + for ( let i = 0; i < users.length; i++ ) { + let user = users[ i ], + userExists = _checkIfUserExists( user.email ); + + if ( !userExists ) { + _createUser( user ); + } + } +}; + +let _checkIfUserExists = ( email ) => { + return Meteor.users.findOne( { 'emails.address': email } ); +}; + +let _createUser = ( user ) => { + Accounts.createUser({ + email: user.email, + password: user.password, + profile: { + name: user.name + } + }); +}; + +let _generateFakeUsers = ( count ) => { + let users = []; + + for ( let i = 0; i < count; i++ ) { + users.push({ + name: { first: faker.name.firstName(), last: faker.name.lastName() }, + email: faker.internet.email(), + password: 'password' + }); + } + + return users; +}; + +Modules.server.generateAccounts = generateAccounts; diff --git a/server/modules/startup.js b/server/modules/startup.js index b74ddaa..6a12a24 100644 --- a/server/modules/startup.js +++ b/server/modules/startup.js @@ -1,3 +1,10 @@ -var startup = function() {}; +let startup = () => { + _setBrowserPolicies(); + _generateAccounts(); +}; + +var _setBrowserPolicies = () => {}; + +var _generateAccounts = () => Modules.server.generateAccounts(); Modules.server.startup = startup; diff --git a/server/publications/example.js b/server/publications/example.js deleted file mode 100644 index 237ba1c..0000000 --- a/server/publications/example.js +++ /dev/null @@ -1,17 +0,0 @@ -/* -* Publications: Example -* Data publications for the Example collection. -*/ - -Meteor.publish('examplePublication', function(){ - // If need be, Meteor gives us access to the current user via this.userId. - // Example below shows using this.userId to locate documents where the - // owner field is equal to a userId. Additionally, a fields projection is - // added to specify which fields you want to return (where 1 = true and - // 0 = false). - - var user = this.userId; - var data = Example.find({"owner": user}, {fields: {"owner": 1}}); - - return data; -}); diff --git a/server/publications/template.js b/server/publications/template.js new file mode 100644 index 0000000..f72904f --- /dev/null +++ b/server/publications/template.js @@ -0,0 +1,3 @@ +Meteor.publish( 'template', function() { + return Collection.find( { 'owner': this.userId }, { fields: { 'owner': 1 } } ); +}); diff --git a/server/startup.js b/server/startup.js index 1ccd98f..9299567 100644 --- a/server/startup.js +++ b/server/startup.js @@ -1 +1 @@ -Meteor.startup( function() { Modules.server.startup(); } ); +Meteor.startup( () => Modules.server.startup() ); -- 2.0.0