Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using SimpleJSON;
- using System.IO;
- public class Loginform : MonoBehaviour
- {
- public GameObject inputUsername;
- public GameObject inputPassword;
- public Text displayText;
- private const string URL = "http://cameri.kivi-tv.net/api/login?username=";
- public Animator anim;
- string writePath;
- public List<string> writeList = new List<string> ();
- void Start () {
- writePath = Application.dataPath + "/TestFile.txt";
- AppendFile(writePath);
- anim = GetComponent<Animator>();
- }
- public void Onclick () {
- string username = inputUsername.GetComponent<InputField>().text;
- string password = inputPassword.GetComponent<InputField>().text;
- WWW www = new WWW(URL + username + "&password=" + password);
- StartCoroutine (request (www));
- }
- public void Button () {
- Onclick();
- }
- IEnumerator request (WWW www)
- {
- yield return www;
- JSONObject jsonstring = (JSONObject)JSON.Parse(www.data);
- string session = jsonstring["session_id"];
- string message = jsonstring["message"];
- displayText.text = message;
- if (displayText.text == "Successful login")
- {
- anim.Play("Main anim");
- writeList.Add(session);
- }
- }
- void Update()
- {
- }
- void AppendFile(string filePath)
- {
- StreamWriter sWriter;
- if(!File.Exists(filePath))
- {
- sWriter = File.CreateText(Application.dataPath + "/TestFile.txt");
- }
- else
- {
- sWriter = new StreamWriter(filePath, append: true);
- }
- for (int k = 0; k < writeList.Count; k++)
- {
- sWriter.WriteLine(writeList[k]);
- }
- sWriter.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement