diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 48cf460..d72b211 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -88,7 +88,11 @@ Security.permit(['insert', 'update', 'remove']).collections([schools, classes, w Meteor.methods({ 'genCode': function() { - return Math.random().toString(36).substr(2, 6); + currcode = Math.random().toString(36).substr(2, 6); + while (classes.findOne({code: currcode}) !== undefined) { + currcode = Math.random().toString(36).substr(2, 6); + } + return currcode; }, 'createSchool': function(schoolname) { if (Meteor.user() !== null &&