From f05ccab3073246cc25a287c16eace95374d62a4e Mon Sep 17 00:00:00 2001 From: Andrew Buss Date: Mon, 18 May 2015 01:57:30 -0700 Subject: [PATCH] half-implemented login redirection --- config.js | 55 +++++++++++++++++++++-------- home.html | 11 ++---- materialize/sass/components/_variables.scss | 2 +- scripts/LoginController.js | 3 +- scripts/LogoutController.js | 14 +++++--- scripts/RootController.js | 6 ++-- scripts/UserService.js | 25 ++++++++----- styles/materialize.css | 14 ++++---- 8 files changed, 82 insertions(+), 48 deletions(-) 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 @@ -