Last active
August 29, 2015 14:09
-
-
Save dohomi/0c9b6979c1cc3a817b19 to your computer and use it in GitHub Desktop.
autoform pure schema validation create user
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.registerHelper(Schemas, Schema); |
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.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"; | |
} | |
} | |
} | |
}); |
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({ | |
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); | |
} | |
}); |
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="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