diff --git a/config.js b/config.js index 10cd1ca..5e83e05 100644 --- a/config.js +++ b/config.js @@ -13,130 +13,127 @@ angular.module('flashy', [ 'flashy.VerifyEmailController', 'flashy.CardListController', 'ngCookies']). - config(['$stateProvider', '$urlRouterProvider', '$httpProvider', - '$locationProvider', - function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { - 'use strict'; - $httpProvider.defaults.withCredentials = true; - $httpProvider.defaults.xsrfCookieName = 'csrftoken'; - $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; + config(function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { + 'use strict'; + $httpProvider.defaults.withCredentials = true; + $httpProvider.defaults.xsrfCookieName = 'csrftoken'; + $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; - var arrayMethods = Object.getOwnPropertyNames(Array.prototype); - arrayMethods.forEach(attachArrayMethodsToNodeList); - function attachArrayMethodsToNodeList(methodName) { - if (methodName !== 'length') { - NodeList.prototype[methodName] = Array.prototype[methodName]; - } - }; + var arrayMethods = Object.getOwnPropertyNames(Array.prototype); + arrayMethods.forEach(attachArrayMethodsToNodeList); + function attachArrayMethodsToNodeList(methodName) { + if (methodName !== 'length') { + NodeList.prototype[methodName] = Array.prototype[methodName]; + } + }; - $httpProvider.interceptors.push(function($q) { - return { - 'responseError': function(rejection) { - if (rejection.status >= 500) { - console.log('got error'); - console.log(rejection); - $('body').html('
Sorry, the server is not serving requests properly. Try again later
'); - } - return $q.reject(rejection); - } - }; - }); - $locationProvider.html5Mode(true); - $urlRouterProvider.otherwise('/login'); - var auth_resolve = { - authorize: ['$q', 'UserService', - function($q, UserService) { - console.log('resolving user before continuing'); - return UserService.getUserData(); + $httpProvider.interceptors.push(function($q) { + return { + 'responseError': function(rejection) { + if (rejection.status >= 500) { + console.log('got error'); + console.log(rejection); + $('body').html('
Sorry, the server is not serving requests properly. Try again later
'); } - ] + return $q.reject(rejection); + } }; - $stateProvider. - state('login', { - url: '/login', - 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: '', - templateUrl: 'templates/root.html', - controller: 'RootController' - }). - state('feed', { - resolve: auth_resolve, - url: '/feed/{sectionId}', - templateUrl: 'templates/feed.html', - controller: 'FeedController' - }). - state('cardlist', { - resolve: auth_resolve, - url: '/cards/{sectionId}', - templateUrl: 'templates/cardlist.html', - controller: 'CardListController' - }). - state('addclass', { - resolve: auth_resolve, - url: '/addclass', - templateUrl: 'templates/addclass.html', - controller: 'ClassAddController' - }). - state('deck', { - resolve: auth_resolve, - url: '/deck/{sectionId}', - templateUrl: 'templates/deck.html', - controller: 'DeckController' - }). - state('study', { - resolve: auth_resolve, - url: '/study', - templateUrl: 'templates/study.html', - controller: 'StudyController' - }). - state('flashcard', { - resolve: auth_resolve, - url: '/flashcard', - templateUrl: 'templates/flashcard.html', - controller: 'FlashcardController' - }). - state('requestpasswordreset', { - url: '/requestpasswordreset', - templateUrl: 'templates/requestpasswordreset.html', - controller: 'RequestResetController' - }). - state('resetpassword', { - url: '/resetpassword/{uid}/{token}', - templateUrl: 'templates/resetpassword.html', - controller: 'ResetPasswordController' - }). - state('verifyemail', { - resolve: auth_resolve, - url: '/verifyemail/{key}', - templateUrl: 'templates/verifyemail.html', - controller: 'VerifyEmailController' - }); - } - ]). - run(['$rootScope', '$state', '$stateParams', '$location', 'UserService', - function($rootScope, $state, $stateParams, $location, UserService) { - $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { - if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name); - if (toState.name == 'login') return console.log('we are going to login anyway; just let it happen :)'); - if (!UserService.isUserResolved()) return console.log('user not yet resolved; hold off'); - $rootScope.returnToState = toState; - $rootScope.returnToStateParams = toStateParams; - console.log('going to ' + toState.name + ' after login'); - $state.go('login'); - }); - $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { - console.log('failed to change state: ' + error); - $state.go('login'); + }); + $locationProvider.html5Mode(true); + $urlRouterProvider.otherwise('/login'); + var auth_resolve = { + authorize: function($q, UserService) { + console.log('resolving user before continuing'); + return UserService.getUserData(); + } + }; + $stateProvider. + state('login', { + url: '/login', + 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: '', + templateUrl: 'templates/root.html', + controller: 'RootController' + }). + state('feed', { + resolve: auth_resolve, + url: '/feed/{sectionId}', + templateUrl: 'templates/feed.html', + controller: 'FeedController' + }). + state('cardlist', { + resolve: auth_resolve, + url: '/cards/{sectionId}', + templateUrl: 'templates/cardlist.html', + controller: 'CardListController' + }). + state('addclass', { + resolve: auth_resolve, + url: '/addclass', + templateUrl: 'templates/addclass.html', + controller: 'ClassAddController' + }). + state('deck', { + resolve: auth_resolve, + url: '/deck/{sectionId}', + templateUrl: 'templates/deck.html', + controller: 'DeckController' + }). + state('study', { + resolve: auth_resolve, + url: '/study', + templateUrl: 'templates/study.html', + controller: 'StudyController' + }). + state('flashcard', { + resolve: auth_resolve, + url: '/flashcard', + templateUrl: 'templates/flashcard.html', + controller: 'FlashcardController' + }). + state('requestpasswordreset', { + url: '/requestpasswordreset', + templateUrl: 'templates/requestpasswordreset.html', + controller: 'RequestResetController' + }). + state('resetpassword', { + url: '/resetpassword/{uid}/{token}', + templateUrl: 'templates/resetpassword.html', + controller: 'ResetPasswordController' + }). + state('verifyemail', { + resolve: auth_resolve, + url: '/verifyemail/{key}', + templateUrl: 'templates/verifyemail.html', + controller: 'VerifyEmailController' }); - } - ]); + }). + run(function($rootScope, $state, $stateParams, $location, UserService) { + $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { + if (toState.name == 'login') { + if (UserService.isLoggedIn()) return console.log('already logged in') + $state.go('addclass'); + else return console.log('we are going to login anyway'); + } + if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name); + + if (!UserService.isUserResolved()) return console.log('user not yet resolved; hold off'); + $rootScope.returnToState = toState; + $rootScope.returnToStateParams = toStateParams; + console.log('going to ' + toState.name + ' after login'); + + }); + $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { + console.log('failed to change state: ' + error); + $state.go('login'); + }); + }); diff --git a/home.html b/home.html index 716c1d7..305500b 100644 --- a/home.html +++ b/home.html @@ -13,66 +13,69 @@ Flashy
+
-