@Pajimola wrote:
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') }) }; })
Posts: 1
Participants: 1