diff --git a/config.js b/config.js index a286816..d8ccc99 100644 --- a/config.js +++ b/config.js @@ -1,5 +1,4 @@ angular.module('flashy', [ - 'flashy.LogoutController', 'flashy.LoginController', 'flashy.RootController', 'flashy.FeedController', @@ -79,12 +78,6 @@ angular.module('flashy', [ templateUrl: 'templates/login.html', controller: 'LoginController' }). - state('logout', { - resolve: auth_resolve, - url: '/logout', - templateUrl: 'templates/logout.html', - controller: 'LogoutController' - }). state('root', { resolve: auth_resolve, url: '', diff --git a/home.html b/home.html index 86b042a..fb133ce 100644 --- a/home.html +++ b/home.html @@ -69,7 +69,7 @@
Based on the principles of spaced repetition, Flashy also intelligently determines which' + - ' cards you are most at risk of forgetting, based on your review history. Recieve push ' + + ' cards you are most at risk of forgetting, based on your review history. Receive push ' + "notifications on your Android device's Chrome browser without installing any other app," + " and we'll notify you when you have a few cards which need to be reviewed.
" }, diff --git a/scripts/LogoutController.js b/scripts/LogoutController.js deleted file mode 100644 index d1bcb5d..0000000 --- a/scripts/LogoutController.js +++ /dev/null @@ -1,13 +0,0 @@ -angular.module('flashy.LogoutController', ['ui.router']). - controller('LogoutController', ['$scope', '$state', '$http', '$timeout', 'UserService', - function($scope, $state, $http, $timeout, UserService) { - $http.post('/api/logout/').success(function() { - UserService.logout(); - $timeout(function() { - $state.go('login'); - }, 1000); - }).error(function() { - console.log('Problem logging out'); - }); - } - ]); diff --git a/scripts/RootController.js b/scripts/RootController.js index 09d1c50..d1d1783 100644 --- a/scripts/RootController.js +++ b/scripts/RootController.js @@ -6,7 +6,6 @@ angular.module('flashy.RootController', ['ui.router', 'ngResource', 'ngSanitize' $rootScope.currentSection = {}; $rootScope.UserService = UserService; - //UserService.getUserData().then(function(data) { // console.log(data); // $rootScope.user = data; @@ -63,6 +62,9 @@ angular.module('flashy.RootController', ['ui.router', 'ngResource', 'ngSanitize' console.log('connection closed'); }; + $scope.logout = function() { + UserService.logout($state); + }; $rootScope.$on('server_error', function(error) { Materialize.toast('A server error occurred! Proceed with caution', 4000); }); diff --git a/scripts/UserService.js b/scripts/UserService.js index 9ede76d..344bc83 100644 --- a/scripts/UserService.js +++ b/scripts/UserService.js @@ -39,9 +39,15 @@ angular.module('flashy.UserService', ['ui.router']). this.hasVerifiedEmail = function() { return this.isResolved() && _user.is_confirmed; }; - this.logout = function() { + this.logout = function($state) { + $http.post('/api/logout/').success(function() { + if (!_user.locked)Materialize.toast('Logged out!', 1000); + }).error(function() { + console.log('Problem logging out'); + }); _user = false; deferred.resolve({}); + $state.go('login'); }; this.addClass = function(section) { _user.sections.push(section); @@ -59,7 +65,12 @@ angular.module('flashy.UserService', ['ui.router']). if (!this.isLoggedIn()) return $state.go('login'); if (!_user.sections.length) return $state.go('addclass'); last_state = localStorage.getItem('last_state'); - if (last_state) return $state.go(last_state, JSON.parse(localStorage.getItem('last_state_params'))); + if (last_state) { + last_state_params = JSON.parse(localStorage.getItem('last_state_params')); + if (last_state_params.sectionId && this.authorizedFor(last_state, last_state_params)) { + return $state.go(last_state, JSON.parse(localStorage.getItem('last_state_params'))); + } + } $state.go('feed', {sectionId: _user.sections[0].id}); }; this.authorizedFor = function(state, stateParams) { @@ -72,8 +83,8 @@ angular.module('flashy.UserService', ['ui.router']). }; this.showLockedMessage = function() { Materialize.toast('You must verify your email address before continuing.' + - '' + - 'Resend Verification Email', 4000); + '' + + 'Resend Verification Email', 4000); }; this.noAuthRequired = function(state) { if (['verifyemail'].indexOf(state.name) >= 0) {