Skip to content

Instantly share code, notes, and snippets.

@gabriel-dehan
Created February 1, 2015 19:30
Show Gist options
  • Save gabriel-dehan/3f78d94f6a035c89595d to your computer and use it in GitHub Desktop.
Save gabriel-dehan/3f78d94f6a035c89595d to your computer and use it in GitHub Desktop.
Autoform for registration
<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>
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;
}
}
});
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";
}
}
},
});
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