loginListener

Package: machii_info_sample.controllers
Inherits from: MachII.framework.Listener
Authenticates a user?s login credentials based on username and password.
Method Summary
public void attemptLogin(Event event)
public void configure()
private void doLogin(numeric userID)
public void doLogout(Event event)
private boolean isLoginValid(string username, string password)
Method Detail
attemptLogin

public void attemptLogin( Event event )

Parameters:
Event event

Code:

	<cffunction name="attemptLogin" access="public" returntype="void">
		<cfargument name="event" type="MachII.framework.Event" required="true" />		
		<cfscript>
			var username = arguments.event.getArg("username");
			var password = arguments.event.getArg("password");
			//AUTHENTICATE USER INFO 
			//ANNOUNCE SUCCESS/FAILURE EVENT 
			if (isLoginValid(username, password)){
				announceEvent("loginSucceeded");
			} else {
				announceEvent("loginFailed");
			}
		</cfscript>
	</cffunction> 

configure

public void configure( )

Parameters:

Code:

	<cffunction name="configure" access="public" returntype="void">		
		<cfscript>			
			var appConstants = getAppManager().getPropertyManager().getProperty("appConstants");
			var dsn = appConstants.getDsn();
			var dbType = appConstants.getDbType(); 			
			variables.pm = getAppManager().getPropertyManager();
			variables.userGateway = createObject("component","machii_info_sample.model.user.userGateway").init(dsn);
			variables.userDAO = CreateObject("component", "machii_info_sample.model.dao.DAOFactory").init(dsn, "machii_info").getDAOFactory(dbtype).getUserDAO();
		</cfscript>
	</cffunction> 

doLogin

private void doLogin( numeric userID )

Parameters:
numeric userID

Code:

	<cffunction name="doLogin" access="private" returntype="void">		
		<cfargument name="userID" type="numeric" required="true" />
		<cfscript>				
			var uf = pm.getProperty("userfacade");
			var user = createObject("component","machii_info_sample.model.user.user").init();			
			var userTO = variables.userDAO.read(arguments.userid);			
			user.setUserFromTO(userTO);
			user.setIsLoggedIn(true);
			uf.setUser(user);			
		</cfscript>
	
	</cffunction> 

doLogout

public void doLogout( Event event )

Parameters:
Event event

Code:

	<cffunction name="doLogout" access="public" returntype="void">
		<cfargument name="event" type="MachII.framework.Event" required="true" />				
		<cfscript>	
			var uf = pm.getProperty("userfacade");
			var user = uf.getUser();
			user.setIsLoggedIn(false);						
		</cfscript>	
	</cffunction> 

isLoginValid

private boolean isLoginValid( string username, string password )

Parameters:
string username
string password

Code:

	<cffunction name="isLoginValid" access="private" returntype="boolean">
		<cfargument name="username" type="string" required="true" />
		<cfargument name="password" type="string" required="true" />
		<cfset var qry_user = variables.userGateway.getUserByUsernamePassword(arguments.username,arguments.password) >				
		<cfif qry_user.recordCount >
			<cfset doLogin(qry_user.userID) >
			<cfreturn true />
		<cfelse>
			<cfreturn false />
		</cfif>
	</cffunction>