22.3. Revising Login

Login and logout are currently accomplished with the following classes:

  • LoginEvent

  • LogoutEvent

  • LoginDelegate

  • LoginCommand

  • LogoutCommand

The LoginEvent and LogoutEvent will be replaced with types on the UserEvent class.

The login function of the LoginDelegate will be moved to the UserDelegate.

The LoginCommand will be updated to cast the event as a UserEvent and use the new UserDelegate.

The LogoutCommand does not make use of a delegate, nor does it reference any data passed in by the event class, so it will remain as is.

Start by updating the UserEvent class by adding the following two constants:

public static const LOGIN:String = 'loginEvent';
public static const LOGOUT:String = 'logoutEvent';

Now move the login function from the LoginDelegate class to the UserDelegate class. It should now look as follows:

package com.FlexBlog.delegates { import com.FlexBlog.valueobjects.UserVO; import flash.errors.SQLError; import mx.rpc.IResponder; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import sql.FlexBlogDatabaseManager; public class UserDelegate { private var responder:IResponder; public function UserDelegate(responder:IResponder) { this.responder =responder; } public function register(user:UserVO):void{ var dbManager:FlexBlogDatabaseManager = FlexBlogDatabaseManager.getInstance(); try{ var userAdded:int = dbManager.registerUser(user); var event:ResultEvent = new ResultEvent(ResultEvent.RESULT,false,true,{added:userAdded}) this.responder.result(event) ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.