Validation with Phonegap and Webservice

Asked

Viewed 26 times

1

I am validating the login and password fields via Web Services, it returns me if the login is valid and generates a cookie number (done via sql), so far okay ,I can perform normal validation but I came up with the following doubt(I took a good look on the internet about cookie validation using jquery),how do I make my system validate this value that comes via WEBSERVICE and if the user has already logged in once and needs to close the application,.

So far my code is like this (I tried to use $cookie to save the value):

$.ajax({
                type: 'POST'
                //Caminho do WebService + / + nome do metodo
                , url: "http://localhost:11078/wsLogin.asmx/Login"
                , crossDomain: true
                , contentType: 'application/json; charset=utf-8'
                , dataType: 'json'
                //Abaixo adicione as variáveis caso haja alguma.
                , data: "{chave:'" + email + "', senha:'" + senha + "'}"
                , success: function (data, status) {
                    var txtHValue = $("#email");
                    var valoresID;
                    var arrCookie = [];
                    var arrLoginStatus = [];
                    var arrUsuarioID = [];

                    for (var i = 0; i < data.d.length; i++) {

                        var item = JSON.stringify(data.d[i]["ID"]);

                        arrCookie.push(data.d[i]["Cookie"]);
                        arrLoginStatus.push(data.d[i]["LoginStatus"]);
                        arrUsuarioID.push(data.d[i]["UsuarioID"]);
                    }


                    switch (parseInt(arrLoginStatus)) {
                        case 0:
                            alert("Usuario Não Encontrado");
                            break;
                        case 1:
                            alert("UsuarioAtivo");
                            break;
                        case 2:
                            txtHValue.focus();
                            $("#msgErro").text("Necessario preencher os campos corretamentes");
                            break;
                        case 5:
                            alert("SenhaValida");
                            break;
                        case 4:
                            alert("UsuarioEncontrado");
                            break;
                        case 7:
                            var list = $.cookie("example", "" + arrCookie);
                            alert(list);

                            break;
                        case 8:
                            alert("UsuarioDuplicado");
                            break;
                        case 9:
                            alert("ChaveLicencaNaoLocalizada");
                            break;
                        case 10:
                            alert("LicencaExpirada");
                            break;
                        case 11:
                            alert("ExcessaoGenerica");
                            break;
                        case 16:
                            alert("LogonExpirado");
                            break;

                    }

                }
                , error: function (xmlHttpRequest, status, err) {
                    //Caso ocorra algum erro:
                    $('.alert').html('Ocorreu um erro');
                }
            });

        });
    });
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.