Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Newbie Question about Proxys and User Authentication  (Read 8264 times)
skasssam
Jr. Member
**
Posts: 18


View Profile Email
« on: May 28, 2008, 11:50:33 »

I am finally starting to get my application off the ground. I am still trying to wrap my heard around all this since I am new to puremvc and flex.

I am authenticating a user using a remoteobject.

All that works, I am able to authenticate and change my viewstack if the authentication is successful.

On my view that is displayed after the user logs in I want to display a simple "Welcome, <username>"

How do I access my user object from an arbitrary view?

Here is my code for the loginProxy:
:
public class LoginProxy extends Proxy implements IProxy
{
public static const NAME:String = "LoginProxy";

private var loginService:RemoteObject;

public function LoginProxy( data:Object = null ){
super(NAME, data);

}

public function userLogin(username:String,password:String):void {
loginService = new RemoteObject();
loginService.source = "org.enohp.app.Userdao";
loginService.destination = "userService";
loginService.addEventListener( FaultEvent.FAULT, onFault );
loginService.getUserFromLogin.addEventListener( ResultEvent.RESULT, onResult );
loginService.getUserFromLogin.send(username,password);
}

private function onResult( event:ResultEvent ):void {
if (!event.result) {
Alert.show("You have entered an invalid username/password", "Login Error");
} else {
setData(event.result as User);
Alert.show("You have successfully logged in.", "Login Success");
sendNotification( ApplicationFacade.VIEW_FBAPP );
}
}

private function onFault(fault:FaultEvent):void {
Alert.show(fault.fault.faultString + "\n" + fault.fault.faultDetail, fault.fault.faultCode.toString());
}

public function get user():User
{
return data as User;
}
}

The loginProxy is called from a notification that is handled by my loginMediator:

:
private function onMouseClick(e:Event):void {
loginProxy.userLogin(theView.username.text,theView.password.text);
Alert.show(ObjectUtil.toString(loginProxy.getData()), "Login User from Login Mediator");
}

I thought  that my alert in the mediator should show the user that was authenticated but it returns null.

Any help is appreciated.

TIA,
Shinan
« Last Edit: May 29, 2008, 05:36:13 by skasssam » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 29, 2008, 05:31:45 »

Have the proxy send a notification with the data as the body Have the appropriate mediator list tha( notification as an interest and respond by taking the data and setting it on the view component.

-=Cliff>
Logged
skasssam
Jr. Member
**
Posts: 18


View Profile Email
« Reply #2 on: May 29, 2008, 05:35:13 »

Yes, indeed. That occurred to me late yesterday after pouring through the forums and documentation. It worked. It is all starting to make more sense to me now.

Thanks Cliff for pureMVC and for taking the time to help us newbies out in the forums.

I appreciate it.

Regards.
Logged
Pages: [1]
Print