Commit f05ccab3073246cc25a287c16eace95374d62a4e
1 parent
e384f6cef4
Exists in
master
and in
1 other branch
half-implemented login redirection
Showing 8 changed files with 82 additions and 48 deletions Side-by-side Diff
config.js
View file @
f05ccab
... | ... | @@ -10,11 +10,11 @@ |
10 | 10 | 'flashy.UserService', |
11 | 11 | 'flashy.FlashcardDirective', |
12 | 12 | 'flashy.ResetPasswordController', |
13 | - 'flashy.VerifyEmailController', | |
13 | + 'flashy.VerifyEmailController', | |
14 | 14 | 'ngCookies']). |
15 | 15 | config(['$stateProvider', '$urlRouterProvider', '$httpProvider', |
16 | 16 | '$locationProvider', |
17 | - function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | |
17 | + function ($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | |
18 | 18 | 'use strict'; |
19 | 19 | $httpProvider.defaults.withCredentials = true; |
20 | 20 | $httpProvider.defaults.xsrfCookieName = 'csrftoken'; |
21 | 21 | |
... | ... | @@ -35,12 +35,27 @@ |
35 | 35 | state('root', { |
36 | 36 | url: '/', |
37 | 37 | templateUrl: 'templates/root.html', |
38 | - controller: 'RootController' | |
38 | + controller: 'RootController', | |
39 | + resolve: { | |
40 | + authorize: ['UserService', | |
41 | + function (UserService) { | |
42 | + return UserService.getUserData(); | |
43 | + } | |
44 | + ] | |
45 | + } | |
46 | + | |
39 | 47 | }). |
40 | 48 | state('feed', { |
41 | 49 | url: '/feed', |
42 | 50 | templateUrl: 'templates/feed.html', |
43 | - controller: 'FeedController' | |
51 | + controller: 'FeedController', | |
52 | + resolve: { | |
53 | + authorize: ['UserService', | |
54 | + function (UserService) { | |
55 | + return UserService.getUserData(); | |
56 | + } | |
57 | + ] | |
58 | + } | |
44 | 59 | }). |
45 | 60 | state('addclass', { |
46 | 61 | url: '/addclass', |
... | ... | @@ -67,15 +82,25 @@ |
67 | 82 | templateUrl: 'templates/requestpasswordreset.html', |
68 | 83 | controller: 'RequestResetController' |
69 | 84 | }). |
70 | - state('resetpassword', { | |
71 | - url: '/resetpassword/{uid}/{token}', | |
72 | - templateUrl: 'templates/resetpassword.html', | |
73 | - controller: 'ResetPasswordController' | |
74 | - }). | |
75 | - state('verifyemail', { | |
76 | - url: '/verifyemail/{key}', | |
77 | - templateUrl: 'templates/verifyemail.html', | |
78 | - controller: 'VerifyEmailController' | |
79 | - }); | |
80 | - }]); | |
85 | + state('resetpassword', { | |
86 | + url: '/resetpassword/{uid}/{token}', | |
87 | + templateUrl: 'templates/resetpassword.html', | |
88 | + controller: 'ResetPasswordController' | |
89 | + }). | |
90 | + state('verifyemail', { | |
91 | + url: '/verifyemail/{key}', | |
92 | + templateUrl: 'templates/verifyemail.html', | |
93 | + controller: 'VerifyEmailController' | |
94 | + }); | |
95 | + }]).run(['$rootScope', '$state', '$stateParams', '$location', 'UserService', | |
96 | + function ($rootScope, $state, $stateParams, $location, UserService) { | |
97 | + $rootScope.$on('$stateChangeStart', function (event, toState, toStateParams) { | |
98 | + $rootScope.returnToState = toState; | |
99 | + $rootScope.returnToStateParams = toStateParams; | |
100 | + console.log('going to' + toState.name); | |
101 | + console.log(UserService.isLoggedIn()); | |
102 | + if (!UserService.isLoggedIn() && toState.name != 'login') $location.path('login'); | |
103 | + }); | |
104 | + } | |
105 | + ]); |
home.html
View file @
f05ccab
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | |
12 | 12 | <body ng-controller="RootController"> |
13 | 13 | |
14 | -<ul id="slide-out" class="side-nav fixed"> | |
14 | +<ul ng-show="UserService.isLoggedIn()" id="slide-out" class="side-nav fixed"> | |
15 | 15 | <ul class="collapsible collapsible-accordion"> |
16 | 16 | <div class = "top"> |
17 | 17 | <li id = "sidebar"> |
... | ... | @@ -25,6 +25,7 @@ |
25 | 25 | <li class="bold"><a ui-sref="addclass">Add Class</a></li> |
26 | 26 | <li class="bold"><a ui-sref="feed">Feed</a></li> |
27 | 27 | <li class="bold"><a ui-sref="deck">Deck</a></li> |
28 | + <li class="bold"><a ui-sref="logout">Logout</a></li> | |
28 | 29 | </ul> |
29 | 30 | </div> |
30 | 31 | </li> |
... | ... | @@ -34,12 +35,6 @@ |
34 | 35 | |
35 | 36 | </ul> |
36 | 37 | |
37 | -<script type = "text/javascript"> | |
38 | - | |
39 | -$("#top").collapsible('accordion'); | |
40 | - | |
41 | -</script> | |
42 | - | |
43 | 38 | <div class="container" ui-view></div> |
44 | 39 | <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script> |
45 | 40 | <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script> |
... | ... | @@ -63,7 +58,7 @@ |
63 | 58 | <script src="scripts/ClassAddController.js"></script> |
64 | 59 | <script src="scripts/StudyController.js"></script> |
65 | 60 | <script src="scripts/VerifyEmailController.js"></script> |
66 | -<script src="scripts/SidebarController.js"></script> | |
61 | +<!--<script src="scripts/SidebarController.js"></script>--> | |
67 | 62 | |
68 | 63 | <!-- Services --> |
69 | 64 | <script src="scripts/UserService.js"></script> |
materialize/sass/components/_variables.scss
View file @
f05ccab
scripts/LoginController.js
View file @
f05ccab
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | controller('LoginController', ['$scope', '$state', '$http', 'UserService', |
4 | 4 | function($scope, $state, $http, UserService) { |
5 | 5 | 'use strict'; |
6 | + if (UserService.isLoggedIn()) state.go('/addclass'); | |
6 | 7 | $scope.uniqueError = false; |
7 | 8 | $scope.loginError = false; |
8 | 9 | $scope.login = function(email, password) { |
... | ... | @@ -11,7 +12,7 @@ |
11 | 12 | 'password': password |
12 | 13 | })). |
13 | 14 | success(function(data) { |
14 | - UserService.getUserData(); | |
15 | + UserService.setUserData(data); | |
15 | 16 | $state.go('feed'); |
16 | 17 | console.log(data); |
17 | 18 | }). |
scripts/LogoutController.js
View file @
f05ccab
1 | 1 | angular.module('flashy.LogoutController', ['ui.router']). |
2 | - controller('LogoutController', ['$scope', '$state', '$timeout', | |
3 | - function($scope, $state, $timeout) { | |
4 | - $timeout(function($state) { | |
5 | - $state.go('home'); | |
6 | - }, 1000); | |
2 | + controller('LogoutController', ['$scope', '$state', '$http', '$timeout', | |
3 | + function($scope, $state, $http, $timeout) { | |
4 | + $http.post('/api/logout/').success(function() { | |
5 | + $timeout(function() { | |
6 | + $state.go('login'); | |
7 | + }, 1000); | |
8 | + }).error(function() { | |
9 | + console.log('Problem logging out'); | |
10 | + }); | |
7 | 11 | } |
8 | 12 | ]); |
scripts/RootController.js
View file @
f05ccab
1 | 1 | angular.module('flashy.RootController', ['ui.router']). |
2 | 2 | |
3 | 3 | controller('RootController', ['$scope', '$state', 'UserService', function($scope, $state, UserService) { |
4 | - if (UserService.isLoggedIn()) $state.go('login'); | |
5 | - else $state.go('addclass'); | |
4 | + //UserService.getUserData(); | |
5 | + $('#top').collapsible('accordion'); | |
6 | + //if (UserService.isLoggedIn()) $state.go('login'); | |
7 | + //else $state.go('addclass'); | |
6 | 8 | }]); |
scripts/UserService.js
View file @
f05ccab
1 | 1 | angular.module('flashy.UserService', ['ui.router']). |
2 | - service('UserService', function($http, $q) { | |
3 | - var _user = null; | |
4 | - this.getUserData = function() { | |
2 | + service('UserService', function ($http, $q) { | |
3 | + var _user = undefined; | |
4 | + this.getUserData = function () { | |
5 | 5 | var deferred = $q.defer(); |
6 | - $http.get('/api/user/me').success(function(data) { | |
6 | + if (angular.isDefined(_user)) { | |
7 | + deferred.resolve(_user); | |
8 | + return deferred.promise; | |
9 | + } | |
10 | + $http.get('/api/me/').success(function (data) { | |
11 | + console.log('user is logged in!') | |
7 | 12 | deferred.resolve(data); |
8 | - }).error(function() { | |
13 | + }).error(function () { | |
9 | 14 | deferred.reject('error getting own data'); |
10 | 15 | console.log(deferred); |
11 | 16 | }); |
12 | - _user = deferred.promise; | |
13 | - return _user; | |
17 | + return deferred.promise; | |
14 | 18 | }; |
15 | - this.isLoggedIn = function() { | |
16 | - return !_user; | |
19 | + this.setUserData = function(data){ | |
20 | + _user = data; | |
21 | + } | |
22 | + this.isLoggedIn = function () { | |
23 | + return !(!angular.isDefined(_user) && !_user); | |
17 | 24 | }; |
18 | 25 | }); |
styles/materialize.css
View file @
f05ccab
... | ... | @@ -2067,7 +2067,7 @@ |
2067 | 2067 | .pagination li.active a { |
2068 | 2068 | color: #fff; } |
2069 | 2069 | .pagination li.active { |
2070 | - background-color: #e0e0e0; } | |
2070 | + background-color: #3e1944; } | |
2071 | 2071 | .pagination li.disabled a { |
2072 | 2072 | color: #999; } |
2073 | 2073 | .pagination li i { |
... | ... | @@ -2163,7 +2163,7 @@ |
2163 | 2163 | footer.page-footer { |
2164 | 2164 | margin-top: 20px; |
2165 | 2165 | padding-top: 20px; |
2166 | - background-color: #e0e0e0; } | |
2166 | + background-color: #3e1944; } | |
2167 | 2167 | footer.page-footer .footer-copyright { |
2168 | 2168 | overflow: hidden; |
2169 | 2169 | height: 50px; |
... | ... | @@ -5052,7 +5052,7 @@ |
5052 | 5052 | |
5053 | 5053 | nav { |
5054 | 5054 | color: #fff; |
5055 | - background-color: #e0e0e0; | |
5055 | + background-color: #3e1944; | |
5056 | 5056 | width: 100%; |
5057 | 5057 | height: 56px; |
5058 | 5058 | line-height: 56px; } |
... | ... | @@ -5566,7 +5566,7 @@ |
5566 | 5566 | letter-spacing: 0.8px; |
5567 | 5567 | width: 15%; } |
5568 | 5568 | .tabs .tab a { |
5569 | - color: #e0e0e0; | |
5569 | + color: #3e1944; | |
5570 | 5570 | display: block; |
5571 | 5571 | width: 100%; |
5572 | 5572 | height: 100%; |
5573 | 5573 | |
... | ... | @@ -5576,12 +5576,12 @@ |
5576 | 5576 | -ms-transition: color 0.28s ease; |
5577 | 5577 | transition: color 0.28s ease; } |
5578 | 5578 | .tabs .tab a:hover { |
5579 | - color: white; } | |
5579 | + color: #82348f; } | |
5580 | 5580 | .tabs .indicator { |
5581 | 5581 | position: absolute; |
5582 | 5582 | bottom: 0; |
5583 | 5583 | height: 2px; |
5584 | - background-color: white; | |
5584 | + background-color: #712e7c; | |
5585 | 5585 | will-change: left, right; } |
5586 | 5586 | |
5587 | 5587 | .tabs .tab { |
... | ... | @@ -6855,7 +6855,7 @@ |
6855 | 6855 | } |
6856 | 6856 | |
6857 | 6857 | .side-nav .collapsible-body li.active, .side-nav.fixed .collapsible-body li.active { |
6858 | - background-color: #e0e0e0; } | |
6858 | + background-color: #3e1944; } | |
6859 | 6859 | .side-nav .collapsible-body li.active a, .side-nav.fixed .collapsible-body li.active a { |
6860 | 6860 | color: #fff; } |
6861 | 6861 |