login redirect setup
This commit is contained in:
parent
0061d38152
commit
a6344ce60c
|
@ -13,3 +13,6 @@
|
|||
.notifications-container {
|
||||
width: 25%;
|
||||
}
|
||||
.login-container {
|
||||
top: 25vh;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<div ui-view class="splash-page" ng-controller="SignInController as vm"></div>
|
||||
<div class="search-bar" ui-view="header"></div>
|
||||
<div class="container main-content">
|
||||
<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>
|
||||
<!-- Angular Modules -->
|
||||
<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/app.js" charset="utf-8"></script>
|
||||
<!-- Services -->
|
||||
|
|
35
js/app.js
35
js/app.js
|
@ -1,12 +1,19 @@
|
|||
'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
|
||||
.state('splash-page', {
|
||||
url: '/splash-page',
|
||||
templateUrl: '/templates/splash-page.html',
|
||||
})
|
||||
.state('app',{
|
||||
url: '/',
|
||||
url: '/launchpad-',
|
||||
views: {
|
||||
'header': {
|
||||
templateUrl: '/templates/partials/header.html',
|
||||
|
@ -42,11 +49,6 @@ app.config(function($stateProvider, $urlRouterProvider){
|
|||
controller: 'SignInController',
|
||||
controllerAs: 'vm'
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
loginStatus: function(authService) {
|
||||
return authService.getUser();
|
||||
}
|
||||
}
|
||||
})
|
||||
.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) {
|
||||
var vm = this;
|
||||
app.controller('HomeController', ['$scope', 'Auth', 'localStorageService', '$location', function ($scope, Auth, localStorageService, $location) {
|
||||
|
||||
// $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;
|
||||
vm.userProfile = {};
|
||||
// vm.message = loginStatus;
|
||||
|
||||
vm.sign_in = function () {
|
||||
vm.userProfile.email = vm.userAuthEmail;
|
||||
vm.userProfile.password = vm.userAuthPassword;
|
||||
if (vm.userProfile.email === loginStatus.email && vm.userProfile.password === loginStatus.password) {
|
||||
console.log('yes!');
|
||||
$location.path('/home');
|
||||
} else {
|
||||
alert("wrong")
|
||||
}
|
||||
// Ask to the server, do your job and THEN set the user
|
||||
var user = {
|
||||
email: "john@doe.com"
|
||||
};
|
||||
Auth.setUser(user); //Update the state of the user in the app
|
||||
$location.path('/launchpad-home');
|
||||
};
|
||||
|
||||
}]);
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
app.factory('authService', function($q){
|
||||
app.factory('Auth', [function(){
|
||||
var user;
|
||||
|
||||
return{
|
||||
getUser: function(){
|
||||
var user = {
|
||||
email: 'jane@doe.com',
|
||||
password: 'password'
|
||||
}
|
||||
return $q.when(user);
|
||||
setUser : function(aUser){
|
||||
user = aUser;
|
||||
},
|
||||
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