userGateway

Package: machii_info_sample.model.user
I am a data gateway to users
Method Summary
public userGateway init(string dsn)

I initialize the user gateway.

public query getUserByUsernamePassword(string username, string password)

I return a query of the user with the matching username/password.

public query getUsers([string username=""], [string email=""])

I return a query containing users

Method Detail
getUserByUsernamePassword

public query getUserByUsernamePassword( string username, string password )

I return a query of the user with the matching username/password.

Parameters:
string username
string password

Code:

	<cffunction name="getUserByUsernamePassword" access="public" returntype="query" output="false" displayname="getUserByUsernamePassword" hint="I return a query of the user with the matching username/password.">
		<cfargument name="username" type="string" required="true" />						
		<cfargument name="password" type="string" required="true" />
		<cfset var userSelect = 0 />
		<cfquery  name="userSelect" datasource="#variables.dsn#">
			SELECT *
			FROM users
			WHERE username = '#trim(arguments.username)#' and password = '#trim(arguments.password)#'
		</cfquery>
		<cfreturn userSelect />
	</cffunction> 

getUsers

public query getUsers( [string username=""], [string email=""] )

I return a query containing users

Parameters:
[string username=""]
[string email=""]

Code:

	<cffunction name="getUsers" access="public" returntype="query" output="false" displayname="Find All" hint="I return a query containing users">
		<cfargument name="username" type="string" required="false" default="" hint="filter users by"/>
		<cfargument name="email" type="string" required="false" default="" hint="filter users by"/>
		<cfset var userSelect = 0 />
		<cfquery  name="userSelect" datasource="#variables.dsn#">
			SELECT *
			FROM	users
			WHERE 1=1 
			<cfif len(arguments.username)>
				AND username LIKE '#trim(arguments.username)#%'
			</cfif>
			<cfif len(arguments.email)>
				AND email LIKE '#trim(arguments.email)#%'
			</cfif>
			ORDER BY lastName, firstName			
		</cfquery>
		<cfreturn userSelect />
	</cffunction> 

init

public userGateway init( string dsn )

I initialize the user gateway.

Parameters:
string dsn

Code:

	<cffunction name="init" access="public" returntype="machii_info_sample.model.user.userGateway" output="false" displayname="Article Gateway Constructor" hint="I initialize the user gateway.">
		<cfargument name="dsn" type="string" required="yes" displayname="Data Source Name" hint="I am the data source to use for persistence." />	
		<cfset variables.dsn = arguments.dsn />
		<cfreturn this />
	</cffunction>