简体   繁体   中英

Login system with flex mobile

I followed an example on how to make a login system in flex. This example was not made for flex mobile projects, but desktops running in a browser. As I understand I can use the same code but with different components. I keep getting errors. My code is beneath.

PHP code for connecting and quering the database, and send result back with xml

<?php

echo "<?xml version="\"1.0\" ?>\n";

$con = mysql_connect("HOST","USER","PASS");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("DatabaseName here"); 

//Variables that I wil retrieve from the flex application

$user = $_POST['user']; 
$pass = $_POST['pass'];


//mySQL query 
$result = mysql_query("SELECT * FROM `brukere` WHERE 1");

//not logged in so it's false
$loged = false; 

//Comparing the text i retrieved from the flex app and the rows in my database. 

while($row = mysql_fetch_assoc($result))
{
   if(strtolower($user) == strtolower($row['brukernavn']) &&
   strtolower($pass) == strtolower($row['passord']))   
   {
         $loged = true: 
       }
} 

//so if loged is true, pass true in xml to my flex application. 
if($loged == true) 
echo "<status>true</status>"; 
else
echo "<status>false</status>"; 
?>

My HTTPService in the flex code

    <fx:Declarations>

    <mx:HTTPService id="loginService" result="onResult(event)"  method="POST" url="URL TO THE PHP SCRIPT">

        <mx:request xmlns="">

            <user>{username.text}</user>

            <pass>{pass.text}</pass>

        </mx:request>

    </mx:HTTPService>
        </fx:Declarations>

And then my Actionscripts

<fx:Script>
    <![CDATA[
        import mx.rpc.events.ResultEvent;
        import mx.controls.Alert; 

        private function login():void 
        {
            loginService.send();    
        }

        private function onResult(e:ResultEvent):void
        {

            if(e.result.status == true) {

                Alert.show("Succesful"); 

            }

            else {

                Alert.show("Wrong"); 
            }
        }
    ]]>
</fx:Script>

Finally the GUI:

<s:VGroup includeIn="notLoggedIn" x="286" y="164" width="45%" height="200">
    <s:HGroup includeIn="notLoggedIn" width="100%" height="38" verticalAlign="middle">
        <s:Label width="30%" height="31" text="Brukernavn: " verticalAlign="middle"/>
        <s:TextInput id="username" width="70%"/>
    </s:HGroup>
    <s:Spacer width="459" height="10"/>
    <s:HGroup includeIn="notLoggedIn" width="100%" height="40" verticalAlign="middle">
        <s:Label width="30%" height="34" text="Passord:" verticalAlign="middle"/>
        <s:TextInput id="pass" width="70%"/>
    </s:HGroup>
    <s:Spacer width="458" height="10"/>
    <s:HGroup width="462" height="65">
        <s:Spacer width="70%" height="64"/>
        <s:Button width="30%" label="Logg inn" click="login()"/>
    </s:HGroup>
</s:VGroup>

This is all the output when I debugging the app:

[SWF] AKTIVe.swf - 4,192,242 bytes after decompression
ReferenceError: Error #1069: Property status not found on String and there is no    default value.
at Views::Login/onResult()[C:\Users\Tobias\Documents\bacheloroppgave\workspace\src\Views\Login.mxml:54]
at Views::Login/__loginService_result()[C:\Users\Tobias\Documents\bacheloroppgave\workspace\src\Views\Login.mxml:13]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:993]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318]
at mx.rpc::Responder/result()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

My First thought was that I can't use <mx:HTTPService> and other mx based services in my mobile flex application. Does anybody know what I should look for?

Sorry for a long post, but atleast its informal enough :)

Thanks in advance

use charles proxy to check what exactly you are sending to server (request) and getting back from server (response)

charles proxy website

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM