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 -->
|
||||||
|
|
35
js/app.js
35
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.message = loginStatus;
|
|
||||||
|
|
||||||
vm.sign_in = function () {
|
vm.sign_in = function () {
|
||||||
vm.userProfile.email = vm.userAuthEmail;
|
// Ask to the server, do your job and THEN set the user
|
||||||
vm.userProfile.password = vm.userAuthPassword;
|
var user = {
|
||||||
if (vm.userProfile.email === loginStatus.email && vm.userProfile.password === loginStatus.password) {
|
email: "john@doe.com"
|
||||||
console.log('yes!');
|
};
|
||||||
$location.path('/home');
|
Auth.setUser(user); //Update the state of the user in the app
|
||||||
} else {
|
$location.path('/launchpad-home');
|
||||||
alert("wrong")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
app.factory('authService', function($q){
|
app.factory('Auth', [function(){
|
||||||
|
var user;
|
||||||
|
|
||||||
return{
|
return{
|
||||||
getUser: function(){
|
setUser : function(aUser){
|
||||||
var user = {
|
user = aUser;
|
||||||
email: 'jane@doe.com',
|
},
|
||||||
password: 'password'
|
isLoggedIn : function(){
|
||||||
}
|
return(user)? user : false;
|
||||||
return $q.when(user);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
}]);
|
||||||
|
|
|
@ -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