diff --git a/hourglass/server/main.js b/hourglass/server/main.js index aabb5c7..115579b 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -52,7 +52,7 @@ Meteor.methods({ }, 'joinClass': function(change, pass) { found = classes.find({_id: change, status: true}).fetch(); - if (Meteor.user() != null && found.length > 0 && pass === found[0].code) { + if (Meteor.user() != null && found.length > 0 && pass === found[0].code && Meteor.user().profile.classes.indexOf(change) === -1) { current = Meteor.user().profile; current.classes.append(change); Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}}); @@ -60,5 +60,17 @@ Meteor.methods({ } else { return 0; } + }, + 'leaveClass': function(change) { + if (Meteor.user() != null) { + profile = Meteor.user().profile + index = profile.classes.indexOf(change) + if (index >= 0) { + profile.classes.splice(index, 1); + Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}}); + return 1 + } + + } } }); \ No newline at end of file