diff --git a/config.js b/config.js
index 34422a1..4c166d0 100644
--- a/config.js
+++ b/config.js
@@ -10,11 +10,11 @@ angular.module('flashy', [
'flashy.UserService',
'flashy.FlashcardDirective',
'flashy.ResetPasswordController',
- 'flashy.VerifyEmailController',
+ 'flashy.VerifyEmailController',
'ngCookies']).
config(['$stateProvider', '$urlRouterProvider', '$httpProvider',
'$locationProvider',
- function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
+ function ($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
'use strict';
$httpProvider.defaults.withCredentials = true;
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
@@ -35,12 +35,27 @@ angular.module('flashy', [
state('root', {
url: '/',
templateUrl: 'templates/root.html',
- controller: 'RootController'
+ controller: 'RootController',
+ resolve: {
+ authorize: ['UserService',
+ function (UserService) {
+ return UserService.getUserData();
+ }
+ ]
+ }
+
}).
state('feed', {
url: '/feed',
templateUrl: 'templates/feed.html',
- controller: 'FeedController'
+ controller: 'FeedController',
+ resolve: {
+ authorize: ['UserService',
+ function (UserService) {
+ return UserService.getUserData();
+ }
+ ]
+ }
}).
state('addclass', {
url: '/addclass',
@@ -67,14 +82,24 @@ angular.module('flashy', [
templateUrl: 'templates/requestpasswordreset.html',
controller: 'RequestResetController'
}).
- state('resetpassword', {
- url: '/resetpassword/{uid}/{token}',
- templateUrl: 'templates/resetpassword.html',
- controller: 'ResetPasswordController'
- }).
- state('verifyemail', {
- url: '/verifyemail/{key}',
- templateUrl: 'templates/verifyemail.html',
- controller: 'VerifyEmailController'
- });
- }]);
+ state('resetpassword', {
+ url: '/resetpassword/{uid}/{token}',
+ templateUrl: 'templates/resetpassword.html',
+ controller: 'ResetPasswordController'
+ }).
+ state('verifyemail', {
+ 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) {
+ $rootScope.returnToState = toState;
+ $rootScope.returnToStateParams = toStateParams;
+ console.log('going to' + toState.name);
+ console.log(UserService.isLoggedIn());
+ if (!UserService.isLoggedIn() && toState.name != 'login') $location.path('login');
+ });
+ }
+ ]);
diff --git a/home.html b/home.html
index a886bde..16249d7 100644
--- a/home.html
+++ b/home.html
@@ -11,7 +11,7 @@
-
+
-
-
@@ -63,7 +58,7 @@ $("#top").collapsible('accordion');
-
+
diff --git a/materialize/sass/components/_variables.scss b/materialize/sass/components/_variables.scss
index 2421c72..62a831d 100644
--- a/materialize/sass/components/_variables.scss
+++ b/materialize/sass/components/_variables.scss
@@ -1,5 +1,5 @@
/*** Colors ***/
-$primary-color: color("grey", "lighten-2") !default;
+$primary-color: #3e1944 !default;
$primary-color-light: lighten($primary-color, 15%) !default;
$primary-color-dark: darken($primary-color, 15%) !default;
diff --git a/scripts/LoginController.js b/scripts/LoginController.js
index f0fffd4..d2c0f88 100644
--- a/scripts/LoginController.js
+++ b/scripts/LoginController.js
@@ -3,6 +3,7 @@ angular.module('flashy.LoginController', ['ui.router']).
controller('LoginController', ['$scope', '$state', '$http', 'UserService',
function($scope, $state, $http, UserService) {
'use strict';
+ if (UserService.isLoggedIn()) state.go('/addclass');
$scope.uniqueError = false;
$scope.loginError = false;
$scope.login = function(email, password) {
@@ -11,7 +12,7 @@ angular.module('flashy.LoginController', ['ui.router']).
'password': password
})).
success(function(data) {
- UserService.getUserData();
+ UserService.setUserData(data);
$state.go('feed');
console.log(data);
}).
diff --git a/scripts/LogoutController.js b/scripts/LogoutController.js
index 45614ca..0e81e08 100644
--- a/scripts/LogoutController.js
+++ b/scripts/LogoutController.js
@@ -1,8 +1,12 @@
angular.module('flashy.LogoutController', ['ui.router']).
- controller('LogoutController', ['$scope', '$state', '$timeout',
- function($scope, $state, $timeout) {
- $timeout(function($state) {
- $state.go('home');
- }, 1000);
+ controller('LogoutController', ['$scope', '$state', '$http', '$timeout',
+ function($scope, $state, $http, $timeout) {
+ $http.post('/api/logout/').success(function() {
+ $timeout(function() {
+ $state.go('login');
+ }, 1000);
+ }).error(function() {
+ console.log('Problem logging out');
+ });
}
]);
diff --git a/scripts/RootController.js b/scripts/RootController.js
index e2738c1..4397bdd 100644
--- a/scripts/RootController.js
+++ b/scripts/RootController.js
@@ -1,6 +1,8 @@
angular.module('flashy.RootController', ['ui.router']).
controller('RootController', ['$scope', '$state', 'UserService', function($scope, $state, UserService) {
- if (UserService.isLoggedIn()) $state.go('login');
- else $state.go('addclass');
+ //UserService.getUserData();
+ $('#top').collapsible('accordion');
+ //if (UserService.isLoggedIn()) $state.go('login');
+ //else $state.go('addclass');
}]);
diff --git a/scripts/UserService.js b/scripts/UserService.js
index e1de75a..da5baa4 100644
--- a/scripts/UserService.js
+++ b/scripts/UserService.js
@@ -1,18 +1,25 @@
angular.module('flashy.UserService', ['ui.router']).
- service('UserService', function($http, $q) {
- var _user = null;
- this.getUserData = function() {
+ service('UserService', function ($http, $q) {
+ var _user = undefined;
+ this.getUserData = function () {
var deferred = $q.defer();
- $http.get('/api/user/me').success(function(data) {
+ if (angular.isDefined(_user)) {
+ deferred.resolve(_user);
+ return deferred.promise;
+ }
+ $http.get('/api/me/').success(function (data) {
+ console.log('user is logged in!')
deferred.resolve(data);
- }).error(function() {
+ }).error(function () {
deferred.reject('error getting own data');
console.log(deferred);
});
- _user = deferred.promise;
- return _user;
+ return deferred.promise;
};
- this.isLoggedIn = function() {
- return !_user;
+ this.setUserData = function(data){
+ _user = data;
+ }
+ this.isLoggedIn = function () {
+ return !(!angular.isDefined(_user) && !_user);
};
});
diff --git a/styles/materialize.css b/styles/materialize.css
index 4805a6c..b0f177a 100644
--- a/styles/materialize.css
+++ b/styles/materialize.css
@@ -2067,7 +2067,7 @@ img.responsive-img, video.responsive-video {
.pagination li.active a {
color: #fff; }
.pagination li.active {
- background-color: #e0e0e0; }
+ background-color: #3e1944; }
.pagination li.disabled a {
color: #999; }
.pagination li i {
@@ -2163,7 +2163,7 @@ ul.staggered-list li {
footer.page-footer {
margin-top: 20px;
padding-top: 20px;
- background-color: #e0e0e0; }
+ background-color: #3e1944; }
footer.page-footer .footer-copyright {
overflow: hidden;
height: 50px;
@@ -5052,7 +5052,7 @@ span.badge {
nav {
color: #fff;
- background-color: #e0e0e0;
+ background-color: #3e1944;
width: 100%;
height: 56px;
line-height: 56px; }
@@ -5566,7 +5566,7 @@ small {
letter-spacing: 0.8px;
width: 15%; }
.tabs .tab a {
- color: #e0e0e0;
+ color: #3e1944;
display: block;
width: 100%;
height: 100%;
@@ -5576,12 +5576,12 @@ small {
-ms-transition: color 0.28s ease;
transition: color 0.28s ease; }
.tabs .tab a:hover {
- color: white; }
+ color: #82348f; }
.tabs .indicator {
position: absolute;
bottom: 0;
height: 2px;
- background-color: white;
+ background-color: #712e7c;
will-change: left, right; }
.tabs .tab {
@@ -6855,7 +6855,7 @@ select {
}
.side-nav .collapsible-body li.active, .side-nav.fixed .collapsible-body li.active {
- background-color: #e0e0e0; }
+ background-color: #3e1944; }
.side-nav .collapsible-body li.active a, .side-nav.fixed .collapsible-body li.active a {
color: #fff; }