Commit 7439c59f5fd11d1e89fd283b2e3bfc19f3d9619f
1 parent
cabe1c46e5
Exists in
master
Add in a server-only account creation pattern. Add an index route for once
the user is authenticated (with a template). Update file tree in README. Add an NPM packages package to import NPM modules.
Showing
7 changed files
with
86 additions
and
19 deletions
Show diff stats
README.md
client/controllers/public/login.coffee
... | ... | @@ -19,17 +19,17 @@ Template.login.helpers( |
19 | 19 | |
20 | 20 | # Events |
21 | 21 | Template.login.events( |
22 | - 'submit form': (e) -> | |
22 | + 'submit form': (e,t) -> | |
23 | 23 | |
24 | 24 | # Prevent form from submitting. |
25 | 25 | e.preventDefault() |
26 | 26 | |
27 | 27 | # Grab the user's details. |
28 | 28 | user = |
29 | - email: $('[name="emailAddress"]').val() | |
30 | - password: $('[name="password"]').val() | |
29 | + email: t.find('[name="emailAddress"]').value | |
30 | + password: t.find('[name="password"]').value | |
31 | 31 | |
32 | - # Create the user's account. | |
32 | + # Log the user in. | |
33 | 33 | Meteor.loginWithPassword(user.email, user.password, (error)-> |
34 | 34 | alert error.reason if error |
35 | 35 | ) | ... | ... |
client/controllers/public/signup.coffee
... | ... | @@ -19,18 +19,24 @@ Template.signup.helpers( |
19 | 19 | |
20 | 20 | # Events |
21 | 21 | Template.signup.events( |
22 | - 'submit form': (e) -> | |
22 | + 'submit form': (e,t) -> | |
23 | 23 | |
24 | 24 | # Prevent form from submitting. |
25 | 25 | e.preventDefault() |
26 | 26 | |
27 | 27 | # Grab the user's details. |
28 | 28 | user = |
29 | - email: $('[name="emailAddress"]').val() | |
30 | - password: $('[name="password"]').val() | |
29 | + email: t.find('[name="emailAddress"]').value | |
30 | + password: t.find('[name="password"]').value | |
31 | 31 | |
32 | 32 | # Create the user's account. |
33 | - Accounts.createUser(user, (error)-> | |
34 | - alert error.reason if error | |
35 | - ) | |
33 | + Meteor.call 'createUserAccount', user, (error,response) -> | |
34 | + | |
35 | + # If the account is created successfully, log the user in using the credentials | |
36 | + # from above. | |
37 | + if response.success | |
38 | + Meteor.loginWithPassword(user.email, user.password, (error)-> | |
39 | + alert error.reason if error | |
40 | + ) | |
41 | + | |
36 | 42 | ) | ... | ... |
client/routes/routes-authenticated.coffee
1 | 1 | Router.map(-> |
2 | - ### | |
3 | - @route('exampleAuthenticatedRoute', | |
4 | - path: '/example' | |
5 | - template: 'example' | |
6 | - layoutTemplate: 'customLayoutExample' | |
7 | - onBeforeAction: -> | |
8 | - # Code to run before route goes here. | |
9 | - ) | |
10 | - ### | |
2 | + @route('index', | |
3 | + path: '/' | |
4 | + template: 'index' | |
5 | + onBeforeAction: -> | |
6 | + # Code to run before route goes here. | |
7 | + ) | |
11 | 8 | ) | ... | ... |
client/views/authenticated/index.html
packages/npm-packages/package.js
server/admin/accounts.coffee
... | ... | @@ -0,0 +1,53 @@ |
1 | +### | |
2 | + Accounts | |
3 | + Server side account creation and manipulation methods. | |
4 | + | |
5 | + NPM Requires: | |
6 | + - Fibers (https://www.npmjs.org/package/fibers) | |
7 | + - Futures (https://www.npmjs.org/package/fibers) | |
8 | + | |
9 | + Configuration: | |
10 | + - forbidClientAccountCreation: Disallow client side account creation. | |
11 | + | |
12 | + Methods: | |
13 | + - createUserAccount: Performs a server-side account creation using the Meteor Accounts Password package. | |
14 | +### | |
15 | + | |
16 | +# NPM Requires | |
17 | +Future = Npm.require('fibers/future'); | |
18 | +Fibers = Npm.require('fibers'); | |
19 | + | |
20 | +# Configuration: | |
21 | +Accounts.config( | |
22 | + forbidClientAccountCreation: true | |
23 | +) | |
24 | + | |
25 | +# Define Methods | |
26 | +Meteor.methods( | |
27 | + | |
28 | + createUserAccount: (user)-> | |
29 | + | |
30 | + # Check values against correct pattern. | |
31 | + pattern = { email: String, password: String } | |
32 | + check(user, pattern) | |
33 | + | |
34 | + # Define the Future so we can return to the client later. | |
35 | + createUserAccount = new Future() | |
36 | + | |
37 | + # Run the Timeout function and create the user. | |
38 | + setTimeout(-> | |
39 | + | |
40 | + # Run Meteor code in a Fiber. | |
41 | + # Note: Accounts.createUser does NOT allow a callback on the server, so we currently | |
42 | + # cannot check to see if an error took place. | |
43 | + Fibers(-> | |
44 | + Accounts.createUser(user) | |
45 | + # Send a faux response back to the client. | |
46 | + createUserAccount.return({"success": "Account successfully created!"}) | |
47 | + ).run() | |
48 | + | |
49 | + ,300) | |
50 | + | |
51 | + # Wait for the process to complete. | |
52 | + createUserAccount.wait() | |
53 | +) | ... | ... |