1 Reply Latest reply on Apr 10, 2007 3:04 AM by Antonio H Garcia

    How to login based on XML

    comlong
      Hello,
      I am new for a Flex demo. The request is login and register. I want save all information in a XML file and then check it. From Adobe's demo, there are only the interface, I want to know how to implement the function and the code. If I juse this way without Java, is it possilbe to publish on a web-server?
      Thanks a lot
        • 1. Re: How to login based on XML
          Antonio H Garcia
          check this code:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*" initialize="login_user.send();" width="100%" height="100%">

          <mx:Style source="style.css" />

          <mx:Script>
          <![CDATA[
          //import easing classes
          import mx.effects.easing.Bounce;
          ]]>
          </mx:Script>

          <!--start transitions-->
          <mx:transitions>
          <!--applies a composite transition to the login and register states-->
          <mx:Transition fromState="*" toState="*">
          <!-- Parallel effects execute in unison -->
          <mx:Parallel targets="{[loginPanel, registerLink, loginButton, confirm]}">
          <mx:Resize duration="500" easingFunction="Bounce.easeOut"/>
          <!--Sequence effects execute in turn only affect the confirm FormItem.-->
          <mx:Sequence target="{confirm}"><mx:Blur duration="200" blurYFrom="1.0" blurYTo="20.0" />
          <mx:Blur duration="200" blurYFrom="20.0" blurYTo="1" />
          </mx:Sequence>
          </mx:Parallel>
          </mx:Transition>
          </mx:transitions>

          <!-- The states property of the Application class defines the view states. -->
          <mx:states>
          <!--The "Register" state is based on the base state.-->
          <mx:State name="registro" basedOn="">
          <!-- Add a FormItem component to the form. -->
          <mx:AddChild
          relativeTo="{loginForm}"
          position="lastChild"
          creationPolicy="all">

          <mx:FormItem id="confirm" label="Confirma:">
          <mx:TextInput/>
          </mx:FormItem>
          </mx:AddChild>

          <!-- Set properties on the Panel container and Button control. -->
          <mx:SetProperty target="{loginPanel}"
          name="title" value="Registro de promotores"/>

          <mx:SetProperty target="{loginButton}"
          name="label" value="Registrar"/>

          <!-- Remove the existing LinkButton control. -->
          <mx:RemoveChild target="{registerLink}"/>

          <!--Add a new LinkButton control to change view state back to the login form.-->
          <mx:AddChild relativeTo="{spacer1}" position="before">

          <mx:LinkButton label="Volver a Ingreso" click="currentState=''"/>
          </mx:AddChild>
          <mx:SetProperty target="{loginPanel}" name="height" value="186"/>
          <mx:SetStyle target="{loginPanel}" name="horizontalCenter" value="0.5"/>

          </mx:State>
          <mx:State name="Viewdata">
          <mx:RemoveChild target="{loginPanel}"/>
          <mx:AddChild position="lastChild">
          <mx:Panel width="90%" height="90%" layout="absolute" title="Area de clientes" id="ViewdataPanel" horizontalCenter="0" verticalCenter="1.5">
          <mx:MenuBar x="480" y="-30"></mx:MenuBar>
          <mx:Label x="10" y="10" text="Bienvenido {login_user.lastResult.contents.dclave.(usuario == username.text).nombre} al Area Clientes"/>
          </mx:Panel>
          </mx:AddChild>
          </mx:State>
          </mx:states>
          <!--This actionscript defines a bindable data provider to pass in an array from the database.
          Needs the RemotingConnection.as class in order to work -->

          <mx:Script>
          <![CDATA[
          import mx.rpc.events.ResultEvent;
          import mx.collections.*;
          import mx.controls.*;
          import mx.events.*;
          import mx.messaging.events.*;
          import mx.rpc.*;
          import mx.rpc.events.*;
          import mx.effects.easing.Bounce;
          import flash.net.Responder;
          public function gooURL():void
          {

          var str1:String = "newpromociones.asp?id=";
          var str4:String = str1;
          var gourl:String = str4;
          navigateToURL( new URLRequest( gourl ),"_self");
          }
          ]]>
          </mx:Script>
          <mx:Script>


          <![CDATA[

          [Bindable]
          private var estilos:Array = ["Centro Urbano", "Montaña", "Playa", "Golf"];

          private function checkLogin():void
          {

          if (login_user.lastResult.contents.dclave.(usuario == username.text).usuario == username.text && login_user.lastResult.contents.dclave.(clave == password.text).clave == password.text)
          {currentState = "Viewdata";};

          if (login_user.lastResult.contents.dclave.(usuario == username.text).usuario != username.text && login_user.lastResult.contents.dclave.(clave == password.text).clave == password.text)
          {mx.controls.Alert.show('Usuario incorrecto');};

          if (login_user.lastResult.contents.dclave.(usuario == username.text).usuario == username.text && login_user.lastResult.contents.dclave.(clave == password.text).clave != password.text)
          {mx.controls.Alert.show('Contraseña incorrecta');};

          if (login_user.lastResult.contents.dclave.(usuario == username.text).usuario != username.text && login_user.lastResult.contents.dclave.(clave == password.text).clave != password.text)
          {mx.controls.Alert.show('Usuario y contraseña incorrecta');};
          }



          ]]>


          </mx:Script>

          <mx:HTTPService id="login_user" resultFormat="e4x" showBusyCursor="true" url="login.xml" useProxy="false"/>

          <mx:Panel
          title="Ingreso de promotores" id="loginPanel"
          horizontalScrollPolicy="off" verticalScrollPolicy="off" layout="horizontal" height="158" horizontalCenter="0" verticalCenter="0">

          <mx:Form id="loginForm">
          <mx:FormItem label="Usuario:">
          <mx:TextInput id="username"/>

          </mx:FormItem>
          <mx:FormItem label="Contraseña:">
          <mx:TextInput id="password" displayAsPassword="true"/>
          </mx:FormItem>
          </mx:Form>


          <mx:ControlBar>
          <!--Use the LinkButton control to change to the Register view state.-->
          <mx:LinkButton
          label="Registrarse ?" id="registerLink"
          click="currentState='registro'"/>

          <mx:Spacer width="100%" id="spacer1"/>

          <mx:LinkButton label="Ingresar" id="loginButton"
          click="checkLogin();"/>

          </mx:ControlBar>

          </mx:Panel>
          </mx:Application>