You now have a login form, which does nothing other than move and close.
Next, you'll process the log-on. Validating the log-on requires a new
method in the ColdFusion component. Copy the code for the Authenticate
method to employees.cfc.
<CFFUNCTION NAME="Authenticate"
HINT="Employee authentication"
ACCESS="remote"
RETURNTYPE="boolean">
<CFARGUMENT NAME="LoginName"
TYPE="string"
REQUIRED="true">
<CFARGUMENT NAME="LoginPassword"
TYPE="string"
REQUIRED="true">
<CFSET var result=FALSE>
<CFIF ARGUMENTS.LoginPassword IS "password">
<CFSET result=TRUE>
</CFIF>
<CFRETURN result>
</CFFUNCTION>
The Authenticate method takes a login name and password,
and returns true if the log-on authenticates and false
if not. Although this particular method is stubbed for simplicity's
sake, instead of doing a real lookup, it looks at the password and returns
true if the password is password. In your
own apps, you would obviously replace the processing in this method
with your own database or LDAP lookups, or some other processing.
You need to make Flash aware of this new method, so use the following steps:
Authenticate()
method.With that done, you can now wire up the login screen:
Select the Parameters tab. In the WSDLURL field, select
the URL to the employees.cfc web service. If you're using the defaults,
this will be http://localhost:8500/cfflash/employees.cfc?wsdl.
In the operation field select Authenticate (Figure
20).
Figure 20. Define web service properties manually in the Components Inspector panel.
Authenticate web service requires that you pass
two parameters to it: the login name and password. Therefore, you
must bind the two form fields in the login form to this web service.
Select the Bindings tab, click the Plus (+) button to display the
Add Binding dialog box, select LoginName, and click
OK to add it as an available binding.Locate the login form, select the loginName
TextInput, click the text field on the right (Figure
22), and click OK to bind the loginName field to the
LoginName web service argument.
Figure 21. When using the Bound To dialog, be sure to select the correct components.
loginPassword
TextInput field to the LoginPassword web service argument.Now, when the authService web service executes, it will
pass values from the two form fields to ColdFusion for processing. The
only problem is that, as is, the web service will never execute on its
own. You need to add code to the form's Login button so that it will
execute the web service call when a user presses it. You can do it manually
or use a simple wizard:
Expand the tree to locate root > application > login > authService (see Figure 22).
Figure 22. The Trigger Data Source behavior allows for the interactive selection of web services.
When a user runs the application now, clicking the Login button causes the login form to pop up, which asks the user for a name and password and authenticates him. But you've yet to tell Flash what to do when the Authenticate method returns true or false. Use the following steps to add this code:
Open the Actions panel and paste the following code:
// Process authentication results
on (result) {
if (results) {
// If returned true
// Make employee data editable
_root.application.data.empDataGrid.editable=true;
// Close login popup
_root.application.login.loginInstance.deletePopUp();
}
else {
// Returned false, show error message
mx.controls.Alert.show("Login Failed!", "Login");
}
}
Save the application and test it. You should now be able to login using any login name and a password of password. Upon successful log-on, you can edit the employee DataGrid (Figure 23).
Figure 23. The Flash DataGrid supports inline editing.