fixed code generator

This commit is contained in:
yamanq 2016-08-08 05:39:20 -04:00
parent d6dac78912
commit 7fed7b56a6

View File

@ -41,22 +41,15 @@ function allow(user, method) {
//Switch/case for different permissions per method/function //Switch/case for different permissions per method/function
} }
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; _uuid4 = function(cc) {
var rr = Math.random() * 16 | 0;
return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16);
}
Meteor.startup(() => { Meteor.startup(() => {
Meteor.methods({ Meteor.methods({
'genCode': function() { 'genCode': function() {
var text = ""; return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, _uuid4);
var same = true;
while(same) {
for(var i = 0; i < 6; i++) {
text += possible.charAt(Math.floor(Math.random() * 52));
}
if(!classes.find( { code: { $eq: text } } ).limit(1)) {
same = false;
}
}
return text;
}, },
'createClass': function(input) { 'createClass': function(input) {
if(allow(Meteor.userId(),"createClass")) { if(allow(Meteor.userId(),"createClass")) {