Advertisement
Guest User

Untitled

a guest
Apr 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.UI;
  5. using System;
  6. using System.IO;
  7. using UnityEngine.Networking;
  8.  
  9.  
  10. public class LoginDB : MonoBehaviour {
  11.  
  12.     public static string user = "";
  13.     private string password = "", id = "";
  14.     public InputField loginInput;
  15.     public InputField passInput;
  16.     public Text text;
  17.  
  18.    
  19.  
  20.     public void toReg()
  21.     {
  22.         Application.LoadLevel("Regist");
  23.     }
  24.  
  25.  
  26.  
  27.     [Serializable]
  28.  
  29.     public class Data
  30.     {
  31.         public string id;
  32.         public string name;
  33.         public string _class;
  34.     }
  35.     public void Login()
  36.     {
  37.         //message = "";
  38.         user = loginInput.text.ToString ();
  39.         password = passInput.text.ToString ();
  40.  
  41.         if (user == "" || password == "")
  42.             text.text = "Please enter all the fields \n";
  43.         else
  44.         {
  45.             WWWForm form = new WWWForm();
  46.             form.AddField("email", user);
  47.             form.AddField("password", password);
  48.             WWW www = new WWW("http://uo.cx.ua/api/auth/login", form);
  49.             StartCoroutine(login(www));
  50.  
  51.         }
  52.  
  53.         }
  54.     IEnumerator login(WWW www)
  55.     {
  56.         yield return www;
  57.         if (www.error != null)
  58.         {
  59.             Debug.Log ("error " + www.error);
  60.            
  61.             }
  62.  
  63.         else
  64.         {
  65.             string json = www.text;
  66.             Data data;
  67.             data = JsonUtility.FromJson<Data> (json);
  68.             Debug.Log (data.id);
  69.  
  70.         }
  71.     }
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement