示例#1
0
    /// <summary>
    /// Metodo que se ejecuta al presionar enviar codigo (envia el codigo de activacion para registrarse)
    /// </summary>
    public void ClickSendConfirmation()
    {
        InputField username = GameObject.Find("/Canvas/SignUpPanel/TFUsername").GetComponent <InputField>();

        Debug.Log(username);
        InputField correo           = GameObject.Find("/Canvas/SignUpPanel/TFEmail").GetComponent <InputField>();
        InputField password         = GameObject.Find("/Canvas/SignUpPanel/TFPassword").GetComponent <InputField>();
        InputField confirmationPass = GameObject.Find("/Canvas/SignUpPanel/TFConfirmation").GetComponent <InputField>();

        Debug.Log("Comparando contraseñas");
        string hashPass             = HashManager.GeneratePasswordHash(password.text);
        string hashPassConfirmation = HashManager.GeneratePasswordHash(confirmationPass.text);

        if (username.text == null || correo.text == null || password.text == null || confirmationPass == null)
        {
            Debug.Log("Hay campos vacios");
            SSTools.ShowMessage(LocalizationManager.instance.GetLocalizedValue("message_empty_fields"),
                                SSTools.Position.bottom, SSTools.Time.oneSecond);
        }
        else
        {
            if (hashPassConfirmation.Equals(hashPass))
            {
                GameObject.Find("/Canvas/SignUpPanel").SetActive(false);
                GameObject VerificationSignUpPanel = BuscarObjetoInactivo("VerificationSignUpPanel");
                VerificationSignUpPanel.SetActive(true);

                string nombre = username.text;
                string email  = correo.text;

                Jugador.instance.Username        = nombre;
                Jugador.instance.Pass            = hashPass;
                Jugador.instance.Correo          = email;
                Jugador.instance.PartidasGanadas = 0;
                Jugador.instance.PartidasJugadas = 0;

                Debug.Log("Datos antes de clase mail = " + nombre + ", " + email);
                MailMessage mail     = new MailMessage(nombre, email);
                string      mailData = JsonConvert.SerializeObject(mail);
                Debug.Log("JSON = " + mailData);

                Debug.Log("Enviando codigo de activacion a " + correo.text);
                ConnectionManager.instance.socket.Emit("sendActivationCode", mailData);

                username.text         = "";
                correo.text           = "";
                password.text         = "";
                confirmationPass.text = "";
            }
            else
            {
                Debug.Log("La contraseña y la confirmacion de la contraseñ son diferentes");
                SSTools.ShowMessage(LocalizationManager.instance.GetLocalizedValue("passwords_diferent"),
                                    SSTools.Position.bottom, SSTools.Time.oneSecond);
            }
        }
    }
    /// <summary>
    /// Metodo llamado por servidor que envia el hash de la pass para comprobar que sea correcta
    /// </summary>
    private void OnLogin(Socket socket, Packet packet, params object[] args)
    {
        Debug.Log("Comprobando pass");
        InputField password     = GameObject.Find("TFPassword").GetComponent <InputField>();
        string     hashPass     = HashManager.GeneratePasswordHash(password.text);
        var        datosJugador = JSON.Parse(packet.ToString());
        string     passFound    = datosJugador[1].ToString().Trim(new Char[] { '"' });

        Debug.Log(passFound + " vs " + hashPass);
        if (passFound.Equals(hashPass))
        {
            ConnectionManager.instance.socket.Emit("loginSuccess");
        }
        else
        {
            Debug.Log("Contrasena incorrecta");
        }
    }