Initial commit
This commit is contained in:
commit
35745a89ec
44 changed files with 3342 additions and 0 deletions
71
server/methods.js
Normal file
71
server/methods.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import { Roles } from 'meteor/roles';
|
||||
|
||||
Meteor.methods({
|
||||
'addToRole' (role) {
|
||||
const getUserInfo = async() => {
|
||||
try {
|
||||
let countOfUsers = await Meteor.users.find().countAsync();
|
||||
const user = await Meteor.userAsync();
|
||||
if (user) {
|
||||
let userId = user._id;
|
||||
if (countOfUsers > 1) {
|
||||
Roles.addUsersToRolesAysnc(userId, role);
|
||||
} else if (countOfUsers == 1) {
|
||||
Roles.addUsersToRolesAsync(userId, "systemadmin");
|
||||
} else {
|
||||
console.log("The count of users didn't seem to work when adding a new user.");
|
||||
}
|
||||
} else {
|
||||
console.log(" ---- No user info found.")
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR getting user info on server: " + error);
|
||||
}
|
||||
}
|
||||
getUserInfo();
|
||||
},
|
||||
'edit.userPass' (userId, newPassword) {
|
||||
check(userId, String);
|
||||
check(newPassword, String);
|
||||
|
||||
const setUsersPassword = async() => {
|
||||
try {
|
||||
const setPass = await Accounts.setPasswordAsync(userId, newPassword);
|
||||
if (setPass) {
|
||||
return setPass;
|
||||
} else {
|
||||
console.log(" Error seeting user password, await returned nothing.");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR setting user's password: " + error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
'delete.userFromSys' (userId) {
|
||||
check(userId, String);
|
||||
|
||||
return Meteor.users.remove({ _id: userId });
|
||||
},
|
||||
'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);
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue