Questions or problems with cookies

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);
}
})

Oh my dear god, do not store passwords in cookies.

Also, I would suggest using localStorage and not cookies in general for storing data in an app.

3 Likes

oh if perfect, this application makes no sense, do not worry about that, I was looking for an alternative to generate a value that should be maintained. I in my other applications if occupied localStorage, I just wanted to try.