[flexcoders] Re: storing login data from a cfquery for use throught flex app
wow this seems to work but never used singleton before. jeremy, care to explain how staff works in detail? or maybe stinasius may understand what is being done here. if so please share with a flex newbie.
[flexcoders] Re: storing login data from a cfquery for use throught flex app
sorry john, i have never used singletons before either. i have a static class and would like to know how to get it store the result of the query. otherwise i have not made any progress at all. am thinking if someone can work out for me a solid flex/cf/access login(authentication) system and well commented that i can use in my projects i am prepared to pay for it.
[flexcoders] Re: storing login data from a cfquery for use throught flex app
hi, may be i will try to put the question this way, in my cfc i have to return a Boolean value true or false because in my result handler on the login page i test to see if the result returned is true or false then make a decision to accept login or not. this is my result handler on the login page private function login_result(event:ResultEvent):void { // login successful, remember the user. if( event.result == true || event.result == TRUE || event.result == 1 || event.result == 1 ) { this.dispatchEvent( new Event('loginSuccessful') ); } else { // login didn't work. show message errorMessage(Login unsuccessful); } } but if i set the cfc to return a query result in this case checkAuthentication nothing happens. so is there a way of returning a query result and have the result handler check against the returned result in order to make a decision to authenticate or not?
RE: [flexcoders] Re: storing login data from a cfquery for use throught flex app
What I do is to use xml. I wrap all of my return server data in a status node, like this successful login: callstatus status=success statusDescription=User authenticated userInfo first=John last=Smith email...@gmail.com ./ /callstatus If the login fails, I return: callstatus status=fail statusDescription=credentials are not valid / In the handler I do: var xmlResult:XML = XML(event.result); //musy have resultFormat=e4x if (xmlresu...@status == success) { UserInfo.first = xmlresult.userin...@first; . } else { Alert.show(Login Failed: +xmlresu...@statusdescription ) } Tracy Spratt, Lariat Services, development services available _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of stinasius Sent: Friday, March 13, 2009 2:17 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: storing login data from a cfquery for use throught flex app hi, may be i will try to put the question this way, in my cfc i have to return a Boolean value true or false because in my result handler on the login page i test to see if the result returned is true or false then make a decision to accept login or not. this is my result handler on the login page private function login_result(event:ResultEvent):void { // login successful, remember the user. if( event.result == true || event.result == TRUE || event.result == 1 || event.result == 1 ) { this.dispatchEvent( new Event('loginSuccessful') ); } else { // login didn't work. show message errorMessage(Login unsuccessful); } } but if i set the cfc to return a query result in this case checkAuthentication nothing happens. so is there a way of returning a query result and have the result handler check against the returned result in order to make a decision to authenticate or not?
[flexcoders] Re: storing login data from a cfquery for use throught flex app
i have also had the same problem with login authentication in flex and coldfusion. this is not well addressed especially for beginners like me.i wish someone could come up with a tutorial that does login authentication through database and cfc remote object calls and then shows how to store login info for use through out the application. so far i have to say i am where stinasius is and failed to progress.
[flexcoders] Re: storing login data from a cfquery for use throught flex app
give this a try , the problem may be the return type, struct for successful and boolean for unsuccessful cffunction name=loginUser access=remote returntype=struct //do your stuff cfset returnValue = structnew() cfset returnValue.success = false cfset returnValue.lastResult = cfif checkAuthentication.recordCount EQ 1 cfset returnValue.success = true cfset returnValue.lastResult = checkAuthentication /cfif cfreturn returnValue/ /cffunction private function login_result(event:ResultEvent):void { if(Number(event.result.success) == 1 || String(event.result.success).toLowerCase() == true) { this.dispatchEvent( new Event('loginSuccessful') ); var store:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(event.result.lastResult)) } else errorMessage(Login unsuccessful); }
[flexcoders] Re: storing login data from a cfquery for use throught flex app
when i try that i get the following error ReferenceError: Error #1069: Property message not found on mx.messaging.messages.ErrorMessage and there is no default value. at components::Login/serverFault() at components::Login/___Operation1_fault() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent() at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler() at mx.rpc::Responder/fault() at mx.rpc::AsyncRequest/fault() at NetConnectionMessageResponder/statusHandler() at mx.messaging::MessageResponder/status()
[flexcoders] Re: storing login data from a cfquery for use throught flex app
If I were you I would go through the tutorials at... http://flexcf.com/tutorials http://blogs.adobe.com/flexdoc/2007/02/hello_world_application_for_fl_1.html http://www.adobe.com/devnet/coldfusion/articles/adobetv_cfpwrdflex.html http://www.brucephillips.name/blog/index.cfm/2007/3/16/Developing-A-Login-System-For-A-Flex-Application-With-A-ColdFusion-and-Database-Backend-Part-1 http://www.cflex.net/showfiledetails.cfm?ChannelID=1Object=FileobjectID=618 http://coldfusion.sys-con.com/node/256076 and this FlexCoders thread... http://tech.groups.yahoo.com/group/flexcoders/message/132528 Especially Bruce Phillips six part article titled Developing A Login System For A Flex Application With A ColdFusion and Database Backend. --- In flexcoders@yahoogroups.com, johndoematrix johndoemat...@... wrote: i have also had the same problem with login authentication in flex and coldfusion. this is not well addressed especially for beginners like me.i wish someone could come up with a tutorial that does login authentication through database and cfc remote object calls and then shows how to store login info for use through out the application. so far i have to say i am where stinasius is and failed to progress.
[flexcoders] Re: storing login data from a cfquery for use throught flex app
Valdhor, i think what stinasius is asking abt has nothing to do with the links you provided. bruce phillip's example is about login in flex with coldfusion backend. the problem is not the login, the problem is how to store the result of the login query in the static class for use throughout the flex example. say the user wants to edit his info like username, email, date of birth etc he/she has to first login and then edit the info returned by the cfc query.
[flexcoders] Re: storing login data from a cfquery for use throught flex app
Which is just an extension of the examples at the links I provided. By using Bruce Phillips example; The CRUD example at http://flexcf.com/tutorials; and the Ben Forta Adobe TV presentation at http://www.adobe.com/devnet/coldfusion/articles/adobetv_cfpwrdflex.html, anyone should have a good idea at how to do what stinasius wants. All it requires is creating a value object in Flex with username and password; Sending that object to coldfusion and receiving a userinfo value object back containing authentication info and, if authenticated, all the users details. With my extremely limited knowledge of ColdFusion I could probably have something that works in about four hours. If someone wants to pay me for my time I would be happy to put together an example ;-} --- In flexcoders@yahoogroups.com, johndoematrix johndoemat...@... wrote: Valdhor, i think what stinasius is asking abt has nothing to do with the links you provided. bruce phillip's example is about login in flex with coldfusion backend. the problem is not the login, the problem is how to store the result of the login query in the static class for use throughout the flex example. say the user wants to edit his info like username, email, date of birth etc he/she has to first login and then edit the info returned by the cfc query.
[flexcoders] Re: storing login data from a cfquery for use throught flex app
Here is a good example that you can use. Here is a link to the source code. Right click to view. http://view.myhomesmart.com/singleton/singleton.html Here is the cfc code. cffunction name=Do_Login access=remote output=false returntype=struct cfargument name=username type=string required=true/ cfargument name=userpass type=string required=true/ cfset var rtnStc = structNew() cfquery name=GetUser datasource=#dsn# SELECT tbl_smartPanel_User.fld_user_UUID, tbl_smartPanel_User.fld_user_Username, concat(tbl_smartPanel_User_Detail.fld_userDetails_FirstName, ' ' , tbl_smartPanel_User_Detail.fld_userDetails_LastName) AS fullName FROM tbl_smartPanel_User Inner Join tbl_smartPanel_User_Detail ON tbl_smartPanel_User.fld_user_UUID = tbl_smartPanel_User_Detail.fld_user_UUID WHERE tbl_smartPanel_User.fld_user_Username = cfqueryparam cfsqltype=cf_sql_varchar value=#arguments.username#/ AND tbl_smartPanel_User.fld_user_Password = cfqueryparam cfsqltype=cf_sql_varchar value=#arguments.userpass#/ /cfquery cfif GetUser.recordCount gt 0 cfset rtnStc.username = GetUser.fld_user_Username cfset rtnStc.fullname = GetUser.fullName cfset rtnStc.userid = GetUser.fld_user_UUID cfelse cfset rtnStc.msg = FAILED /cfif cfreturn rtnStc / /cffunction
RE: [flexcoders] Re: storing login data from a cfquery for use throught flex app
Use the = operator. We need more detail if you want a more detailed answer. Post what you have so far. Tracy Spratt, Lariat Services, development services available _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of stinasius Sent: Thursday, March 12, 2009 1:34 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: storing login data from a cfquery for use throught flex app hi how do i assign the properties of UserInfo in the result handler?
[flexcoders] Re: storing login data from a cfquery for use throught flex app
in my cfc the return type is boolean and is set to return true if there is a match. when i set the return type to query to return the query result(checkAuthentication), nothing happens. cffunction name=loginUser access=remote returntype=boolean cfargument name=username type=string required=true/ cfargument name=password type=string required=true/ cfquery name=checkAuthentication datasource=authentication SELECT * FROM profile where username = cfqueryparam cfsqltype=cf_sql_varchar value=#arguments.username# and Password = cfqueryparam cfsqltype=cf_sql_varchar value=#arguments.password# /cfquery cfif checkAuthentication.recordCount EQ 1 cfreturn true/ !---cfreturn checkAuthentication--- cfelse cfreturn false/ /cfif /cffunction
RE: [flexcoders] Re: storing login data from a cfquery for use throught flex app
I don't know CF well enough to help you with that, but that must be your first goal, to get a successful login to return the user info to your Flex result handler. Tracy Spratt, Lariat Services, development services available _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of stinasius Sent: Thursday, March 12, 2009 4:05 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: storing login data from a cfquery for use throught flex app in my cfc the return type is boolean and is set to return true if there is a match. when i set the return type to query to return the query result(checkAuthentication), nothing happens. cffunction name=loginUser access=remote returntype=boolean cfargument name=username type=string required=true/ cfargument name=password type=string required=true/ cfquery name=checkAuthentication datasource=authentication SELECT * FROM profile where username = cfqueryparam cfsqltype=cf_sql_varchar value=#arguments.username# and Password = cfqueryparam cfsqltype=cf_sql_varchar value=#arguments.password# /cfquery cfif checkAuthentication.recordCount EQ 1 cfreturn true/ !---cfreturn checkAuthentication--- cfelse cfreturn false/ /cfif /cffunction
[flexcoders] Re: storing login data from a cfquery for use throught flex app
Don't you already know the username and password? You had to send them to CF for authentication. If the response is yes, populate your userinfo object; Otherwise, don't ;-} --- In flexcoders@yahoogroups.com, stinasius stinas...@... wrote: in my cfc the return type is boolean and is set to return true if there is a match. when i set the return type to query to return the query result(checkAuthentication), nothing happens. cffunction name=loginUser access=remote returntype=boolean cfargument name=username type=string required=true/ cfargument name=password type=string required=true/ cfquery name=checkAuthentication datasource=authentication SELECT * FROM profile where username = cfqueryparam cfsqltype=cf_sql_varchar value=#arguments.username# and Password = cfqueryparam cfsqltype=cf_sql_varchar value=#arguments.password# /cfquery cfif checkAuthentication.recordCount EQ 1 cfreturn true/ !---cfreturn checkAuthentication--- cfelse cfreturn false/ /cfif /cffunction
[flexcoders] Re: storing login data from a cfquery for use throught flex app
hi how do i assign the properties of UserInfo in the result handler?
[flexcoders] Re: storing login data from a cfquery for use throught flex app
This can be done fairly simply using an oop approach. With out going into to much detail. You can create a single instance of a storage class that gets/sets the data that you are looking for. Here is a really basic example: package com.login{ // do some imports public class myLogin{ private var username:string = new String(); private var email:string = new String(); public function myLogin(){ // do some constructor stuff here } public function getUsername():String{ return username; } public function getEmail():String{ return email; } public function setUsername(username:string):void{ // set your username } public function setEmail(email:string):void{ // set your email } } } So when you first instantiate your class you set the username/email. Then all you will need to do is use getUsername/getEmail to retrieve the data that you are looking for. One last point make sure you that only instantiate the myLogin class once.
[flexcoders] Re: storing login data from a cfquery for use throught flex app
--- In flexcoders@yahoogroups.com, stinasius stinas...@... wrote: hi i got a login form in flex with a coldfusion backend and it work's perfectly but i need it to go one step further. store login data form the cfquery so that it can be reused throughout the flex app. here is a senario. the login form has a username and password textinput fields which are validated using a remote object call to a cfc that queries a db table with username, password and email fields. now when login is successful i would like to store the data returned from the cfc including email for use throughout my application. please help me out here. thanks You might want to also look into using singleton patterns.
[flexcoders] Re: storing login data from a cfquery for use throught flex app
hi i created a storage class that i was using and it works perfectly but i dont know how to use it to get data from a cfc through remote object call. here is my code it works with username and password but when it comes to geting the email address associated with the username and password from the db i dont know how to do that and thats my biggest problem. mainApp.mxml ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute xmlns:view=components.* mx:states mx:State name=Log Out mx:SetProperty target={label1} name=text value=Log Out/ /mx:State /mx:states mx:Script ![CDATA[ import components.*; //Flash Classes import flash.events.Event; import flash.events.MouseEvent; //Flex Classes import mx.containers.TitleWindow; import mx.controls.Alert; import mx.events.CloseEvent; import mx.managers.PopUpManager; import mx.core.IFlexDisplayObject; import mx.utils.ObjectUtil; //static class import classes.UserInfo; public var loggedin:Boolean = false; public var pop:Login; private function showLogin():void { pop = Login(PopUpManager.createPopUp(Application.application as DisplayObject,Login,true)); pop.showCloseButton =true; PopUpManager.centerPopUp(pop); pop.addEventListener(close,removeMe); pop[cancelButton].addEventListener(click, removeMe); pop.addEventListener( loginSuccessful, handleLoginSucess); //UserInfo.Email = pop.authManager.email; } private function removeMe(event:Event):void { PopUpManager.removePopUp(pop); } private function handleLoginSucess(event:Event):void{ viewstack1.selectedChild = admin; lbl_intro.text = Welcome +pop.username_txt.text; removeMe(event); currentState = 'Log Out'; UserInfo.UserName = pop.username_txt.text; UserInfo.Email = pop.authManager.email; //mx.controls.Alert.show(mx.utils.ObjectUtil.toString(pop.authManager)); //trace (UserInfo.Email); } ]] /mx:Script mx:Label x=0 y=0 text=Sign In id=label1 buttonMode=true useHandCursor=true mouseChildren=false click=showLogin()/ mx:ViewStack x=0 y=26 id=viewstack1 width=100% height=100% view:Home id=home/ view:Admin id=admin/ /mx:ViewStack mx:Label x=700 y=0 id=lbl_intro/ /mx:Application login.mxml ?xml version=1.0 encoding=utf-8? mx:TitleWindow xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute title=Login Form mx:Metadata [Event(name=loginSuccessful, type=flash.events.Event)] /mx:Metadata mx:Script ![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.utils.ObjectUtil; import mx.controls.Alert; import mx.events.ValidationResultEvent; import mx.core.Application; import classes.UserInfo; private function isValid():Boolean { var emailValidResult:ValidationResultEvent = this.emailValidate.validate(this.username_txt.text); var pswdValidResult:ValidationResultEvent = this.pswdValidate.validate(this.password_txt.text); if (emailValidResult.type==ValidationResultEvent.VALID pswdValidResult.type==ValidationResultEvent.VALID) { return true; } else { return false; } } private function authenticateUser():void { if( isValid() ) { authManager.loginUser( this.username_txt.text, this.password_txt.text/* , userCredentials */); UserInfo.isLogged = true; } } private function errorMessage(msg:String):void { //Alert.show(
RE: [flexcoders] Re: storing login data from a cfquery for use throught flex app
Have your login cfc return the user data if the user is verified, and assign the properties of UserInfo in the result handler. Tracy Spratt, Lariat Services, development services available _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of stinasius Sent: Wednesday, March 11, 2009 1:14 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: storing login data from a cfquery for use throught flex app hi i created a storage class that i was using and it works perfectly but i dont know how to use it to get data from a cfc through remote object call. here is my code it works with username and password but when it comes to geting the email address associated with the username and password from the db i dont know how to do that and thats my biggest problem. mainApp.mxml ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe. http://www.adobe.com/2006/mxml com/2006/mxml layout=absolute xmlns:view=components.* mx:states mx:State name=Log Out mx:SetProperty target={label1} name=text value=Log Out/ /mx:State /mx:states mx:Script ![CDATA[ import components.*; //Flash Classes import flash.events.Event; import flash.events.MouseEvent; //Flex Classes import mx.containers.TitleWindow; import mx.controls.Alert; import mx.events.CloseEvent; import mx.managers.PopUpManager; import mx.core.IFlexDisplayObject; import mx.utils.ObjectUtil; //static class import classes.UserInfo; public var loggedin:Boolean = false; public var pop:Login; private function showLogin():void { pop = Login(PopUpManager.createPopUp(Application.application as DisplayObject,Login,true)); pop.showCloseButton =true; PopUpManager.centerPopUp(pop); pop.addEventListener(close,removeMe); pop[cancelButton].addEventListener(click, removeMe); pop.addEventListener( loginSuccessful, handleLoginSucess); //UserInfo.Email = pop.authManager.email; } private function removeMe(event:Event):void { PopUpManager.removePopUp(pop); } private function handleLoginSucess(event:Event):void{ viewstack1.selectedChild = admin; lbl_intro.text = Welcome +pop.username_txt.text; removeMe(event); currentState = 'Log Out'; UserInfo.UserName = pop.username_txt.text; UserInfo.Email = pop.authManager.email; //mx.controls.Alert.show(mx.utils.ObjectUtil.toString(pop.authManager)); //trace (UserInfo.Email); } ]] /mx:Script mx:Label x=0 y=0 text=Sign In id=label1 buttonMode=true useHandCursor=true mouseChildren=false click=showLogin()/ mx:ViewStack x=0 y=26 id=viewstack1 width=100% height=100% view:Home id=home/ view:Admin id=admin/ /mx:ViewStack mx:Label x=700 y=0 id=lbl_intro/ /mx:Application login.mxml ?xml version=1.0 encoding=utf-8? mx:TitleWindow xmlns:mx=http://www.adobe. http://www.adobe.com/2006/mxml com/2006/mxml layout=absolute title=Login Form mx:Metadata [Event(name=loginSuccessful, type=flash.events.Event)] /mx:Metadata mx:Script ![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.utils.ObjectUtil; import mx.controls.Alert; import mx.events.ValidationResultEvent; import mx.core.Application; import classes.UserInfo; private function isValid():Boolean { var emailValidResult:ValidationResultEvent = this.emailValidate.validate(this.username_txt.text); var pswdValidResult:ValidationResultEvent = this.pswdValidate.validate(this.password_txt.text); if (emailValidResult.type==ValidationResultEvent.VALID pswdValidResult.type==ValidationResultEvent.VALID) { return true; } else { return false; } } private function authenticateUser():void { if( isValid() ) { authManager.loginUser( this.username_txt.text, this.password_txt.text/* , userCredentials */); UserInfo.isLogged = true; } } 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']); } //[Bindable] //private var profileAr:ArrayCollection = new ArrayCollection; private function login_result(event:ResultEvent):void { // login successful, remember the user. if( event.result == true || event.result == TRUE || event.result == 1 || event.result == 1 ) { //profileAr = new ArrayCollection((event.result as ArrayCollection).source); /* Application.application.authenticateUser(userCredentials); */ this.dispatchEvent( new Event('loginSuccessful') ); } else { // login didn't work. show message errorMessage(Login unsuccessful); } } ]] /mx:Script mx:RemoteObject id=authManager destination=ColdFusion source=login_example.cfc.login showBusyCursor=true mx:method name=loginUser result=login_result(event) fault=serverFault(event) / /mx:RemoteObject mx:StringValidator id=emailValidate source={this.username_txt} property=text required=true / mx:StringValidator id=pswdValidate source={this.password_txt} property=text required=true