Hello,
with the package “accounts-password”/'accounts-base" and “alanning:roles” I try to create a user creation system in my backoffice. (Only the administrator can create accounts and for that it must be connected).
My form is composed of :
- user name
- password
- roles
The problem is that the email address does not insert.
When I put the required email field, it returns an error like: “Email is required…”
While with a.log console I can see that my email field is returned correctly…
(I only want one email address per account.)
Here is my schema:
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);
Schema = {};
/**
* Création du schema pour CreateUser
*/
Schema.UserServices = new SimpleSchema({
password: {
type: String,
label: "Mot de passe",
autoform: {
afFieldInput: {
type: "password"
}
}
},
passwordConfirmation: {
type: String,
label: "Confirmation",
custom: function(){
if(this.value !== this.field('password').value){
return "passwordMissmatch";
}
},
autoform: {
afFieldInput: {
type: "password"
}
}
}
});
Schema.AccountData = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/,
label: "Nom d'utilisateur"
},
emails: {
optional: false,
type: Array,
label:"Adresse email"
},
"emails.$": {
type: Object
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean,
optional: true,
autoform: {
omit: true
}
},
createdAt: {
type: Date,
autoValue: function () {
if (this.isInsert) {
return new Date;
} else {
this.unset();
}
},
autoform: {
omit: true
}
},
services: {
type: Schema.UserServices,
optional: true,
blackbox: true,
autoform:{
omit: true
}
},
roles: {
type: String,
optional: true,
label:"Role",
blackbox: true
}
});
Meteor.users.attachSchema(Schema.AccountData);
Method server side create user :
Meteor.methods({
"usercreation": function (data) {
if (_.isObject(data)) {
if (data.username) {
let id = Accounts.createUser({
username:data.username,
password:data.password,
emails :data.emails
});
if (data.roles.length > 0) {
// Need _id of existing user record so this call must come
// after `Accounts.createUser` or `Accounts.onCreate`
//[].concat(user);
Roles.addUsersToRoles(id, data.roles, Roles.GLOBAL_GROUP);
}
_.extend(data, {id: id});
return id;
}
}
}
});
Hook client side :
AutoForm.hooks({
'usercreation': {
onSubmit: function(dataEvent){
// Gestion du formulaire d'inscription
this.event.preventDefault();
if(dataEvent !== undefined) {
Schema.AccountData.clean(dataEvent);
console.log(dataEvent);
let username = dataEvent.username;
let email = dataEvent.email;
let password = dataEvent.services.password;
let roles = dataEvent.roles;
Meteor.call("usercreation", {
username: username,
password: password,
email: email,
roles: roles
}, (err, res) => {
if (err)
this.done(err);
else if(res)
this.done();
});
}
},
onSuccess: function(){
swal("Nouvel utilisateur ajouté", "L'utilisateur a bien été créé. <br> Vous pouvez le modifier ou le supprimer à tout moment.", "success");
},
onError: function(formType, err){
swal("Erreur !", err.reason, "error");
}
}
});
form html :
{{#autoForm collection="Meteor.users" id="usercreation" class="ui form gestionUtilisateurs"}}
{{> afQuickField name="username"}}
{{> afQuickField name="services.password"}}
{{> afQuickField name="services.passwordConfirmation"}}
{{> afQuickField name="email"}}
{{> afQuickField name="roles"}}
<br>
<button type="submit" class="ui submit button">Créer l'utilisateur</button>
{{/autoForm}}
Do you have any idea?