I’m having a problem with “cookies”. They are not saved and do their effect.
I’m following this tutorial : tutorial
.factory("auth", function($cookies,$cookieStore,$location,$state)
{
return{
login : function(username, password)
{
console.log(username);
console.log(password);
$cookies.username = username,
$cookies.password = password;
$location.path('/event/home');
},
logout : function()
{
$cookieStore.remove("username"),
$cookieStore.remove("password");
$location.path("/menu_registro/login");
},
checkStatus : function()
{
alert("Verificando login "+$cookies.username);
var rutasPrivadas = ["/event/home/","/event/misviews/","/event/view/","/menu_registro/login"];
if(this.in_array($location.path(),rutasPrivadas) && typeof($cookies.username) == "undefined")
{
$location.path("/menu_registro/login");
}
if(this.in_array("/menu_registro/login",rutasPrivadas) && typeof($cookies.username) != "undefined")
{
$location.path("/event/home/");
}
},
in_array : function(needle, haystack)
{
var key = '';
for(key in haystack)
{
if(haystack[key] == needle)
{
return true;
}
}
return false;
}
}
})
Try to close the application and reopen it to rescue the stored data but do not function.
.controller('LoginCtrl', function($scope,$ionicPopup, $state,$location,auth) {
$scope.data = {};
auth.checkStatus();
$scope.login = function()
{
auth.login($scope.data.username, $scope.data.password);
}
})