Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added postSignUpHook as discussed in #536 #586

Merged
merged 2 commits into from
Dec 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ AccountsTemplates.configure({
onLogoutHook: myLogoutFunc,
onSubmitHook: mySubmitFunc,
preSignUpHook: myPreSubmitFunc,
postSignUpHook: myPostSubmitFunc,

// Texts
texts: {
Expand Down Expand Up @@ -281,6 +282,7 @@ Details for each of them follow.
| onLogoutHook | Function | | Called on `AccountsTemplates.logout` invocation: allows for custom redirects or whatever custom action to be taken on user logout. |
| onSubmitHook | Function | | `func(error, state)` Called when the `pwdForm` is being submitted: allows for custom actions to be taken on form submission. `error` contains possible errors occurred during the submission process, `state` specifies the `atForm` internal state from which the submission was triggered. A nice use case might be closing the modal or side-menu showing `atForm` |
| preSignUpHook | Function | | `func(password, info)` Called just before submitting the `pwdForm` for sign-up: allows for custom actions on the data being submitted. A nice use could be extending the user profile object accessing `info.profile`. to be taken on form submission. The plain text `password` is also provided for any reasonable use. |
| postSignUpHook | Function | | `func(userId, info)` Called, **server side only**, just after a successfull user account creation, post submitting the `pwdForm` for sign-up: allows for custom actions on the data being submitted ___after___ we are sure a new user was ___successfully___ created. A common use might be applying roles to the user, as this is only possible after fully completing user creation in alanning:roles. The `userId` is available as the first parameter, so that user user object may be retrieved. The `password` is not available as it's already encrypted, though the encrypted password may be found in `info` if of use. |

##### onSubmitHook

Expand Down
1 change: 1 addition & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ CONFIG_PAT = {
onLogoutHook: Match.Optional(Function),
onSubmitHook: Match.Optional(Function),
preSignUpHook: Match.Optional(Function),
postSignUpHook: Match.Optional(Function),

texts: Match.Optional(TEXTS_PAT),

Expand Down
6 changes: 6 additions & 0 deletions lib/server_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Meteor.methods({
throw new Error("createUser failed to insert new user");
}

// Call postSignUpHook, if any...
var postSignUpHook = AccountsTemplates.options.postSignUpHook;
if (postSignUpHook) {
postSignUpHook(userId, options);
}

// Send a email address verification email in case the context permits it
// and the specific configuration flag was set to true
if (options.email && AccountsTemplates.options.sendVerificationEmail) {
Expand Down