Commit 8fa323ef66e4a4bec2d39cf2848b15548eaf598c
1 parent
0b8a1b6050
Exists in
master
and in
1 other branch
more on userservice. conditionally display sidebar
Showing 9 changed files with 73 additions and 70 deletions Side-by-side Diff
config.js
View file @
8fa323e
... | ... | @@ -49,7 +49,7 @@ |
49 | 49 | }). |
50 | 50 | state('feed', { |
51 | 51 | resolve: auth_resolve, |
52 | - url: '/feed', | |
52 | + url: '/feed/{sectionId}', | |
53 | 53 | templateUrl: 'templates/feed.html', |
54 | 54 | controller: 'FeedController' |
55 | 55 | }). |
56 | 56 | |
... | ... | @@ -78,13 +78,11 @@ |
78 | 78 | controller: 'FlashcardController' |
79 | 79 | }). |
80 | 80 | state('requestpasswordreset', { |
81 | - resolve: auth_resolve, | |
82 | 81 | url: '/requestpasswordreset', |
83 | 82 | templateUrl: 'templates/requestpasswordreset.html', |
84 | 83 | controller: 'RequestResetController' |
85 | 84 | }). |
86 | 85 | state('resetpassword', { |
87 | - resolve: auth_resolve, | |
88 | 86 | url: '/resetpassword/{uid}/{token}', |
89 | 87 | templateUrl: 'templates/resetpassword.html', |
90 | 88 | controller: 'ResetPasswordController' |
91 | 89 | |
... | ... | @@ -99,15 +97,16 @@ |
99 | 97 | function($rootScope, $state, $stateParams, $location, UserService) { |
100 | 98 | $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { |
101 | 99 | if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name); |
102 | - if (toState.name == 'login') return; | |
103 | - if (!UserService.isUserResolved()) return; | |
100 | + if (toState.name == 'login') return console.log('we are going to login anyway; just let it happen :)'); | |
101 | + if (!UserService.isUserResolved()) return console.log('user not yet resolved; hold off'); | |
104 | 102 | $rootScope.returnToState = toState; |
105 | 103 | $rootScope.returnToStateParams = toStateParams; |
106 | 104 | console.log('going to ' + toState.name + ' after login'); |
107 | 105 | $state.go('login'); |
108 | 106 | }); |
109 | - $rootScope.$on('$routeChangeError', function() { | |
110 | - console.log('failed to change routes'); | |
107 | + $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | |
108 | + console.log('failed to change state: ' + error); | |
109 | + $state.go('login'); | |
111 | 110 | }); |
112 | 111 | } |
113 | 112 | ]); |
flashy.css
View file @
8fa323e
home.html
View file @
8fa323e
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | |
14 | 14 | <body ng-controller="RootController"> |
15 | 15 | |
16 | -<ul id="slide-out" class="side-nav fixed"> | |
16 | +<ul id="slide-out" ng-show="isLoggedIn" class="side-nav fixed"> | |
17 | 17 | <li class="logo"><a href="//flashy.cards/" id="logo-container"> |
18 | 18 | <h1>Flashy</h1> |
19 | 19 | </a></li> |
... | ... | @@ -24,9 +24,9 @@ |
24 | 24 | <li> |
25 | 25 | <ul> |
26 | 26 | <li ui-sref="feed">WRONG 123</li> |
27 | - <li ui-sref="feed/4567">CSE 1337</li> | |
28 | - <li ui-sref="feed/1242">MATH 20Z</li> | |
29 | - <li ui-sref="feed/2842">BILD 99</li> | |
27 | + <li ui-sref="feed(4567)">CSE 1337</li> | |
28 | + <li ui-sref="feed(1242)">MATH 20Z</li> | |
29 | + <li ui-sref="feed(2842)">BILD 99</li> | |
30 | 30 | </ul> |
31 | 31 | </li> |
32 | 32 | <li class="bold"><a ui-sref="addclass">Add Class</a></li> |
scripts/FeedController.js
View file @
8fa323e
1 | 1 | angular.module('flashy.FeedController', ['ui.router']). |
2 | 2 | |
3 | - controller('FeedController', ['$scope', '$state', '$http', function($scope, $state, $http) { | |
3 | + controller('FeedController', ['$scope', '$stateParams', '$state', '$http', function($scope, $stateParams, $state, $http) { | |
4 | 4 | console.log('Hello from feed'); |
5 | - | |
5 | + sectionId = $stateParams.sectionId; | |
6 | 6 | $scope.cards = []; |
7 | 7 | |
8 | + $scope.cards[0] = {'id': 1, 'title': 'title1', 'content': 'abc'}; | |
9 | + $scope.cards[1] = {'id': 2, 'title': 'title2', 'content': 'xyz'}; | |
10 | + $scope.cards[2] = {'id': 2, 'title': 'title3', 'content': 'qwe'}; | |
8 | 11 | |
9 | - $scope.cards[0] = { 'id': 1, 'title': 'title1', 'content': 'abc' }; | |
10 | - $scope.cards[1] = { 'id': 2, 'title': 'title2', 'content': 'xyz' }; | |
11 | - $scope.cards[2] = { 'id': 2, 'title': 'title3', 'content': 'qwe' }; | |
12 | + $http.get('/api/sections/' + sectionId + '/flashcards/'). | |
13 | + success(function(data) { | |
14 | + for (var i = 0; i < data.length; i++) { | |
15 | + cards.push({'title': data[i].title, 'content': data[i].content}); | |
16 | + } | |
17 | + }). | |
18 | + error(function(err) { | |
19 | + console.log('no'); | |
20 | + }); | |
12 | 21 | |
13 | - $http.get('/api/sections/{pk}/flashcards'). | |
14 | - success(function(data) { | |
15 | - for (var i = 0; i < data.length; i++) { | |
16 | - cards.push({ 'title': data[i].title, 'content': data[i].content }); | |
17 | - } | |
18 | - }). | |
19 | - error(function(err) { | |
20 | - console.log('no'); | |
21 | - }); | |
22 | - | |
23 | 22 | $scope.viewDeck = function() { |
24 | 23 | $state.go('deck'); |
25 | 24 | console.log('go to deck'); |
26 | 25 | |
27 | 26 | |
... | ... | @@ -38,30 +37,31 @@ |
38 | 37 | |
39 | 38 | // attempt to make card :( |
40 | 39 | $http.post('/api/flashcards/', {'text': $scope.text, 'pushed': pushed, 'mask': []}). |
41 | - success(function(data) { | |
42 | - console.log('No way, really?'); | |
43 | - }). | |
44 | - error(function(error) { | |
45 | - console.log('haha, n00b'); | |
46 | - }); | |
40 | + success(function(data) { | |
41 | + console.log('No way, really?'); | |
42 | + }). | |
43 | + error(function(error) { | |
44 | + console.log('haha, n00b'); | |
45 | + }); | |
47 | 46 | |
48 | 47 | $scope.text = ''; |
49 | 48 | }; |
50 | 49 | |
51 | - $scope.flashcard = 'hi i am a flashcard. I need to be really long and awesome I ain\'t know how long I am right now. Is it good enough now?????????? Howz about now???'; | |
50 | + $scope.flashcard = 'hi i am a flashcard. I need to be really long and awesome I ain\'t ' + | |
51 | + 'know how long I am right now. Is it good enough now?????????? Howz about now???'; | |
52 | 52 | $scope.text = ''; |
53 | 53 | |
54 | 54 | $(document).ready(function() { |
55 | - // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered | |
56 | - $('.modal-trigger').leanModal({ | |
57 | - dismissible: true, // Modal can be dismissed by clicking outside of the modal | |
58 | - opacity: 0, // Opacity of modal background | |
59 | - in_duration: 300, // Transition in duration | |
60 | - out_duration: 200, // Transition out duration | |
61 | - /*ready: function() { alert('Ready'); }, // Callback for Modal open | |
62 | - complete: function() { alert('Closed'); } // Callback for Modal close*/ | |
63 | - } | |
64 | - ); | |
55 | + // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered | |
56 | + $('.modal-trigger').leanModal({ | |
57 | + dismissible: true, // Modal can be dismissed by clicking outside of the modal | |
58 | + opacity: 0, // Opacity of modal background | |
59 | + in_duration: 300, // Transition in duration | |
60 | + out_duration: 200, // Transition out duration | |
61 | + /*ready: function() { alert('Ready'); }, // Callback for Modal open | |
62 | + complete: function() { alert('Closed'); } // Callback for Modal close*/ | |
63 | + } | |
64 | + ); | |
65 | 65 | }); |
66 | 66 | |
67 | 67 | }]); |
scripts/RequestResetController.js
View file @
8fa323e
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | $scope.success = false; |
7 | 7 | $scope.error = false; |
8 | 8 | $scope.resetPass = function(email) { |
9 | - $http.post('/api/request_password_reset', JSON.stringify({ | |
9 | + $http.post('/api/request_password_reset/', JSON.stringify({ | |
10 | 10 | 'email': email |
11 | 11 | })) |
12 | 12 | .success(function(data) { |
scripts/ResetPasswordController.js
View file @
8fa323e
scripts/RootController.js
View file @
8fa323e
scripts/UserService.js
View file @
8fa323e
... | ... | @@ -5,18 +5,24 @@ |
5 | 5 | var deferred = $q.defer(); |
6 | 6 | if (angular.isDefined(_user)) { |
7 | 7 | console.log('user is already defined: ' + _user); |
8 | - if (!_user) deferred.reject(_user); | |
9 | - deferred.resolve(_user); | |
8 | + if (!_user) { | |
9 | + console.log('rejecting deferred'); | |
10 | + deferred.reject(_user); | |
11 | + } else { | |
12 | + $rootScope.isLoggedIn = true; | |
13 | + deferred.resolve(_user); | |
14 | + } | |
10 | 15 | return deferred.promise; |
11 | 16 | } |
12 | 17 | $http.get('/api/me/').success(function(data) { |
13 | 18 | console.log('user is logged in!'); |
14 | 19 | _user = data; |
20 | + $rootScope.isLoggedIn = true; | |
15 | 21 | deferred.resolve(data); |
16 | 22 | }).error(function(data) { |
23 | + console.log('not logged in yet: ' + data.detail); | |
17 | 24 | deferred.reject('error getting own data'); |
18 | 25 | _user = false; |
19 | - console.log(data); | |
20 | 26 | }); |
21 | 27 | return deferred.promise; |
22 | 28 | }; |
... | ... | @@ -27,6 +33,7 @@ |
27 | 33 | return angular.isDefined(_user); |
28 | 34 | }; |
29 | 35 | this.logout = function() { |
36 | + $rootScope.isLoggedIn = false; | |
30 | 37 | _user = undefined; |
31 | 38 | }; |
32 | 39 | this.isLoggedIn = function() { |
scripts/VerifyEmailController.js
View file @
8fa323e
... | ... | @@ -3,27 +3,27 @@ |
3 | 3 | .controller('VerifyEmailController', ['$scope', '$state', '$http', '$timeout', |
4 | 4 | function($scope, $state, $http, $timeout) { |
5 | 5 | 'use strict'; |
6 | - var url = document.location.href.split('/'); | |
7 | - var key = url[url.length - 1]; | |
6 | + var url = document.location.href.split('/'); | |
7 | + var key = url[url.length - 1]; | |
8 | 8 | $scope.success = false; |
9 | 9 | $scope.error = false; |
10 | 10 | |
11 | - $http.patch('/api/me', JSON.stringify({ | |
12 | - 'confirmation_key': key | |
13 | - })) | |
14 | - .success(function(data) { | |
15 | - $scope.success = true; | |
16 | - console.log('SUCCESS'); | |
17 | - console.log(data); | |
18 | - $timeout(function($state) { | |
19 | - $state.go('feed'); | |
20 | - }, 2000); | |
21 | - }) | |
22 | - .error(function(data, status, header, config) { | |
23 | - $scope.error = true; | |
24 | - console.log('ERROR'); | |
25 | - console.log(data); | |
26 | - }); | |
11 | + $http.patch('/api/me/', JSON.stringify({ | |
12 | + 'confirmation_key': key | |
13 | + })) | |
14 | + .success(function(data) { | |
15 | + $scope.success = true; | |
16 | + console.log('SUCCESS'); | |
17 | + console.log(data); | |
18 | + $timeout(function($state) { | |
19 | + $state.go('feed'); | |
20 | + }, 2000); | |
21 | + }) | |
22 | + .error(function(data, status, header, config) { | |
23 | + $scope.error = true; | |
24 | + console.log('ERROR'); | |
25 | + console.log(data); | |
26 | + }); | |
27 | 27 | } |
28 | 28 | ]); |