import { Meteor } from ‘meteor/meteor’;
import { Accounts } from ‘meteor/accounts-base’;
import { CONST } from ‘…/…/common/constants.js’;
import { Roles } from ‘meteor/alanning:roles’;
Meteor.methods({
updateUserProfile: (newProfile) => {
const userId = Meteor.userId();
// var isEmailChanged = currentProfile ?
// newProfile.email != currentProfile.email :
Meteor.users.update(userId, {
$set: {
profile: newProfile,
},
}, {
validationContext: 'updateUserProfile',
});
},
createDriver: (newUser) => {
var id =Accounts.createUser({
username: newUser.username,
email: newUser.email,
password: newUser.password,
profile: newUser.profile,
//roles: CONST.USER_ROLES.DRIVER,
});
//console.log(Meteor.userId());
Roles.addUsersToRoles(Accounts.userId(), ‘Driver’);
},
});
driverjoin.js
Template.driverJoin.events({
‘submit #form’: function driverJoinSubmitForm(event) {
// Prevent default browser form submit
event.preventDefault();
const data = {
username: event.target.email.value,
email: event.target.email.value,
password: event.target.password.value,
profile: {
lastName: event.target.lastname.value,
firstName: event.target.firstname.value,
phone: event.target.phone.value,
// email: event.target.email.value,
birthday: moment(event.target.birthday.value, CONST.DEFAULT_DATETIME_FORMAT).toDate(),
creditCard: {
num: event.target.num.value,
validThruM: event.target.validThruM.value,
validThruY: event.target.validThruY.value,
cvv: event.target.cvv.value,
name: event.target.name.value,
},
},
};
// TODO: Add validation
Meteor.call('createDriver', data, (error) => {
if (error) {
Session.set(SESSION.ERROR, error);
} else {
FlowRouter.go('/s/driver/vehicles'); // TODO : replace with redirection by root name
}
});
return false;
},
});