瀏覽代碼

Merge branch 'master' of https://github.com/Musare/Musare

Wesley McCann 9 年之前
父節點
當前提交
d0a5532b7b
共有 5 個文件被更改,包括 147 次插入79 次删除
  1. 94 44
      app/client/client.js
  2. 11 2
      app/client/routes.js
  3. 27 12
      app/client/templates/dashboard.html
  4. 14 16
      app/client/templates/register.html
  5. 1 5
      app/server/server.js

+ 94 - 44
app/client/client.js

@@ -22,6 +22,34 @@ Deps.autorun(function() {
     Meteor.subscribe("userData", Meteor.userId());
 });
 
+var ban_interval = Meteor.setInterval(function() {
+    var userId = Meteor.userId();
+    if (userId !== undefined) {
+        var userData = Meteor.user();
+        if (localStorage.getItem("banned") === "true") {
+            if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
+                var ban = userData.punishments.ban;
+                if (new Date(ban.bannedUntil).getTime() <= new Date().getTime()) {
+                    Meteor.call("isBanned", function(err, res) {
+                        if (res === false) {
+                            localStorage.setItem("banned", false);
+                            Meteor._reload.reload();
+                        }
+                    });
+                }
+            } else {
+                localStorage.setItem("banned", false);
+                Meteor._reload.reload();
+            }
+        } else {
+            if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
+                localStorage.setItem("banned", true);
+                Meteor._reload.reload();
+            }
+        }
+    }
+}, 1000);
+
 var minterval;
 var hpSound = undefined;
 var songsArr = [];
@@ -201,7 +229,7 @@ Template.header.helpers({
         } else {
             return false;
         }
-    },
+    }
 });
 
 Template.header.events({
@@ -214,6 +242,33 @@ Template.header.events({
     }
 });
 
+Template.register.onCreated(function() {
+    Accounts.onLoginFailure(function() {
+        var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> Something went wrong when trying to register with GitHub. Maybe an account with that username already exists?</div>');
+        $(".landing").before(errAlert);
+        Meteor.setTimeout(function() {
+            errAlert.fadeOut(5000, function() {
+                errAlert.remove();
+            });
+        }, 10000);
+    });
+});
+
+Template.login.onCreated(function() {
+    Session.set("github", true);
+    Accounts.onLoginFailure(function() {
+        if (Session.get("github") === true) {
+            var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> Something went wrong when trying to log in with GitHub.</div>');
+            $(".landing").before(errAlert);
+            Meteor.setTimeout(function() {
+                errAlert.fadeOut(5000, function() {
+                    errAlert.remove();
+                });
+            }, 10000);
+        }
+    });
+});
+
 Template.register.events({
     "submit form": function(e){
         e.preventDefault();
@@ -226,11 +281,13 @@ Template.register.events({
 
             if (err) {
                 console.log(err);
-                var errAlert = $('<div class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> ' + err.reason + '</div>');
-                $("#login").after(errAlert);
-                errAlert.fadeOut(20000, function() {
-                    errAlert.remove();
-                });
+                var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> ' + err.reason + '</div>');
+                $(".landing").before(errAlert);
+                Meteor.setTimeout(function() {
+                    errAlert.fadeOut(5000, function() {
+                        errAlert.remove();
+                    });
+                }, 5000);
             } else {
                 Meteor.loginWithPassword(username, password);
                 Accounts.onLogin(function(){
@@ -248,47 +305,28 @@ Template.register.events({
 Template.login.events({
     "submit form": function(e){
         e.preventDefault();
+        Session.set("github", false);
         var username = e.target.loginUsername.value;
         var password = e.target.loginPassword.value;
-        Meteor.loginWithPassword(username, password);
-        Accounts.onLogin(function(){
-            window.location.href = "/";
-        })
-        Accounts.onLoginFailure(function(){
-            $("#login-form input").css("background-color","indianred");
-            $("#login-form input").on("click",function(){
-                $("#login-form input").css({
-                    "-webkit-appearance": "none",
-                    "   -moz-appearance": "none",
-                    "        appearance": "none",
-                    "outline": "0",
-                    "border": "1px solid rgba(255, 255, 255, 0.4)",
-                    "background-color": "rgba(255, 255, 255, 0.2)",
-                    "width": "304px",
-                    "border-radius": "3px",
-                    "padding": "10px 15px",
-                    "margin": "0 auto 10px auto",
-                    "display": "block",
-                    "text-align": "center",
-                    "font-size": "18px",
-                    "color": "white",
-                    "-webkit-transition-duration": "0.25s",
-                    "        transition-duration": "0.25s",
-                    "font-weight": "300"
-                });
-                $("#login-form input:focus").css({
-                    "width": "354px",
-                    "color": "white"
-                })
-                $("#login-form input").on("blur", function(){
-                    $(this).css("width", "304px");
-                })
-            })
+        Meteor.loginWithPassword(username, password, function(err) {
+            if (err) {
+                var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> ' + err.reason + '</div>');
+                $(".landing").before(errAlert);
+                Meteor.setTimeout(function() {
+                    errAlert.fadeOut(5000, function() {
+                        errAlert.remove();
+                    });
+                }, 5000);
+            } else {
+                window.location.href = "/";
+            }
         });
     },
 
     "click #github-login": function(){
-        Meteor.loginWithGithub({loginStyle: "redirect"});
+        Meteor.loginWithGithub({loginStyle: "redirect"}, function(err, res) {
+            console.log(err, res);
+        });
     }
 });
 
@@ -305,6 +343,20 @@ Template.dashboard.helpers({
         } else {
             return {};
         }
+    },
+    isAdmin: function() {
+        if (Meteor.user() && Meteor.user().profile) {
+            return Meteor.user().profile.rank === "admin";
+        } else {
+            return false;
+        }
+    },
+    isModerator: function() {
+        if (Meteor.user() && Meteor.user().profile && (Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator")) {
+            return true;
+        } else {
+            return false;
+        }
     }
 });
 
@@ -723,9 +775,7 @@ Template.banned.onCreated(function() {
     rTimeInterval = Meteor.setInterval(function() {
         Session.set("time", new Date().getTime());
     }, 10000);
-    Meteor.subscribe("ownBan", Meteor.userId(), function() {
-        Session.set("ban", Meteor.user().punishments.ban);
-    });
+    Session.set("ban", Meteor.user().punishments.ban);
 });
 
 Template.registerHelper("rtime", function(date) {

+ 11 - 2
app/client/routes.js

@@ -9,7 +9,6 @@ Router.onBeforeAction(function() {
         Meteor.call("isBanned", function(err, res) {
             if (res) {
                 self.render('banned');
-                pause();
             } else {
                 next();
             }
@@ -132,7 +131,17 @@ Router.route("/admin/alerts", {
 });
 
 Router.route("/:type", {
-    template: "room"
+    waitOn: function() {
+        return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
+    },
+    action: function() {
+        var user = Meteor.users.findOne({});
+        if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
+            this.render("room");
+        } else {
+            this.redirect("/");
+        }
+    }
 });
 
 Router.route("/u/:user", {

+ 27 - 12
app/client/templates/dashboard.html

@@ -1,16 +1,31 @@
 <template name="dashboard">
     <div class="row">
-       {{#each rooms}}
-          <div class="col-md-4 col-sm-6 col-xs-12">
-              <div class="station">
-                  <h3>{{display}}</h3>
-                  {{#with type=type}}
-                      <h5>{{currentSong.song.title}}</h5>
-                      <h6>{{currentSong.song.artist}}</h6>
-                  {{/with}}
-                  <a href="/{{type}}" class="station_link"></a>
-              </div>
-          </div>
-       {{/each}}
+        {{#each rooms}}
+            {{#if private}}
+                {{#if isModerator}}
+                    <div class="col-md-4 col-sm-6 col-xs-12">
+                        <div class="station" style="background-color: gray">
+                            <h3>{{display}}</h3>
+                            {{#with type=type}}
+                                <h5>{{currentSong.song.title}}</h5>
+                                <h6>{{currentSong.song.artist}}</h6>
+                            {{/with}}
+                            <a href="/{{type}}" class="station_link"></a>
+                        </div>
+                    </div>
+                {{/if}}
+            {{else}}
+                <div class="col-md-4 col-sm-6 col-xs-12">
+                    <div class="station">
+                        <h3>{{display}}</h3>
+                        {{#with type=type}}
+                        <h5>{{currentSong.song.title}}</h5>
+                        <h6>{{currentSong.song.artist}}</h6>
+                        {{/with}}
+                        <a href="/{{type}}" class="station_link"></a>
+                    </div>
+                </div>
+            {{/if}}
+        {{/each}}
     </div>
 </template>

+ 14 - 16
app/client/templates/register.html

@@ -1,20 +1,18 @@
 <template name="register">
     {{> alerts}}
-  <div class="landing">
-    {{> header}}
-    <div class="container">
-        <h1>Sign Up</h1>
-        <form class="form">
-            <input id="usernameInput" type="text" autocorrect="off" name="registerUsername" placeholder="Enter a username" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter a username'" required/>
-            <input id="emailInput" type="email" name="registerEmail" placeholder="Enter your email" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter your email'" required>
-            <input type="password" name="registerPassword" placeholder="Enter a password" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter a password'" required/> {{> reCAPTCHA}}
-            <p>By registering, you agree to the Terms and Conditions and Privacy Policy.</p>
-            <button type="submit">Sign Up</button>
-        </form>
-        <button class="btn-social" id="github-login"><i class="fa fa-github pull-left"></i>Signup with Github</button>
+    <div class="landing">
+        {{> header}}
+        <div class="container">
+            <h1>Sign Up</h1>
+            <form class="form">
+                <input id="usernameInput" type="text" autocorrect="off" name="registerUsername" placeholder="Enter a username" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter a username'" required/>
+                <input id="emailInput" type="email" name="registerEmail" placeholder="Enter your email" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter your email'" required>
+                <input type="password" name="registerPassword" placeholder="Enter a password" onfocus="this.placeholder = ''" onblur="this.placeholder='Enter a password'" required/> {{> reCAPTCHA}}
+                <p>By registering, you agree to the Terms and Conditions and Privacy Policy.</p>
+                <button type="submit">Sign Up</button>
+            </form>
+            <button class="btn-social" id="github-login"><i class="fa fa-github pull-left"></i>Signup with Github</button>
+        </div>
+        {{> bubbles}}
     </div>
-
-      {{> bubbles}}
-
-  </div>
 </template>

+ 1 - 5
app/server/server.js

@@ -380,7 +380,7 @@ Meteor.publish("alerts", function() {
 
 Meteor.publish("userData", function(userId) {
     if (userId !== undefined) {
-        return Meteor.users.find(userId, {fields: {"services.github.username": 1}})
+        return Meteor.users.find(userId, {fields: {"services.github.username": 1, "punishments": 1}})
     } else {
         return undefined;
     }
@@ -410,10 +410,6 @@ Meteor.publish("chat", function() {
     return Chat.find({});
 });
 
-Meteor.publish("ownBan", function(userId) {
-    return Meteor.users.find(userId, {"punishments.ban": 1, "profile": 1});
-});
-
 Meteor.publish("userProfiles", function(username) {
     var settings = Meteor.users.findOne({"profile.usernameL": username}, {fields: {"profile.settings": 1}});
     if (settings !== undefined && settings.profile.settings) {