Logic to stop downloads from DE if user not logged in.
authorCameron Ball <cameron@getapproved.com.au>
Fri, 5 Dec 2014 03:33:57 +0000 (11:33 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Fri, 5 Dec 2014 03:33:57 +0000 (11:33 +0800)
app/components/hello/hello-service.js
app/components/user/user-service.js
app/components/userMenu/userMenu-directive.js
app/components/userMenu/userMenu.html
app/divinelegy.css
app/pages/packs/packs.js

index 739ff69..01012e9 100644 (file)
@@ -74,6 +74,11 @@ factory("HelloService", ['rockEndpoint', '$http', '$location', '$q', function(ro
         
     hello.getFacebookId = function()
     {
+        if(!this.isLoggedIn())
+        {
+            return null;
+        }
+        
         return hello('facebook').api('/me').then(function(r)
         {
             return r.id;
index ecbfd41..f4dda5d 100644 (file)
@@ -46,6 +46,11 @@ factory("UserService", ['$rootScope', 'rockEndpoint', '$http', '$q', 'HelloServi
     {           
         if (!this.facebookId)
         {
+            if(!HelloService.getFacebookId())
+            {
+                return null;
+            }
+            
             return HelloService.getFacebookId().then(function(fbId)
                 {
                     //cant use this here bc scope or something
@@ -70,6 +75,12 @@ factory("UserService", ['$rootScope', 'rockEndpoint', '$http', '$q', 'HelloServi
             this.getUser(this.facebookId, true);
         }
     };
+    
+    UserService.flushCache = function()
+    {
+        this.userCache = {};
+        this.facebookId = null;
+    };
          
     return UserService;
 }]);
\ No newline at end of file
index 343aeb0..ccfb912 100644 (file)
@@ -21,7 +21,6 @@ directive('userMenu', ['HelloService', 'UserService', function(HelloService, Use
             {
                 UserService.getCurrentUser().then(function(user)
                 {
-                    console.log(user);
                     scope.welcomeMessage = 'Welcome, ' + user.displayName;
                     scope.quota = user.quota;
                     scope.quotaRemaining = user.quotaRemaining;
@@ -32,6 +31,7 @@ directive('userMenu', ['HelloService', 'UserService', function(HelloService, Use
             
             HelloService.on('auth.logout', function()
             {
+                UserService.flushCache();
                 scope.welcomeMessage = '';
                 scope.loggedIn = false;
                 scope.$$phase || scope.$apply();
index 3182f7d..f4a8f9c 100644 (file)
@@ -2,8 +2,8 @@
     <ul>
         <li>
             {{welcomeMessage}}
-            <a href="#" ng-if="loggedIn" ng-click="doLogout()">logout</a>
-            <a href="#" ng-if="!loggedIn" ng-click="doLogin()">login</a>
+            <a class="de-link" ng-if="loggedIn" ng-click="doLogout()">logout</a>
+            <a class="de-link" ng-if="!loggedIn" ng-click="doLogin()">login</a>
         </li>
     </ul>
     <div ng-if="loggedIn">
index 2667117..d0170df 100644 (file)
@@ -121,13 +121,13 @@ body {
     margin-right:5px;
 }
 
-.simfileListing a {
+a {
     font-weight: bold;
     color: #FFB122;
     text-decoration: none;
 }
 
-.simfileListing a:hover {
+a:hover {
     text-decoration: underline;
 }
 
index e8a2c5e..db2c771 100644 (file)
@@ -39,9 +39,15 @@ angular.module("DivinElegy.pages.packs", ["DivinElegy.components.simfiles","Divi
     };
 
     $scope.downloadFromDe = function(pack)
-    {        
-        UserService.getCurrentUser().then(function(user)
+    {    
+        if(!UserService.getCurrentUser())
         {
+            $rootScope.$broadcast('message.error', 'You need to be logged in to download from DivinElegy.'); 
+            return;
+        }
+        
+        UserService.getCurrentUser().then(function(user)
+        {            
             var size = filesizeBytes(pack.size);
             var quotaRemaining = filesizeBytes(user.quotaRemaining);