Skip to content

Instantly share code, notes, and snippets.

@dohomi
Last active August 29, 2015 14:09
Show Gist options
  • Save dohomi/0c9b6979c1cc3a817b19 to your computer and use it in GitHub Desktop.
Save dohomi/0c9b6979c1cc3a817b19 to your computer and use it in GitHub Desktop.
autoform pure schema validation create user
Template.registerHelper(Schemas, Schema);
Schemas.UserRegister = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
email: {
type: String,
// this must be optional if you also use other login services like facebook,
// but if you use only accounts-password, then it can be required
regEx: SimpleSchema.RegEx.Email
}
password: {
type: String,
label: "Enter a password",
min: 8
},
confirmPassword: {
type: String,
label: "Enter the password again",
min: 8,
custom: function () {
if (this.value !== this.field('password').value) {
return "passwordMismatch";
}
}
}
});
Meteor.methods({
insertUser: function(doc, modif, userId) {
// if you have autValue you need to clean first
// Important server-side check for security and data integrity
check(doc,Schemas.User);
var options = {
username: doc.username,
email: doc.email,
password: doc.password
};
var userId = Accounts.createUser(options);
}
});
<template name="userRegister">
{{#autoForm schema=Schemas.UserRegister id="userForm" meteormethod="insertUser" type="method"}}
<fieldset>
<legend>Contact Us</legend>
{{> afQuickField name="username"}}
{{> afQuickField name="email" id="email"}}
{{> afQuickField name="password"}}
{{> afQuickField name="confirmPassword"}}
<div>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</fieldset>
{{/autoForm}}
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment