Created
February 1, 2015 19:30
-
-
Save gabriel-dehan/3f78d94f6a035c89595d to your computer and use it in GitHub Desktop.
Autoform for registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template name="signUpForm"> | |
{{ #autoForm schema="Schemas.Form.Register" id="user-auth-form" type="method" meteormethod="user-auth:register" }} | |
<fieldset> | |
<legend>Create an account</legend> | |
{{> afQuickField name='username' }} | |
{{> afQuickField name='email' label='Email' }} | |
{{> afQuickField name='password' }} | |
{{> afQuickField name='passwordConfirmation' }} | |
</fieldset> | |
<input type="submit"> | |
{{ /autoForm }} | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AutoForm.addHooks('user-auth-form', { | |
after: { | |
'user-auth:register': function (_, loginData) { | |
// Seems unsafe, see user-auth/server/methods | |
Meteor.loginWithPassword(loginData.email, loginData.password, function(e) { | |
console.log(e); | |
}) | |
return false; | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Schemas.Form.Register = new SimpleSchema({ | |
username: { | |
type: String, | |
regEx: /^[a-z0-9A-Z_]{3,15}$/, | |
unique: true | |
}, | |
email: { | |
type: String, | |
regEx: SimpleSchema.RegEx.Email | |
}, | |
password: { | |
type: String, | |
label: "Enter the password", | |
min: 6, | |
autoform: { | |
afFieldInput: { | |
type: "password" | |
} | |
} | |
}, | |
passwordConfirmation: { | |
type: String, | |
label: "Enter the password again", | |
min: 6, | |
autoform: { | |
afFieldInput: { | |
type: "password" | |
} | |
}, | |
custom: function () { | |
if (this.value !== this.field('password').value) { | |
return "passwordMismatch"; | |
} | |
} | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.methods({ | |
'user-auth:register': function(params) { | |
Accounts.createUser({ | |
username: params.username, | |
email: params.email, | |
password: params.password | |
}); | |
// TODO: Seems really unsafe, StackOverflow pls ? | |
return { email: params.email, password: params.password }; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment