From e23398999a4efd3e372c4846af99c2576d6883b2 Mon Sep 17 00:00:00 2001 From: Yaman Qalieh Date: Thu, 1 Sep 2016 00:13:17 -0400 Subject: [PATCH] fix #76 --- hourglass/lib/router.js | 8 ++++---- hourglass/server/main.js | 30 ++++++++++-------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/hourglass/lib/router.js b/hourglass/lib/router.js index 864468f..7190bfa 100644 --- a/hourglass/lib/router.js +++ b/hourglass/lib/router.js @@ -1,6 +1,6 @@ Router.route('/', { waitOn: function() { - if (!Meteor.userId()) { + if (!Meteor.userId() || !Meteor.user().profile.school) { this.redirect('/login'); } else { return [ @@ -12,7 +12,7 @@ Router.route('/', { ]; } }, - action: function() { + action: function() { this.render("main"); } }); @@ -20,7 +20,7 @@ Router.route('/', { Router.route('/login', function() { if (!Meteor.userId()) { this.render("login"); - } else if (Object.keys(Meteor.user().profile).length <= 1) { + } else if (!Meteor.user().profile.school) { this.redirect('/profile'); } else { this.redirect('/'); @@ -67,4 +67,4 @@ Router.route('/admin', { Router.configure({ notFoundTemplate: "NotFound" -}); \ No newline at end of file +}); diff --git a/hourglass/server/main.js b/hourglass/server/main.js index e04972b..e13060b 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -7,7 +7,6 @@ import { } from 'meteor/mongo'; // Defines who the admins are - not added - var superadmins = [ "ybq987@gmail.com", "ksjdragon@gmail.com", @@ -40,14 +39,14 @@ Meteor.publish('classes', function() { return classes.find(); } else { // Return user classes and all _public_ classes. - var userprofile = Meteor.users.findOne(this.userId).profile; - if (userprofile !== undefined && userprofile.classes !== undefined) { + var userprofile = Meteor.users.findOne(this.userId); + if (userprofile !== undefined && userprofile.profile.classes !== undefined) { return classes.find({ $or: [{ privacy: false }, { _id: { - $in: userprofile.classes + $in: userprofile.profile.classes } }] }, { @@ -67,11 +66,8 @@ Meteor.publish('classes', function() { } }); } else { - var empty; - Meteor.call('createProfile', this.userId, function(error, result) { - empty = result; - }); - return result; + Meteor.call('createProfile', this.userId); + return classes.find({_id: null}); } } }); @@ -82,20 +78,17 @@ Meteor.publish('work', function() { if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) { return work.find(); } else { - var userprofile = Meteor.users.findOne(this.userId).profile; - if (userprofile !== undefined && userprofile.classes !== undefined) { + var userprofile = Meteor.users.findOne(this.userId); + if (userprofile !== undefined && userprofile.profile.classes !== undefined) { return work.find({ // Only return work of enrolled classes class: { - $in: userprofile.classes + $in: userprofile.profile.classes } }); } else { - var empty; - Meteor.call('createProfile', this.userId, function(error, result) { - empty = result; - }); - return result; + Meteor.call('createProfile', this.userId); + return classes.find({_id: null}); } } @@ -518,9 +511,6 @@ Meteor.methods({ profile: current } }); - return classes.find({ - _id: null - }); }, 'joinClass': function(input) { var change = input[0];