Now let's go to Construct 2
We will need to add to our project
three global variables
Username (text)
Password (text)
UserID (number)
Now we will need to add to our Layout two "Text Box" plugins
let's call them Username and Password for easier reference.
Also let's add a "button" to use for the authentication event.
Let's name this button Login.
Now to access our php script we will use the "AJAX" plugin so add this to your project.
To make the user have to fill in something before clicking Login we will set the Login button to start as disabled (Do this using the attributes section, after clicking on "Login" to your left).
First thing to do is to use the text boxes to fill our global variables.
Add an event for each of the Text Boxes on text changed
ie
event Username On text Changed
action System Set Username to Username.Text
To accomplish a simple check on the user filling the two variables, we can add an event checking if any of them are equal to nothing.
So add an event in the form of
System Username = ""
or
System Password = ""
action
Set Login Disabled
Now the user is unable to click the Login button unless the two variables have something in there.
Now add an else event to enable the Login button (use right click to accomplish that)
event else
action Set Login Enabled
Now we need to add the AJAX request to get the login authenticated. We will use the Login button to accomplish that. So add now an event for the Lgin button.
event Login On clicked
action AJAX Request Tag "Login" URL "http://mydomain.com/login.php?fname='"&Username&"'&fpass='"&Password&"'"
Change the path according to where you uploaded the php script.
Now we need to get the login info back
So add an event in the form of
event
AJAX on "Login" Completed
action
System Set UserID to AJAX.Lastdata
Now we need to have a trigger running once for each chane to check if we got a valid reply and cleanup our layout
event
System UserID>0
System Trigger Once
action
Login Destroy
Password Destroy
Username Destroy
and we now have the UserID back and made sure the user has been authenticated against our database.
Your event sheet should look something like this