2022-08-04 19:50:18 -05:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
|
import { Mongo } from 'meteor/mongo';
|
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
|
|
|
|
|
|
Meteor.methods({
|
|
|
|
|
'addToRole' (role) {
|
2022-08-05 16:55:56 -05:00
|
|
|
let countOfUsers = Meteor.users.find().count();
|
|
|
|
|
|
|
|
|
|
// if users = 1 - set to role passed in function call
|
|
|
|
|
if (countOfUsers > 1) {
|
|
|
|
|
console.log("User id for role: " + Meteor.userId() );
|
|
|
|
|
let userId = Meteor.userId();
|
|
|
|
|
Roles.addUsersToRoles(userId, role);
|
2024-07-22 11:56:35 -05:00
|
|
|
Meteor.call('add.darkModePref', "light", function(err, result) {
|
2022-08-15 18:07:39 -05:00
|
|
|
if (err) {
|
|
|
|
|
console.log(" ERROR: can't set user dark mode preference: " + err);
|
|
|
|
|
} else {
|
|
|
|
|
console.log(" SUCCESSFULLY set user dark mode preference.");
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-08-05 16:55:56 -05:00
|
|
|
} else if (countOfUsers == 1) {
|
|
|
|
|
console.log("Creating first system admin user: " + Meteor.userId() );
|
|
|
|
|
let userId = Meteor.userId();
|
|
|
|
|
Roles.addUsersToRoles(userId, "systemadmin");
|
2024-07-22 11:56:35 -05:00
|
|
|
Meteor.call('add.darkModePref', "light", function(err, result) {
|
2022-08-15 18:07:39 -05:00
|
|
|
if (err) {
|
|
|
|
|
console.log(" ERROR: can't set user dark mode preference: " + err);
|
|
|
|
|
} else {
|
|
|
|
|
console.log(" SUCCESSFULLY set user dark mode preference.");
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-08-05 16:55:56 -05:00
|
|
|
}
|
2022-08-04 19:50:18 -05:00
|
|
|
},
|
2023-06-09 09:51:11 -05:00
|
|
|
'edit.userPass' (userId, newPassword) {
|
2024-07-25 09:56:37 -05:00
|
|
|
check(userId, String);
|
|
|
|
|
check(newPassword, String);
|
2023-06-09 09:51:11 -05:00
|
|
|
|
2024-07-25 09:56:37 -05:00
|
|
|
return Accounts.setPassword(userId, newPassword);
|
2023-06-09 09:51:11 -05:00
|
|
|
},
|
|
|
|
|
'delete.userFromSys' (userId) {
|
|
|
|
|
check(userId, String);
|
|
|
|
|
|
|
|
|
|
return Meteor.users.remove({ _id: userId });
|
|
|
|
|
},
|
2024-07-25 09:56:37 -05:00
|
|
|
'update.userEmail' (userId, email) {
|
|
|
|
|
check(userId, String);
|
|
|
|
|
check(email, String);
|
|
|
|
|
|
|
|
|
|
return Meteor.users.update({ _id: userId }, {
|
|
|
|
|
$set: {
|
|
|
|
|
'emails.0.address': email,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
'edit.userRole' (userId, role) {
|
|
|
|
|
check(userId, String);
|
|
|
|
|
check(role, String);
|
|
|
|
|
|
|
|
|
|
return Roles.setUserRoles(userId, role);
|
|
|
|
|
}
|
2022-08-04 19:50:18 -05:00
|
|
|
});
|