diff --git a/index.html b/index.html index bbced88..f841a57 100644 --- a/index.html +++ b/index.html @@ -29,6 +29,7 @@ + diff --git a/js/app.js b/js/app.js index 88638e7..cd3b272 100644 --- a/js/app.js +++ b/js/app.js @@ -1,5 +1,3 @@ -'use strict'; - var app = angular.module('launchpad', ['ui.router', 'LocalStorageModule']); app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', function($stateProvider, $urlRouterProvider, localStorageServiceProvider){ @@ -131,7 +129,6 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider app.run(['$rootScope', '$location', 'Auth', function ($rootScope, $location, Auth) { $rootScope.$on('$routeChangeStart', function (event) { - if (!Auth.isLoggedIn()) { console.log('DENY'); event.preventDefault(); diff --git a/js/controllers/HomeController.js b/js/controllers/HomeController.js index 893054c..549b3b8 100644 --- a/js/controllers/HomeController.js +++ b/js/controllers/HomeController.js @@ -1,12 +1,19 @@ app.controller('HomeController', ['$scope', 'Auth', 'localStorageService', '$location', function ($scope, Auth, localStorageService, $location) { + var vm = this; - // $scope.$watch(Auth.isLoggedIn, function (value, oldValue) { - // if(value) { - // console.log("LOGGED IN!!!!"); - // } else if (!value && !oldValue) { - // console.log("NOT LOGGED IN!!!"); - // $location.path('/splash-page'); - // } - // }, true); + vm.signOut = function () { + localStorageService.remove('userAuth'); + $location.path('/splash-page'); + } + + function userAuth() { + return JSON.parse(localStorageService.get('userAuth')); + } + + $scope.$watch(Auth.isLoggedIn, function (value, oldValue) { + if (!value && !oldValue) { + $location.path('/splash-page'); + } + }, true); }]); diff --git a/js/controllers/signInController.js b/js/controllers/signInController.js index 34b7876..426463e 100644 --- a/js/controllers/signInController.js +++ b/js/controllers/signInController.js @@ -1,11 +1,18 @@ -app.controller('SignInController', ['$scope', 'Auth', '$location', function ($scope, Auth, $location) { +app.controller('SignInController', ['$scope', 'Auth', '$location', 'localStorageService', function ($scope, Auth, $location, localStorageService) { var vm = this; - vm.sign_in = function () { - // Ask to the server, do your job and THEN set the user - var user = { - email: "john@doe.com" + vm.signIn = function () { + + var userInfo = { + email: vm.userAuthEmail }; - Auth.setUser(user); //Update the state of the user in the app + + Auth.setUser(userInfo); + + var userAuthenticated = function() { + return localStorageService.set('userAuth', JSON.stringify(userInfo)); + }(); + $location.path('/launchpad-home'); }; + }]); diff --git a/js/services/auth.js b/js/services/auth.js index 5b679a9..2d18613 100644 --- a/js/services/auth.js +++ b/js/services/auth.js @@ -1,12 +1,12 @@ -app.factory('Auth', [function(){ +app.factory('Auth', ['localStorageService', function(localStorageService){ var user; - return{ - setUser : function(aUser){ - user = aUser; + setUser : function(currentUser){ + user = currentUser; }, isLoggedIn : function(){ - return(user)? user : false; + user = JSON.parse(localStorageService.get('userAuth')); + return (user) ? user : false; } }; }]); diff --git a/js/services/login.js b/js/services/login.js deleted file mode 100644 index 1492cbd..0000000 --- a/js/services/login.js +++ /dev/null @@ -1,3 +0,0 @@ -app.factory('LoginService', [function(){ - -}]); diff --git a/templates/partials/header.html b/templates/partials/header.html index fdf08c6..a22ad6b 100644 --- a/templates/partials/header.html +++ b/templates/partials/header.html @@ -19,13 +19,13 @@ diff --git a/templates/splash-page.html b/templates/splash-page.html index fe35e6f..3ffb573 100644 --- a/templates/splash-page.html +++ b/templates/splash-page.html @@ -9,6 +9,6 @@ - +