5 Replies Latest reply on Jul 31, 2006 6:21 AM by slikone27

    user authentication

      I am coldfusion programmer and new to flex and was wondering if anyone could help me out. I am converting a coldfusion app to flex and dont understand user authentication in flex. I have looked at the JamJar app and want to do something similar.

      1. How do I popup the login screen when the app is loaded? I need to make the session timeout after 20 minutes of no activity and make the login screen pop back up.

      2. How does the user authentication work in flex? I want to be able to do the same thing that I do in coldfusion. I need to be able to check user credentials against the database and store them in the session somehow. I get the roles from the database too. Is there a better way to accomplish this in flex?

      3. Should I use AS if statements to control what the user can see/do in the app? or is there a better way to do this in flex?

      I definetly think adobe needs to go into this in more detail since this is one of the most important part of the application.

      Thanks for your help.
        • 1. Re: user authentication
          ANSCORP Level 1
          This can be handled a couple of different ways, I think. You can actually use a CFML page to authenticate a user against your database and then pass information (such as the user ID, user name, access control variables, etc.) into the Flex application in the html wrapper that loads your SWF file (using Flashvars). These variables would be accessed in the Application.application.parameters scope in Action Script. The documentation on how to do this can be found here:

          http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=L iveDocs_Parts&file=00001003.html

          I can't see why you would'nt be able to do something similar with a Flex login screen too using view states and/or transitions. You'd make a remote call to your database and then store the results in public variables in your application to determine access within your application.

          If you find a better way to handle this, let me know. For now, this is likely the method that I'll use.

          Good Luck,
          M. McConnell
          • 2. Re: user authentication
            ANSCORP Level 1
            Actually, scratch that. The documentation I've referred you to is basically useless. The code examples don't work.

            I am becoming increasingly frustrated with this product (Flex). It is fairly complex, particularly if you're just a CF developer, and I find myself spending more time trying to figure something out in the documentation than doing any real programming. It's like having to learn to code all over again. In addition, the first response to questions in these forums by Adobe (and others - myself included) is "look at the docs". Well, if the docs aren't correct, what good are they? I literally cut and pasted all the example code associated with communicating with a Flex app through flahsvars as described in LiveDocs (see link in my previous post in this thread) and it did not work. All I get for the application variables is "null" values.

            At this point, I'm considering just cutting my losses and going back to CFForms.

            M. McConnell
            • 3. Re: user authentication
              ANSCORP Level 1
              Update - After reviewing several more articles and Doc references(none of which had the complete answer by itself), I found the answer to using Flashvars. You'll notice that when you compile your Flex app, Flex builder creates an html wrapper for your SWF. It's usually entitled "yourappname.html" where "yourappname" is the name of your main mxml application file. There is a section in the JavaScript code that identifies the user's version of the Flash player. If the user passes all tests for major and minor version, the JavaScript creates the code to embed the SWF file for your Flex app. There is a line in this code segment that references "flashvars". By default, it looks like this:

              "flashvars",'historyUrl=history.htm%3F&lconid=' + lc_id + '',

              If you edit the line with "flashvars" on it to pass in your variables, you can then access the variables with the Application.application.parameters.myvariablename call inside your mxml code. Let's say you wanted to pass a user name into the Flex app. You could do it by modifying the flashvars line in the wrappers JavaScript code as follows:

              "flashvars","myName=Mike&historyURL=history.htm%3f&Iconid=' + Ic_id + ",

              Then, you would access it in MXML as follows:

              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="initVars()">
              import mx.controls.Alert;
              import mx.core.Application;
              // Declare bindable properties in Application scope.
              public var myName:String;

              // Assign values to new properties.
              private function initVars():void {
              myName = Application.application.parameters.myName;

              <mx:Label text="Name: "/>
              <mx:Label text="{myName}" fontWeight="bold"/>

              When you run this file, you should see the value of the name you've passed in via Flashvars.

              This code is available in the Flex docs, but the Flex docs don't do a very good job of telling you how to use Flashvars to pass in the values. A WORD OF CAUTION: If you make a change to your mxml code and Flex recompiles your application, the changes you made to the wrapper are overwritten and you'll lose your flashvar settings. I'm sure there is a way to avoid this behavior (at least I hope there is), but I haven't looked into it yet.

              M. McConnell
              • 4. user authentication
                ANSCORP Level 1
                And one more thing....If you save an exact copy of your Flex created wrapper file, let's say "main.html" as "main.cfm", it won't get overwritten. Plus, you can pass variables to the flashvars line in the JavaScript code between <cfoutput> tags so you can read url variables or form variables and change the content of the flashvars (eg. myName=<cfoutput>#url.myname#</cfoutput>. I just tried it and it actually works. If anyone has a better way to do this, please chime in.

                M. McConnell
                • 5. Re: user authentication
                  slikone27 Level 1
                  thanks... I currently have a login screen as a state of the app. When the user logins the app changes view states so the menu comes up at the top. Just wanted to make sure I was doing it right before I got to far along. Unfortunately I can't use CF because we are going to FDS so data will be real time. I think I remember seeing somewhere that if you change the wrapper file that is in the bin directory of your workspace, when it recompiles you wont lose your changes.