Commit a650201b9e7a69d1f424405cf6c6805a1cdb0362
1 parent
9436dc71d2
Exists in
master
and in
1 other branch
don't trust the user's local storage; they could have logged out on a different account
Showing 6 changed files with 21 additions and 29 deletions Side-by-side Diff
config.js
View file @
a650201
1 | 1 | angular.module('flashy', [ |
2 | - 'flashy.LogoutController', | |
3 | 2 | 'flashy.LoginController', |
4 | 3 | 'flashy.RootController', |
5 | 4 | 'flashy.FeedController', |
... | ... | @@ -78,12 +77,6 @@ |
78 | 77 | url: '/login', |
79 | 78 | templateUrl: 'templates/login.html', |
80 | 79 | controller: 'LoginController' |
81 | - }). | |
82 | - state('logout', { | |
83 | - resolve: auth_resolve, | |
84 | - url: '/logout', | |
85 | - templateUrl: 'templates/logout.html', | |
86 | - controller: 'LogoutController' | |
87 | 80 | }). |
88 | 81 | state('root', { |
89 | 82 | resolve: auth_resolve, |
home.html
View file @
a650201
... | ... | @@ -69,7 +69,7 @@ |
69 | 69 | <li ui-sref-active="active"><a ui-sref="settings"><i data-position="bottom" data-delay="50" |
70 | 70 | data-tooltip="Settings" |
71 | 71 | class="mdi-action-settings tooltipped"></i></a></li> |
72 | - <li><a ui-sref="logout"><i data-position="bottom" data-delay="50" data-tooltip="Logout" | |
72 | + <li><a ng-click="logout()" ui-sref="login"><i data-position="bottom" data-delay="50" data-tooltip="Logout" | |
73 | 73 | class="mdi-content-forward tooltipped"></i></a></li> |
74 | 74 | |
75 | 75 | |
... | ... | @@ -114,7 +114,7 @@ |
114 | 114 | </ul> |
115 | 115 | <li><a ui-sref="study">Study</a></li> |
116 | 116 | <li><a ui-sref="settings">Settings</a></li> |
117 | - <li><a ui-sref="logout">Logout</a></li> | |
117 | + <li><a ng-click="logout()">Logout</a></li> | |
118 | 118 | </ul> |
119 | 119 | </div> |
120 | 120 | </nav> |
... | ... | @@ -160,7 +160,6 @@ |
160 | 160 | <script src="scripts/RootController.js"></script> |
161 | 161 | <script src="scripts/SettingsController.js"></script> |
162 | 162 | <script src="scripts/LoginController.js"></script> |
163 | -<script src="scripts/LogoutController.js"></script> | |
164 | 163 | <script src="scripts/DeckController.js"></script> |
165 | 164 | <script src="scripts/RequestResetController.js"></script> |
166 | 165 | <script src="scripts/ClassAddController.js"></script> |
scripts/HelpController.js
View file @
a650201
... | ... | @@ -29,7 +29,7 @@ |
29 | 29 | " feed. Don't want to contribute cards? That's fine! By adding others' cards to your deck, you" + |
30 | 30 | ' help identify high-quality cards which should remain at the top of the feed for others to choose.' + |
31 | 31 | '</p><p>Based on the principles of spaced repetition, Flashy also intelligently determines which' + |
32 | - ' cards you are most at risk of forgetting, based on your review history. Recieve push ' + | |
32 | + ' cards you are most at risk of forgetting, based on your review history. Receive push ' + | |
33 | 33 | "notifications on your Android device's Chrome browser without installing any other app," + |
34 | 34 | " and we'll notify you when you have a few cards which need to be reviewed.</p>" |
35 | 35 | }, |
scripts/LogoutController.js
View file @
a650201
1 | -angular.module('flashy.LogoutController', ['ui.router']). | |
2 | - controller('LogoutController', ['$scope', '$state', '$http', '$timeout', 'UserService', | |
3 | - function($scope, $state, $http, $timeout, UserService) { | |
4 | - $http.post('/api/logout/').success(function() { | |
5 | - UserService.logout(); | |
6 | - $timeout(function() { | |
7 | - $state.go('login'); | |
8 | - }, 1000); | |
9 | - }).error(function() { | |
10 | - console.log('Problem logging out'); | |
11 | - }); | |
12 | - } | |
13 | - ]); |
scripts/RootController.js
View file @
a650201
... | ... | @@ -6,7 +6,6 @@ |
6 | 6 | $rootScope.currentSection = {}; |
7 | 7 | $rootScope.UserService = UserService; |
8 | 8 | |
9 | - | |
10 | 9 | //UserService.getUserData().then(function(data) { |
11 | 10 | // console.log(data); |
12 | 11 | // $rootScope.user = data; |
... | ... | @@ -63,6 +62,9 @@ |
63 | 62 | console.log('connection closed'); |
64 | 63 | }; |
65 | 64 | |
65 | + $scope.logout = function() { | |
66 | + UserService.logout($state); | |
67 | + }; | |
66 | 68 | $rootScope.$on('server_error', function(error) { |
67 | 69 | Materialize.toast('A server error occurred! Proceed with caution', 4000); |
68 | 70 | }); |
scripts/UserService.js
View file @
a650201
... | ... | @@ -39,9 +39,15 @@ |
39 | 39 | this.hasVerifiedEmail = function() { |
40 | 40 | return this.isResolved() && _user.is_confirmed; |
41 | 41 | }; |
42 | - this.logout = function() { | |
42 | + this.logout = function($state) { | |
43 | + $http.post('/api/logout/').success(function() { | |
44 | + if (!_user.locked)Materialize.toast('Logged out!', 1000); | |
45 | + }).error(function() { | |
46 | + console.log('Problem logging out'); | |
47 | + }); | |
43 | 48 | _user = false; |
44 | 49 | deferred.resolve({}); |
50 | + $state.go('login'); | |
45 | 51 | }; |
46 | 52 | this.addClass = function(section) { |
47 | 53 | _user.sections.push(section); |
... | ... | @@ -59,7 +65,12 @@ |
59 | 65 | if (!this.isLoggedIn()) return $state.go('login'); |
60 | 66 | if (!_user.sections.length) return $state.go('addclass'); |
61 | 67 | last_state = localStorage.getItem('last_state'); |
62 | - if (last_state) return $state.go(last_state, JSON.parse(localStorage.getItem('last_state_params'))); | |
68 | + if (last_state) { | |
69 | + last_state_params = JSON.parse(localStorage.getItem('last_state_params')); | |
70 | + if (last_state_params.sectionId && this.authorizedFor(last_state, last_state_params)) { | |
71 | + return $state.go(last_state, JSON.parse(localStorage.getItem('last_state_params'))); | |
72 | + } | |
73 | + } | |
63 | 74 | $state.go('feed', {sectionId: _user.sections[0].id}); |
64 | 75 | }; |
65 | 76 | this.authorizedFor = function(state, stateParams) { |
... | ... | @@ -72,8 +83,8 @@ |
72 | 83 | }; |
73 | 84 | this.showLockedMessage = function() { |
74 | 85 | Materialize.toast('You must verify your email address before continuing.' + |
75 | - '<a class="btn-flat cyan-text" onclick="rootscope.UserService.resendConfirmationEmail()">' + | |
76 | - 'Resend Verification Email</a>', 4000); | |
86 | + '<a class="btn-flat cyan-text" onclick="rootscope.UserService.resendConfirmationEmail()">' + | |
87 | + 'Resend Verification Email</a>', 4000); | |
77 | 88 | }; |
78 | 89 | this.noAuthRequired = function(state) { |
79 | 90 | if (['verifyemail'].indexOf(state.name) >= 0) { |