Commit 4fb8a3f360883fb8542df325c507c217e93f47da
1 parent
679e2b38e9
Exists in
master
and in
1 other branch
start handling locked account
Showing 1 changed file with 7 additions and 1 deletions Inline Diff
config.js
View file @
4fb8a3f
angular.module('flashy', [ | 1 | 1 | angular.module('flashy', [ | |
'flashy.LogoutController', | 2 | 2 | 'flashy.LogoutController', | |
'flashy.LoginController', | 3 | 3 | 'flashy.LoginController', | |
'flashy.RootController', | 4 | 4 | 'flashy.RootController', | |
'flashy.FeedController', | 5 | 5 | 'flashy.FeedController', | |
'flashy.DeckController', | 6 | 6 | 'flashy.DeckController', | |
'flashy.ClassAddController', | 7 | 7 | 'flashy.ClassAddController', | |
'flashy.RequestResetController', | 8 | 8 | 'flashy.RequestResetController', | |
'flashy.StudyController', | 9 | 9 | 'flashy.StudyController', | |
'flashy.UserService', | 10 | 10 | 'flashy.UserService', | |
'flashy.FlashcardDirective', | 11 | 11 | 'flashy.FlashcardDirective', | |
'flashy.ResetPasswordController', | 12 | 12 | 'flashy.ResetPasswordController', | |
'flashy.VerifyEmailController', | 13 | 13 | 'flashy.VerifyEmailController', | |
'flashy.CardListController', | 14 | 14 | 'flashy.CardListController', | |
'flashy.SettingsController', | 15 | 15 | 'flashy.SettingsController', | |
'ngCookies']). | 16 | 16 | 'ngCookies']). | |
config(function($stateProvider, $urlRouterProvider, $resourceProvider, $httpProvider, $locationProvider) { | 17 | 17 | config(function($stateProvider, $urlRouterProvider, $resourceProvider, $httpProvider, $locationProvider) { | |
'use strict'; | 18 | 18 | 'use strict'; | |
$httpProvider.defaults.withCredentials = true; | 19 | 19 | $httpProvider.defaults.withCredentials = true; | |
$httpProvider.defaults.xsrfCookieName = 'csrftoken'; | 20 | 20 | $httpProvider.defaults.xsrfCookieName = 'csrftoken'; | |
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | 21 | 21 | $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | |
$resourceProvider.defaults.stripTrailingSlashes = false; | 22 | 22 | $resourceProvider.defaults.stripTrailingSlashes = false; | |
var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | 23 | 23 | var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | |
arrayMethods.forEach(attachArrayMethodsToNodeList); | 24 | 24 | arrayMethods.forEach(attachArrayMethodsToNodeList); | |
function attachArrayMethodsToNodeList(methodName) { | 25 | 25 | function attachArrayMethodsToNodeList(methodName) { | |
if (methodName !== 'length') { | 26 | 26 | if (methodName !== 'length') { | |
NodeList.prototype[methodName] = Array.prototype[methodName]; | 27 | 27 | NodeList.prototype[methodName] = Array.prototype[methodName]; | |
} | 28 | 28 | } | |
}; | 29 | 29 | } | |
30 | 30 | |||
$httpProvider.interceptors.push(function($q) { | 31 | 31 | $httpProvider.interceptors.push(function($q) { | |
return { | 32 | 32 | return { | |
'responseError': function(rejection) { | 33 | 33 | 'responseError': function(rejection) { | |
if (rejection.status >= 500) { | 34 | 34 | if (rejection.status >= 500) { | |
console.log('got error'); | 35 | 35 | console.log('got error'); | |
console.log(rejection); | 36 | 36 | console.log(rejection); | |
$('body').html('<div class="card">Sorry, the server is not serving requests properly. Try again later</div>'); | 37 | 37 | $('body').html('<div class="card">Sorry, the server is not serving requests properly. Try again later</div>'); | |
38 | } | |||
39 | if(rejection.status == 403){ | |||
40 | console.log(rejection); | |||
41 | if(rejection.data && rejection.data.detail == "Please verify your email before continuing"){ | |||
42 | material | |||
43 | } | |||
} | 38 | 44 | } | |
return $q.reject(rejection); | 39 | 45 | return $q.reject(rejection); | |
} | 40 | 46 | } | |
}; | 41 | 47 | }; | |
}); | 42 | 48 | }); | |
$locationProvider.html5Mode(true); | 43 | 49 | $locationProvider.html5Mode(true); | |
$urlRouterProvider.otherwise('/404'); | 44 | 50 | $urlRouterProvider.otherwise('/404'); | |
var auth_resolve = { | 45 | 51 | var auth_resolve = { | |
authorize: function($q, $state, $stateParams, UserService) { | 46 | 52 | authorize: function($q, $state, $stateParams, UserService) { | |
console.log('resolving user before continuing'); | 47 | 53 | console.log('resolving user before continuing'); | |
var redirectAsNeeded = function() { | 48 | 54 | var redirectAsNeeded = function() { | |
if (!UserService.isLoggedIn()) { | 49 | 55 | if (!UserService.isLoggedIn()) { | |
console.log(UserService.getUserData()); | 50 | 56 | console.log(UserService.getUserData()); | |
console.log('making the user log in'); | 51 | 57 | console.log('making the user log in'); | |
$state.go('login'); | 52 | 58 | $state.go('login'); | |
} | 53 | 59 | } | |
if (!UserService.authorizedFor($state, $stateParams)) { | 54 | 60 | if (!UserService.authorizedFor($state, $stateParams)) { | |
$state.go('addclass'); | 55 | 61 | $state.go('addclass'); | |
} | 56 | 62 | } | |
}; | 57 | 63 | }; | |
if (UserService.isResolved()) return redirectAsNeeded(); | 58 | 64 | if (UserService.isResolved()) return redirectAsNeeded(); | |
return UserService.getUserData().then(redirectAsNeeded); | 59 | 65 | return UserService.getUserData().then(redirectAsNeeded); | |
} | 60 | 66 | } | |
}; | 61 | 67 | }; | |
$stateProvider. | 62 | 68 | $stateProvider. | |
state('login', { | 63 | 69 | state('login', { | |
url: '/login', | 64 | 70 | url: '/login', | |
templateUrl: 'templates/login.html', | 65 | 71 | templateUrl: 'templates/login.html', | |
controller: 'LoginController' | 66 | 72 | controller: 'LoginController' | |
}). | 67 | 73 | }). | |
state('logout', { | 68 | 74 | state('logout', { | |
resolve: auth_resolve, | 69 | 75 | resolve: auth_resolve, | |
url: '/logout', | 70 | 76 | url: '/logout', | |
templateUrl: 'templates/logout.html', | 71 | 77 | templateUrl: 'templates/logout.html', | |
controller: 'LogoutController' | 72 | 78 | controller: 'LogoutController' | |
}). | 73 | 79 | }). | |
state('root', { | 74 | 80 | state('root', { | |
resolve: auth_resolve, | 75 | 81 | resolve: auth_resolve, | |
url: '/', | 76 | 82 | url: '/', | |
controller: 'RootController' | 77 | 83 | controller: 'RootController' | |
}). | 78 | 84 | }). | |
state('feed', { | 79 | 85 | state('feed', { | |
resolve: auth_resolve, | 80 | 86 | resolve: auth_resolve, | |
url: '/feed/{sectionId}', | 81 | 87 | url: '/feed/{sectionId}', | |
templateUrl: 'templates/feed.html', | 82 | 88 | templateUrl: 'templates/feed.html', | |
controller: 'FeedController' | 83 | 89 | controller: 'FeedController' | |
}). | 84 | 90 | }). | |
state('cardlist', { | 85 | 91 | state('cardlist', { | |
resolve: auth_resolve, | 86 | 92 | resolve: auth_resolve, | |
url: '/cards/{sectionId}', | 87 | 93 | url: '/cards/{sectionId}', | |
templateUrl: 'templates/cardlist.html', | 88 | 94 | templateUrl: 'templates/cardlist.html', | |
controller: 'CardListController' | 89 | 95 | controller: 'CardListController' | |
}). | 90 | 96 | }). | |
state('addclass', { | 91 | 97 | state('addclass', { | |
resolve: auth_resolve, | 92 | 98 | resolve: auth_resolve, | |
url: '/addclass', | 93 | 99 | url: '/addclass', | |
templateUrl: 'templates/addclass.html', | 94 | 100 | templateUrl: 'templates/addclass.html', | |
controller: 'ClassAddController' | 95 | 101 | controller: 'ClassAddController' | |
}). | 96 | 102 | }). | |
state('deck', { | 97 | 103 | state('deck', { | |
resolve: auth_resolve, | 98 | 104 | resolve: auth_resolve, | |
url: '/deck/{sectionId}', | 99 | 105 | url: '/deck/{sectionId}', | |
templateUrl: 'templates/deck.html', | 100 | 106 | templateUrl: 'templates/deck.html', | |
controller: 'DeckController' | 101 | 107 | controller: 'DeckController' | |
}). | 102 | 108 | }). | |
state('study', { | 103 | 109 | state('study', { | |
resolve: auth_resolve, | 104 | 110 | resolve: auth_resolve, | |
url: '/study', | 105 | 111 | url: '/study', | |
templateUrl: 'templates/study.html', | 106 | 112 | templateUrl: 'templates/study.html', | |
controller: 'StudyController' | 107 | 113 | controller: 'StudyController' | |
}). | 108 | 114 | }). | |
state('flashcard', { | 109 | 115 | state('flashcard', { | |
resolve: auth_resolve, | 110 | 116 | resolve: auth_resolve, | |
url: '/flashcard', | 111 | 117 | url: '/flashcard', | |
templateUrl: 'templates/flashcard.html', | 112 | 118 | templateUrl: 'templates/flashcard.html', | |
controller: 'FlashcardController' | 113 | 119 | controller: 'FlashcardController' | |
}). | 114 | 120 | }). | |
state('settings', { | 115 | 121 | state('settings', { | |
resolve: auth_resolve, | 116 | 122 | resolve: auth_resolve, | |
url: '/settings', | 117 | 123 | url: '/settings', | |
templateUrl: 'templates/settings.html', | 118 | 124 | templateUrl: 'templates/settings.html', | |
controller: 'SettingsController' | 119 | 125 | controller: 'SettingsController' | |
}). | 120 | 126 | }). | |
state('requestpasswordreset', { | 121 | 127 | state('requestpasswordreset', { | |
url: '/requestpasswordreset', | 122 | 128 | url: '/requestpasswordreset', | |
templateUrl: 'templates/requestpasswordreset.html', | 123 | 129 | templateUrl: 'templates/requestpasswordreset.html', | |
controller: 'RequestResetController' | 124 | 130 | controller: 'RequestResetController' | |
}). | 125 | 131 | }). | |
state('resetpassword', { | 126 | 132 | state('resetpassword', { | |
url: '/resetpassword/{uid}/{token}', | 127 | 133 | url: '/resetpassword/{uid}/{token}', | |
templateUrl: 'templates/resetpassword.html', | 128 | 134 | templateUrl: 'templates/resetpassword.html', | |
controller: 'ResetPasswordController' | 129 | 135 | controller: 'ResetPasswordController' | |
}). | 130 | 136 | }). | |
state('verifyemail', { | 131 | 137 | state('verifyemail', { | |
resolve: auth_resolve, | 132 | 138 | resolve: auth_resolve, | |
url: '/verifyemail/{key}', | 133 | 139 | url: '/verifyemail/{key}', | |
templateUrl: 'templates/verifyemail.html', | 134 | 140 | templateUrl: 'templates/verifyemail.html', | |
controller: 'VerifyEmailController' | 135 | 141 | controller: 'VerifyEmailController' | |
}). | 136 | 142 | }). | |
state('404', { | 137 | 143 | state('404', { | |
url: '/404', | 138 | 144 | url: '/404', | |
template: "<h1>This page doesn't exist!</h1>" | 139 | 145 | template: "<h1>This page doesn't exist!</h1>" | |
}); | 140 | 146 | }); | |
}). | 141 | 147 | }). | |
run(function($rootScope, $state, $stateParams, $location, UserService) { | 142 | 148 | run(function($rootScope, $state, $stateParams, $location, UserService) { | |
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | 143 | 149 | $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | |
console.log('failed to change state: ' + error); | 144 | 150 | console.log('failed to change state: ' + error); | |
$state.go('login'); | 145 | 151 | $state.go('login'); | |
}); | 146 | 152 | }); | |
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { | 147 | 153 | $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { | |
if (['feed', 'deck', 'cardlist'].indexOf(toState.name) >= 0) { | 148 | 154 | if (['feed', 'deck', 'cardlist'].indexOf(toState.name) >= 0) { | |
localStorage.setItem('last_state', toState.name); | 149 | 155 | localStorage.setItem('last_state', toState.name); | |
localStorage.setItem('last_state_params', JSON.stringify(toParams)); | 150 | 156 | localStorage.setItem('last_state_params', JSON.stringify(toParams)); | |
} | 151 | 157 | } | |
}); | 152 | 158 | }); | |
}); | 153 | 159 | }); |