userListener

Package: machii_info_sample.controllers
Inherits from: MachII.framework.Listener
I am the listener for users
Method Summary
public void configure()

I initialize this listener as part of the framework startup.

public void createUser(Event event)

I cause a user to be created from the current event object.

public void deleteUser(Event event)

I cause a user to be deleted.

public numeric getSessionIsAdmin(Event event)

I return the isAdmin property for the session user

public numeric getSessionUserId(Event event)

I return the userID for the session user

public userTO getUserData(Event event)

I return a user identified by it's ID

public void getUserDataByEmail(Event event)

I return a user identified by it's email

public struct getUserDataById(Event event)

I return a user identified by it's ID

public array getUsers(Event event)

I return a query containing users.

public void updateUser(Event event)

I cause a user to be updated from the current event object.

Method Detail
configure

public void configure( )

I initialize this listener as part of the framework startup.

Parameters:

Code:

	<cffunction name="configure" access="public" returntype="void" output="true" displayname="Listener Constructor" hint="I initialize this listener as part of the framework startup.">				
		<cfscript>						
	        var appConstants = getAppManager().getPropertyManager().getProperty("appConstants");
			variables.dbType = appConstants.getDbType(); 			
	        variables.dsn = appConstants.getDsn(); 						
			variables.userFacade = getAppManager().getPropertyManager().getProperty("userFacade");
			variables.userService = createObject("component", "machii_info_sample.model.user.userService").init();
		</cfscript>					
	</cffunction> 

createUser

public void createUser( Event event )

I cause a user to be created from the current event object.

Parameters:
Event event

Code:

	<cffunction name="createUser" access="public" returntype="void" output="false" displayname="Create User" hint="I cause a user to be created from the current event object.">
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event" />
		<cfset var user = arguments.event.getArg("user") />		
		<cfset var userData = user.getUserTO() />
		<cfset var errors = structNew() />
		<cftry>			
			<cfset variables.userService.createUser(argumentcollection=userData, dsn=variables.dsn, dbtype=variables.dbtype) />
			<cfset announceEvent("createUser.success", arguments.event.getArgs()) />
		<cfcatch type="Database">
			<cfif findNoCase("duplicate",cfcatch.detail) >
				<cfscript>
					errors.usernameExists = "That username has been taken.";
					user.setErrors(errors);
					announceEvent("createUser.usernameExists", arguments.event.getArgs());
				</cfscript>				
			<cfelse>
				<cfrethrow>
			</cfif>
		</cfcatch>
		</cftry>
	</cffunction> 

deleteUser

public void deleteUser( Event event )

I cause a user to be deleted.

Parameters:
Event event

Code:

	<cffunction name="deleteUser" access="public" returntype="void" output="false" displayname="Delete User" hint="I cause a user to be deleted.">
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event" />		
		<cfset var userID = arguments.event.getArg("userID") />		
		<cfset variables.userService.deleteUser(userID=userID,dsn=variables.dsn, dbtype=variables.dbtype) />	 
	</cffunction> 

getSessionIsAdmin

public numeric getSessionIsAdmin( Event event )

I return the isAdmin property for the session user

Parameters:
Event event

Code:

	<cffunction name="getSessionIsAdmin" access="public" returntype="numeric" output="false" displayname="Get session user.isAdmin" hint="I return the isAdmin property for the session user">
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event" />		
		<cfscript>
			var isAdmin = 0;
			isAdmin = userFacade.getUser().getIsAdmin();
		</cfscript>
		<cfreturn isAdmin />
	</cffunction> 

getSessionUserId

public numeric getSessionUserId( Event event )

I return the userID for the session user

Parameters:
Event event

Code:

	<cffunction name="getSessionUserId" access="public" returntype="numeric" output="false" displayname="Get session user.userID" hint="I return the userID for the session user">
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event" />		
		<cfscript>
			var userID = 0;
			userID = userFacade.getUser().getUserID();			
		</cfscript>
		<cfreturn userID />
	</cffunction> 

getUserData

public userTO getUserData( Event event )

I return a user identified by it's ID

Parameters:
Event event

Code:

	<cffunction name="getUserData" access="public" returntype="machii_info_sample.model.user.userTO" output="false" displayname="Get user By ID" hint="I return a user identified by it's ID">
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event." /> 
		<cfset var user = arguments.event.getArg("user") />		
		<cfreturn user.getUserTO() />
	</cffunction> 

getUserDataByEmail

public void getUserDataByEmail( Event event )

I return a user identified by it's email

Parameters:
Event event

Code:

	<cffunction name="getUserDataByEmail" access="public" returntype="void" output="false" displayname="Get user By ID" hint="I return a user identified by it's email">
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event." /> 
		<cfset var email = arguments.event.getArg("email") />		
		<cfreturn variables.userService.getUserDataByEmail(email, variables.dsn, variables.dbtype) />
	</cffunction> 

getUserDataById

public struct getUserDataById( Event event )

I return a user identified by it's ID

Parameters:
Event event

Code:

	<cffunction name="getUserDataById" access="public" returntype="struct" output="false" displayname="Get user By ID" hint="I return a user identified by it's ID">
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event." /> 
		<cfset var userID = arguments.event.getArg("userid") />		
		<cfreturn variables.userService.getUserDataByID(userID, variables.dsn, variables.dbtype) />
	</cffunction> 

getUsers

public array getUsers( Event event )

I return a query containing users.

Parameters:
Event event

Code:

	<cffunction name="getUsers" access="public" returntype="array" output="false" displayname="Get All Users" hint="I return a query containing users.">		
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event." /> 
		<cfscript>
			var username = arguments.event.getArg("username");
			var email = arguments.event.getArg("email");
			return variables.userService.getUsers(variables.dsn,username,email) ;
		</cfscript>		
	</cffunction> 

updateUser

public void updateUser( Event event )

I cause a user to be updated from the current event object.

Parameters:
Event event

Code:

	<cffunction name="updateUser" access="public" returntype="void" output="false" displayname="Update User" hint="I cause a user to be updated from the current event object.">
		<cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event" />		
		<cfscript>
			var user = arguments.event.getArg("user");		
			var errors = structNew();
			var userData = user.getUserTO();			
		</cfscript>
		<cftry>			
			<cfset variables.userService.updateUser(argumentcollection=userData, dsn=variables.dsn, dbtype=variables.dbtype) /> 			
			<cfset announceEvent("updateUser.success") />
		<cfcatch type="Database">
			<cfif findNoCase("duplicate",cfcatch.detail) >
				<cfscript>
					errors.usernameExists = "That username has been taken.";
					user.setErrors(errors);
					announceEvent("updateUser.usernameExists", arguments.event.getArgs());
				</cfscript>				
			<cfelse>
				<cfrethrow>
			</cfif>
		</cfcatch>
		</cftry>
	</cffunction>