I have attached a simpleschema to meteor.users collection and I wanted to know if I could create an user without using Accounts.createuser and just using meteor.users.allow({ insert: function() …}.
Any type help is appreciated.
Here are my schemas:
const UserProfile = new SimpleSchema({
Age: {
type: Number
},
Job: {
type: String
},
Phone: {
type: Number
},
Address: {
type: String
},
Gender: {
type: String
},
City: {
type: String
},
SecurityNumber: {
type: Number
},
HealthInsurance: {
type: Number
},
Rnc: {
type: String
},
Exequatur: {
type: Number
}
});
const UserSchema = new SimpleSchema({
FirstName: {
type: String
},
SecondName: {
type: String
},
Surname: {
type: String
},
LastName: {
type: String
},
BirthDate: {
type: Date
},
Password: {
type: String
},
Profile: {
type: UserProfile
},
CreatedAt: {
type: Date,
autoValue: function () {
return new Date()
}
},
roles: {
type: String,
optional: true,
blackbox: true,
allowedValues: ['client', 'secretary', 'provider', 'admin']
}
});
Meteor.users.attachSchema(UserSchema);
Meteor.users.allow({
insert: function () {
return true;
},
update: function () {
return true;
},
remove: function () {
return true;
}
});
And here’s is the code for creating the user just in case, just looking for new ways of doing it.
Template.signup.events({
"submit .signupForm": function (event) {
var name = trimInput(event.target.name.value);
var secondName = trimInput(event.target.secondName.value);
var surName = trimInput(event.target.surName.value);
var lastName = trimInput(event.target.lastName.value);
var email = trimInput(event.target.email.value);
var password = trimInput(event.target.password.value);
var password2 = trimInput(event.target.password2.value);
//If any of the fills is empty then show me an alert, if the user filled everything send me to the login section
if (isNotEmpty(name) &&
isNotEmpty(surName) &&
isNotEmpty(lastName) &&
isEmail(email) &&
isNotEmpty(password) &&
areValidPasswords(password, password2)) {
Accounts.createUser({
username: name + ' ' + secondName + ' ' + surName + ' ' + lastName,
email: email,
password: password,
}, function (err) {
if (err) {
Bert.alert(err.reason, "danger", "growl-top-right");
} else {
Bert.alert("Registro exitoso!", "success", "growl-top-right");
Router.go("/");
}
});
}
return false; //prevent submit of the form
}
});