login redirect setup
This commit is contained in:
parent
0061d38152
commit
a6344ce60c
|
@ -13,3 +13,6 @@
|
||||||
.notifications-container {
|
.notifications-container {
|
||||||
width: 25%;
|
width: 25%;
|
||||||
}
|
}
|
||||||
|
.login-container {
|
||||||
|
top: 25vh;
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div ui-view class="splash-page" ng-controller="SignInController as vm"></div>
|
||||||
<div class="search-bar" ui-view="header"></div>
|
<div class="search-bar" ui-view="header"></div>
|
||||||
<div class="container main-content">
|
<div class="container main-content">
|
||||||
<div class="menu-container" ui-view="menu"></div>
|
<div class="menu-container" ui-view="menu"></div>
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
<script src="/js/lib/lodash/lodash.underscore.min.js" charset="utf-8"></script>
|
<script src="/js/lib/lodash/lodash.underscore.min.js" charset="utf-8"></script>
|
||||||
<!-- Angular Modules -->
|
<!-- Angular Modules -->
|
||||||
<script src="/js/lib/angular/angular.min.js" charset="utf-8"></script>
|
<script src="/js/lib/angular/angular.min.js" charset="utf-8"></script>
|
||||||
|
<script src="/js/lib/angular/angular-local-storage.js" charset="utf-8"></script>
|
||||||
<script src="/js/lib/angular/angular-ui-router.min.js" charset="utf-8"></script>
|
<script src="/js/lib/angular/angular-ui-router.min.js" charset="utf-8"></script>
|
||||||
<script src="/js/app.js" charset="utf-8"></script>
|
<script src="/js/app.js" charset="utf-8"></script>
|
||||||
<!-- Services -->
|
<!-- Services -->
|
||||||
|
|
37
js/app.js
37
js/app.js
|
@ -1,12 +1,19 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var app = angular.module('launchpad', ['ui.router']);
|
var app = angular.module('launchpad', ['ui.router', 'LocalStorageModule']);
|
||||||
|
|
||||||
|
app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', function($stateProvider, $urlRouterProvider, localStorageServiceProvider){
|
||||||
|
localStorageServiceProvider.setPrefix('launchpad').setStorageType('sessionStorage');
|
||||||
|
|
||||||
|
$urlRouterProvider.otherwise('/splash-page');
|
||||||
|
|
||||||
app.config(function($stateProvider, $urlRouterProvider){
|
|
||||||
$urlRouterProvider.otherwise('/sign-in');
|
|
||||||
$stateProvider
|
$stateProvider
|
||||||
|
.state('splash-page', {
|
||||||
|
url: '/splash-page',
|
||||||
|
templateUrl: '/templates/splash-page.html',
|
||||||
|
})
|
||||||
.state('app',{
|
.state('app',{
|
||||||
url: '/',
|
url: '/launchpad-',
|
||||||
views: {
|
views: {
|
||||||
'header': {
|
'header': {
|
||||||
templateUrl: '/templates/partials/header.html',
|
templateUrl: '/templates/partials/header.html',
|
||||||
|
@ -42,11 +49,6 @@ app.config(function($stateProvider, $urlRouterProvider){
|
||||||
controller: 'SignInController',
|
controller: 'SignInController',
|
||||||
controllerAs: 'vm'
|
controllerAs: 'vm'
|
||||||
}
|
}
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
loginStatus: function(authService) {
|
|
||||||
return authService.getUser();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('app.bolt', {
|
.state('app.bolt', {
|
||||||
|
@ -125,4 +127,19 @@ app.config(function($stateProvider, $urlRouterProvider){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}]);
|
||||||
|
|
||||||
|
app.run(['$rootScope', '$location', 'Auth', function ($rootScope, $location, Auth) {
|
||||||
|
$rootScope.$on('$routeChangeStart', function (event) {
|
||||||
|
|
||||||
|
if (!Auth.isLoggedIn()) {
|
||||||
|
console.log('DENY');
|
||||||
|
event.preventDefault();
|
||||||
|
$location.path('/login');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('ALLOW');
|
||||||
|
$location.path('/home');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}]);
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
app.controller('HomeController', ['$scope', function ($scope) {
|
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);
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
app.controller('SignInController', ['$scope', 'loginStatus', '$location', function ($scope, loginStatus, $location) {
|
app.controller('SignInController', ['$scope', 'Auth', '$location', function ($scope, Auth, $location) {
|
||||||
var vm = this;
|
var vm = this;
|
||||||
vm.userProfile = {};
|
vm.sign_in = function () {
|
||||||
// vm.message = loginStatus;
|
// Ask to the server, do your job and THEN set the user
|
||||||
|
var user = {
|
||||||
vm.sign_in = function() {
|
email: "john@doe.com"
|
||||||
vm.userProfile.email = vm.userAuthEmail;
|
};
|
||||||
vm.userProfile.password = vm.userAuthPassword;
|
Auth.setUser(user); //Update the state of the user in the app
|
||||||
if (vm.userProfile.email === loginStatus.email && vm.userProfile.password === loginStatus.password) {
|
$location.path('/launchpad-home');
|
||||||
console.log('yes!');
|
|
||||||
$location.path('/home');
|
|
||||||
} else {
|
|
||||||
alert("wrong")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
app.factory('authService', function($q){
|
app.factory('Auth', [function(){
|
||||||
return {
|
var user;
|
||||||
getUser: function(){
|
|
||||||
var user = {
|
return{
|
||||||
email: 'jane@doe.com',
|
setUser : function(aUser){
|
||||||
password: 'password'
|
user = aUser;
|
||||||
}
|
},
|
||||||
return $q.when(user);
|
isLoggedIn : function(){
|
||||||
|
return(user)? user : false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
}]);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
app.factory('LoginService', [function(){
|
||||||
|
|
||||||
|
}]);
|
|
@ -0,0 +1,14 @@
|
||||||
|
<section class="col-md-offset-4 col-md-4 login-container">
|
||||||
|
<form>
|
||||||
|
<h4 class="text-center">Sign in</h4>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="exampleInputEmail1">Email address</label>
|
||||||
|
<input type="email" class="form-control" placeholder="Email" ng-model="vm.userAuthEmail">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="exampleInputPassword1">Password</label>
|
||||||
|
<input type="password" class="form-control" placeholder="Password" ng-model="vm.userAuthPassword">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-default" ng-click="vm.sign_in()">Submit</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
Loading…
Reference in New Issue