I am facing an issue with logout page.when logout option is clicked from a page, the login page has to be loaded and even when the user tries to click previous page arrow in browser, only the login page has to be displayed. I have tried using $window.location.reload();
andsessionStorage.clear();
which didnt give the solution.
Right now I have logout page which displays login page but when back page is clicked all the details of previous logged in user are available. Below is the code:
index.html:
<body ng-app="app">
<div class=" ">
<div ui-view></div>
</div>
</body>
login.html:
<form ng-submit=submit()>
<input type="text" name="username" placeholder="Username" ng-model="person.firstName" required />
<input type="password" name="pswd" placeholder="Password" ng-model="person.pswd" required />
<div class="submit">
<input type="submit" value="LOGIN">
</div>
</form>
page.html:
<ul>
<li><a ui-sref="logout">Logout</a></li>
</ul>
app.js:
var app = angular.module('app', ['ui.bootstrap', 'LocalStorageModule']);
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('page', {
url: '/page/:id',
templateUrl: 'page.html'
})
.state('login', {
url: '/login',
templateUrl: 'login.html',
controller: 'LoginCtrl'
})
.state('tab', {
url: '/tab/:id',
templateUrl: 'views/tab.html'
})
.state('logout', {
url: '/logout',
templateUrl: 'logout.html',
controller: 'LogoutCtrl'
});
});
app.controller('LogoutCtrl', function ($scope, $http, $location, $state) {
sessionStorage.clear();
$location.path('/login');
//this is loading login page, but if back arrow is clicked previous logged in details are present//
});
app.controller('LoginCtrl', function ($scope, $http, $location, $state) {
$scope.submit = function () {
$http.get("url" + $scope.Name + "&Password=" + $scope.pswd)
.success(function (data, status, headers, config) {
debugger
$scope.tableData = data;
console.log(data)
if (data == 'Exception') {
window.alert('You have entered wrong username or password');
}
else $state.go('tab', { id: data.Table[0].UserId });
})
}
});
In brief what I need is: After logging out, login page has to be displayed and if user tries to go to back page, then also login page alone has to be displayed.
Would be grateful if anyone can help.