Hello guys is it possible to use localstorage to deny access from a page when not authenticated when localstorage is null or undefined it will not allow a user to go to a page. Can anyone suggest or help me with this thing thanks
.controller(âLoginCtrlâ, function($scope, $state, $location, LoginService) {
$scope.form = {};
$scope.login = function(){
if((angular.isDefined($scope.form.username)
&& $scope.form.username !== "")
&& angular.isDefined($scope.form.password)
&& $scope.form.password !== "")
{
LoginService.login($scope.form).then(function(response){
if(Storage)
{
localStorage.setItem('loginDetails', JSON.stringify(response.data.Username));
$state.go('classattendance');
} else {
alert('String is not defined in this browser. please use other storage.');
}
}, function(error){
});
} else {
}
}
$scope.backbutton=function() {
$state.go(âhomeâ);
}
})
This is the controller that i want to have a permission because even though i didnt login i can access this page.
.controller(âClassCtrlâ, function ($state, $scope,$ionicPopup, $window, $ionicHistory) {
if (localStorage[âloginDetailsâ] == âundefinedâ)
{
//alert(âInvalid accessâ);
$ionicPopup.alert({
title: âAccess Deniedâ,
template: âCheck username and passwordâ
}).then(function(res) {
$window.localStorage.clear();
$state.go(âloginâ)
$window.location.reload();
});
};
$scope.logout=function() {
$window.localStorage.clear();
$ionicHistory.clearCache().then(function(){
$window.location.reload();
$state.go('login')
})
};
})