Ejemplo n.º 1
0
    public async void Auth()
    {
        string name     = inputNameRegister.text;
        string password = inputPasswordRegister.text;

        client = new ChessClient.ChessClient(host, name);
        try
        {
            load.SetActive(true);
            string response = await client.Authentication(host + "Token/gettoken/", name, password);

            AuthRes authRes = JsonUtility.FromJson <AuthRes>(response);
            load.SetActive(false);
            message.text = authRes.Item2 + " успешно авторизован";
            PlayerPrefs.SetString("name", authRes.Item2);
            PlayerPrefs.SetString("token", "Bearer " + authRes.Item1);
            panel.SetActive(false);
            InitGame init = GameObject.Find("Main Camera").GetComponent <InitGame>();
            init.Init();
        }
        catch (WebException ex)
        {
            if (ex.Response == null)
            {
                message.text = "Инет вруби";
                load.SetActive(false);
                return;
            }
            message.text = "Неправильно введен логин или пароль";
            load.SetActive(false);
        }
    }
Ejemplo n.º 2
0
    public void LogOut()
    {
        PlayerPrefs.SetString("token", "");
        InitGame init = GameObject.Find("Main Camera").GetComponent <InitGame>();

        init.Init();
    }
Ejemplo n.º 3
0
    public async void Register()
    {
        string name     = inputNameRegister.text;
        string password = inputPasswordRegister.text;
        string email    = inputEmailRegister.text;

        client = new ChessClient.ChessClient(host, name);
        try
        {
            load.SetActive(true);
            if (!Regex.IsMatch(email, pattern))
            {
                message.text = "Неверный email";
                return;
            }
            await client.RegisterUser(host + "Users", name, password, email);

            load.SetActive(false);
            message.gameObject.SetActive(true);
            message.text = "Вы успешно зарегистрованы";
            panel.SetActive(false);
            InitGame init = GameObject.Find("Main Camera").GetComponent <InitGame>();
            init.Init("Вы успешно зарегистрованы");
        }
        catch (WebException ex)
        {
            if (ex.Response == null)
            {
                message.text = "Инет вруби";
                load.SetActive(false);
                return;
            }
            Stream       errorResponse  = ex.Response.GetResponseStream();
            StreamReader reader         = new StreamReader(errorResponse, Encoding.UTF8);
            string       responseString = reader.ReadToEnd();
            try
            {
                Messages mes = JsonUtility.FromJson <Messages>(responseString);
                load.SetActive(false);
                message.text = mes.Message;
            }
            catch
            {
                message.text = ex.Message;
                load.SetActive(false);
            }
        }
    }