Re: [flexcoders] Using Auth.cfc from CF Wizard

2006-09-10 Thread Mike Nimer


Returning true/false to flex, like you are doing, tells Flash that the authentication was successful and to do what ever you want to do next at the client. However, with the code you have youhaven't told CF the user is authenticated. So if you made some other call that requires roles based security in CF it would fail. 

What you want to do is add a CFLOGIN tag to the method.

hth,
--nimer

something like this:

cffunction name="login" access="remote" returntype=" boolean"cfargument name="user" required="yes" /cfargument name="password" required="yes" /cfset var qRead=""cfquery name="qRead" datasource=" tiomkin" SELECT UserName, UserPassword FROM USERS WHERE UserName = cfqueryparam cfsqltype="CF_ SQL_VARCHAR" value="#arguments. user#" / AND UserPassword = cfqueryparam cfsqltype="CF_ SQL_VARCHAR" value="#arguments. password# " //cfquery

 cflogin
  cfloginuser name="#arguments.user#" password="#arguments.password#" roles="authenticatedUser"/
/cflogin cfif qRead.recordcount gt 0  cfreturn true cfelse  cfreturn false /cfif/cffunction
- Original Message From: envidobi [EMAIL PROTECTED]To: flexcoders@yahoogroups.comSent: Saturday, September 9, 2006 2:09:32 AMSubject: [flexcoders] Using Auth.cfc from CF Wizard

Hi all,Does anyone have a working example of auth.cfc (the file that getsgenerated when using the CF Wizard? I thought the code below would besufficient but its still not working. Any suggestions?CODE:AUTH.CFC:cffunction name="login" access="remote" returntype=" boolean"cfargument name="user" required="yes" /cfargument name="password" required="yes" /cfset var qRead=""cfquery name="qRead" datasource=" tiomkin"SELECT UserName, UserPasswordFROM USERSWHERE UserName = cfqueryparam cfsqltype="CF_ SQL_VARCHAR"value="#arguments. user#" /AND UserPassword = cfqueryparam cfsqltype="CF_ SQL_VARCHAR"value="#arguments. password# " //cfquerycfif qRead.recordcount gt 0cfreturn truecfelsecfreturn false/cfif/cffunctionLOGIN.MXML:?xml version="1.0"
 encoding="utf- 8"?mx:Form xmlns:mx="http://www.adobe. com/2006/ mxml" xmlns="*"width="100%" height="100% " creationComplete= "initApp( )"mx:Metadata[Event("forgotpassw ord")] [Event("loginSucces sful")] /mx:Metadatamx:Script![CDATA[import mx.events.Validatio nResultEvent;import mx.rpc.events. ResultEvent;import mx.rpc.events. FaultEvent;import mx.utils.ObjectUtil ;import mx.controls. Alert;private var lso:SharedObject;private function initApp():void{this.lso = SharedObject. getLocal( "auth");if( this.lso.data[ 'email'] != null ){this.user.text = this.lso.data[ 'email'];this.rememberLogin. selected = true;}if( this.lso.data[ 'password' ] != null ){this.password. text = this.lso.data[ 'password' ];this.rememberLogin. selected
 = true;}}private function isValid():Boolean{var pswdValidResult: ValidationResult Event =this.pswdValidate. validate( this.password. text);if (pswdValidResult. type==Validation ResultEvent. VALID) {return true; }else{return false; }} private function authenticateUser( ):void{if( isValid() ){authManager. login( this.user.text, this.password. text); }} private function errorMessage( msg:String) :void{//Alert.show( ObjectUtil.toString (event.message) );this.errorMsg. text = msg;this.errorMsg. height = 15;this.errorMsg. visible = true;} private function serverFault( event:FaultEvent ):void{errorMessage( event.message[ 'message' ]);} private function login_result( event:ResultEven t):void{// login successful, remember the user.if( Boolean(event. result) ){if( this.rememberLogin.
 selected ){this.lso.data[ 'user'] = this.user.text;this.lso.data[ 'password' ] = this.password. text; }else{this.lso.data[ 'user'] = null;this.lso.data[ 'password' ] = null; }this.dispatchEvent( new Event('loginSuccess ful') );}else{// login didn't work. show messageerrorMessage( "Login unsuccessful" ); }}]]/mx:Scriptmx:RemoteObject id="authManager" destination= "ColdFusion" source="Tiomkin. Tiomkin_Admin. components. cfgenerated. managers. Auth" showBusyCursor= "true"mx:method name="login" result="login_ result(event) "fault="serverFault( event)" //mx:RemoteObject mx:StringValidator id="pswdValidate" source="{this. password} " property="text" required="true" /mx:Text id="errorMsg" visible="true" color="red" width="100%" height="0" /mx:FormItem width="100%"
 label="UserName" required="true" mx:TextInput id="user" width="175"/ /mx:FormItemmx:FormItem width=

[flexcoders] Using Auth.cfc from CF Wizard

2006-09-09 Thread envidobi
Hi all,
Does anyone have a working example of auth.cfc (the file that gets
generated when using the CF Wizard? I thought the code below would be
sufficient but its still not working. Any suggestions?

CODE:
 
AUTH.CFC:
cffunction name=login access=remote returntype=boolean
cfargument name=user required=yes /
cfargument name=password required=yes /

cfset var qRead=

cfquery name=qRead datasource=tiomkin
SELECT UserName, UserPassword
FROM USERS
WHERE UserName = cfqueryparam 
cfsqltype=CF_SQL_VARCHAR
value=#arguments.user# /
AND UserPassword = cfqueryparam 
cfsqltype=CF_SQL_VARCHAR
value=#arguments.password# /
/cfquery

cfif qRead.recordcount gt 0
cfreturn true
cfelse
cfreturn false
/cfif
/cffunction

LOGIN.MXML:

?xml version=1.0 encoding=utf-8?

mx:Form xmlns:mx=http://www.adobe.com/2006/mxml;  xmlns=*
width=100% height=100% creationComplete=initApp()
   
mx:Metadata
   [Event(forgotpassword)] 
   [Event(loginSuccessful)] 
/mx:Metadata

mx:Script
![CDATA[
import mx.events.ValidationResultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.utils.ObjectUtil;
import mx.controls.Alert;


private var lso:SharedObject;

private function initApp():void
{
this.lso = SharedObject.getLocal(auth);

if( this.lso.data['email'] != null )
{
this.user.text = this.lso.data['email'];
this.rememberLogin.selected = true;
}
if( this.lso.data['password'] != null )
{
this.password.text = this.lso.data['password'];
this.rememberLogin.selected = true;
}
}

private function isValid():Boolean
{
var pswdValidResult:ValidationResultEvent =
this.pswdValidate.validate(this.password.text);

if (pswdValidResult.type==ValidationResultEvent.VALID) 
{
return true;
}
else
{
return false;   
}

}


private function authenticateUser():void
{
if( isValid() )
{
authManager.login( this.user.text, this.password.text
);   
}
} 

private function errorMessage(msg:String):void
{
//Alert.show( ObjectUtil.toString(event.message) );
this.errorMsg.text = msg;
this.errorMsg.height = 15;
this.errorMsg.visible = true;
}
   
private function serverFault(event:FaultEvent):void
{
errorMessage(event.message['message']);
}   

  

private function login_result(event:ResultEvent):void
{
// login successful, remember the user.
if( Boolean(event.result) )
{
if( this.rememberLogin.selected )
{
this.lso.data['user'] = this.user.text;
this.lso.data['password'] = this.password.text; 
}
else
{
this.lso.data['user'] = null;
this.lso.data['password'] = null;   
}

this.dispatchEvent( new 
Event('loginSuccessful') );
}
else
{
// login didn't work. show message
errorMessage(Login unsuccessful); 
}
}
]]
/mx:Script

mx:RemoteObject 
id=authManager 
destination=ColdFusion 
   
source=Tiomkin.Tiomkin_Admin.components.cfgenerated.managers.Auth 
showBusyCursor=true
   mx:method name=login result=login_result(event)
fault=serverFault(event) /
/mx:RemoteObject

mx:StringValidator 
id=pswdValidate 
source={this.password}