Good morning all,

I am copying 4 files that make up my LOGIN component.    
login.mxml      -- (wrapped it in an application tag for testing)
CF/login.cfc     -- (Coldfusion component to access database and handle 
business rules
UTIL/modelLocator.as -- for sharing data and handling events
VO/users.as     --  Users class

It works FINE!  it is NOT very OOPS and would like to see what others will 
suggest to make 
it simpler, easier to follow, less code, etc.  (on purpose, there is no style 
sheets, etc.)
  
I am a single developer who will be the only one supporting this code (ok, 
actually a LAZY  
developer who does not like to write extra code just to loosely-couple 
modules).  

I expect some "interesting" discussions since about 1/2 of the people in this 
forum are 
very OOP's focused and see the solution to everything as a class and the other 
1/2 seem 
to be application programmers from (VB/Delphi/....) who are somewhat class 
challenged 
(and certainly actionscript3 challenged)

Bruce

------------- LOGIN.MXML -----------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
        layout="absolute">
<mx:Script>
        <![CDATA[
                import vo.Users;
                import mx.rpc.events.ResultEvent;
                import mx.rpc.events.FaultEvent;
                import util.ModelLocator;
                import mx.controls.Alert;
                
                [Bindable]
                public var model:ModelLocator = ModelLocator.getInstance();

                
                private function processLoginResults( event : ResultEvent) : 
void {
                        model.currentUser = new Users();

                        // EVERYTHING RETURNED FROM CFC IS A STRING AND 
UPPERCASE
                        model.currentUser.loggedIn = (event.result.LOGGEDIN == 
'true');

                        // CHECK FIRST TO SEE IF SUCCESSFUL LOGIN
                        if (model.currentUser.loggedIn) {
                                model.currentUser.userID = event.result.USERID;
                                model.currentUser.firstName = 
event.result.FIRSTNAME;
                                model.currentUser.lastName = 
event.result.LASTNAME;
                                laStatus.text = "Hello " + 
model.currentUser.firstName;
                        } else laStatus.text = event.result.STATUS;     
                // DISPLAY ERROR MSG IF NOT SUCCESSFUL
                }
                
                private function showError(event: FaultEvent, funcName : 
String) :void {
                Alert.show(event.fault.faultDetail, "Database Error - function: 
" + funcName);
                }
                
                public function processOK ( event: Event) : void  {
                        cfcLogin.processLogin(txtUserID.text, txtPassword.text) 
;
                }
                
                
        ]]>
</mx:Script>
<mx:RemoteObject id="cfcLogin" 
        destination="ColdFusion" 
        source="lumber.CF.login" 
        showBusyCursor="true" fault="showError(event, 'Login')">
        <mx:method name="processLogin" result="processLoginResults(event)" />
</mx:RemoteObject> 
        <mx:Panel id="panelLogin" title="Please Login" defaultButton="{pbOK}">
                <mx:Form>
                        <mx:FormItem label="User Name">
                                <mx:TextInput id="txtUserID"/>
                        </mx:FormItem>
                        <mx:FormItem label="Password">
                                <mx:TextInput  id="txtPassword" 
displayAsPassword="true" />
                        </mx:FormItem>
                </mx:Form>
        <mx:ControlBar horizontalAlign="right">
                <mx:Label id = "laStatus" text="Status:  Not Logged in" />
                <mx:Button id="pbOK" label="OK" width="70"  
                         click="processOK( event )"/>
                <mx:Button id="pbCancel" label="Cancel"  width="70" />
        </mx:ControlBar>                
        </mx:Panel>
</mx:Application>

-------------------- CF/LOGIN.CFC -------------------
<cfcomponent>
        <!--- ACCEPTS USER NAME AND PASSWORD AND RETURNS a STRUCTURE  --->
        
        <cffunction access="remote" name="processLogin" output="false" 
returnType="struct">
                <cfargument name="userID" type="string" required="true">
                <cfargument name="password" type="string" required="true">

                <!--- 1ST, CREATE THE STRUCTURE AND DEFAULT SOME VALUES --->
                <cfset var myUser = StructNew()>
                <cfset myUser.loggedIn = 'false' >

                <!--- ATTEMPT TO READ THE USER RECORD --->
                <cfquery name="results" datasource="american">
                select userID, firstName, LastName, password from Users
                                where username = '#arguments.userID#'
                </cfquery>
                
                <cfscript>
                        if (results.recordcount eq 0) {                         
        
                //      IF NO MATCH ON USERID DISPLAY AN ERROR
                                myUser.status = "Invalid UserID";
                        } else if (arguments.password NEQ results.password) { 
        // DITTO IF INVALID PASSWORD
                                myUser.status = "Invalid Password";
                        } else {                                                
                
                                // USER AUTHORIZED
                                myUser.userID = results.userID;
                                myUser.firstName = results.firstName;
                                myUser.lastName = results.lastName;
                                myUser.loggedIn = 'true';
                                myUser.status = "Authorized";
                        }
                </cfscript>
                
                <cfreturn myUser>
        </cffunction>   
</cfcomponent>

--------------------- UTIL/MODELLOCATOR.AS ------------------
/*
        this package is the commuuncations center of the applications
        responsible for dispatching events and storage of share variables
        (specifically the persistant data stored in the database

*/


package util{
        
        import flash.events.EventDispatcher;
        import mx.collections.ArrayCollection;
        // IMPORT ALL USER VO'S BELOW
        import vo.Users;
        
        
        [Bindable]
        public class ModelLocator extends EventDispatcher{
                
                
                public function ModelLocator(){
                        //
                }
                
                private static var _instance:ModelLocator
                
                public static function getInstance() :ModelLocator{
                        if( !_instance ){
                                _instance = new ModelLocator();
                        }
                        return _instance;
                }
                
        // 
        public var currentUser : Users;
        }

}
--------------------VO/USERS.AS -------------------
package vo
{
        [Bindable]
        public class Users
        {               
                public var userID               : int;
                public var firstName    : String;
                public var lastName             : String;
                public var loggedIn             : Boolean = false;
                        
                
                public function Users() {
                }
        }
}






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcoders/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to