Example #1
0
    public void Login(string scene)
    {
        UnityEngine.UI.InputField rut  = GameObject.Find("Usuario_input").GetComponent <UnityEngine.UI.InputField> ();
        UnityEngine.UI.InputField pass = GameObject.Find("ContraseƱa_input").GetComponent <UnityEngine.UI.InputField> ();

        string passDB    = "";
        string colegioDB = "";
        string cursoDB   = "";

        DatabaseReference referenciaFirebase = FirebaseDatabase.DefaultInstance.RootReference;

        FirebaseDatabase.DefaultInstance
        .GetReference("Usuarios")
        .GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot = task.Result;
                DataSnapshot user     = snapshot.Child(rut.text);
                if (!user.HasChildren)
                {
                    Mensaje.SetActive(true);
                }
                IDictionary dictUser = (IDictionary)user.Value;
                passDB    = dictUser["Contrasena"].ToString();
                colegioDB = dictUser["Colegio"].ToString();
                cursoDB   = dictUser["Curso"].ToString();

                if (pass.text.Equals(passDB))
                {
                    sesion.setSesion(System.DateTime.Now.ToString());
                    sesion.setUsuario(rut.text);
                    sesion.setColegio(colegioDB);
                    sesion.setCurso(cursoDB);

                    LoadingSiguiente(scene);
                }
                else
                {
                    Mensaje.SetActive(true);
                }
            }
        });
    }