﻿#pragma strict

var username : String;
var password : String;
var new_username : String;
var new_password : String;

var status: String;

// If you use your own server (not localhost) then replace localhost with your domain name
// Change URL according to your need
var URL : String = "http://localhost/unity_login_system/";

function OnGUI () {
	
	GUI.Label(Rect(10, 10, 200, 20), "Username:");
	// Make a text field that modifies username.
	username = GUI.TextField (Rect (10, 30, 200, 20), username, 15);
	
	GUI.Label(Rect(10, 60, 200, 20), "Password:");
	// Make a text field that modifies password.
	password = GUI.PasswordField (Rect (10, 80, 200, 20), password, "*"[0], 15);
	
	// Login Button
	if(GUI.Button(Rect (10, 120, 100, 20), "Login")) {
		Login();
	}
	
	GUI.Label(Rect(10, 170, 200, 20), "Signup First:");
	GUI.Label(Rect(10, 190, 200, 20), "Username:");
	// Make a text field that modifies username.
	new_username = GUI.TextField (Rect (10, 210, 200, 20), new_username, 15);
	
	GUI.Label(Rect(10, 240, 200, 20), "Password:");
	// Make a text field that modifies password.
	new_password = GUI.PasswordField (Rect (10, 260, 200, 20), new_password, "*"[0], 15);
	
	// Login Button
	if(GUI.Button(Rect (10, 300, 100, 20), "Login")) {
		Signup ();
	}
	
	
	GUI.Label(Rect(Screen.width-205, 10, 200, 20), status);
}

function Login () {

	// URL + script name and add query string as Get mothod
	var www : WWW = new WWW (URL+"login.php?username="+username+"&password="+password);
	yield www;
	try{
		status = www.text;
		// Load login successful scene after login
	}catch(err){
		// If you are using your own server then use bellow exception
		status = "Check your internet connection";
	}
}

function Signup () {

	// URL + script name and add query string as Get mothod
	var www : WWW = new WWW (URL+"signup.php?username="+new_username+"&password="+new_password);
	yield www;
	try{
		status = www.text;
	}catch(err){
		// If you are using your own server then use bellow exception
		status = "Check your internet connection";
	}
}