Karstengp said the following on 10/03/2009 09:09 PM:
> I'm am a newbie. I am going to be implementing Mach-ii on one of our
> major websites and I am currently working on the login features. I
> have setup a LoginPlugin along with a SessionFacade with help from the
> wiki and forums. I want to make sure that I am using my listeners
> correctly, if I read the wiki tutorials correctly, the listeners
> should not have any logic in them, they are just used to facilitate
> the system with directions to the DAO and Gateway.
>
I think the key phrase is "not have business logic" (hence the
recommendation to have a service layer for this). You're absolutely
fine to have announceEvent() calls -- anything framework specific -- as
the listener is part of the controller layer of your application
(Mach-II itself is a controller -- listeners are user extended
extensions of the framework itself).
> I setup an authentication function in the gateway which provides code
> and user feedback then depending on if they were successful I have the
> listener announce the home page or back to the login page. This is
> what I have so far. Is this correct or should I move my if statement
> out of the listener, and where to?
>
> Thanks for any help...
>
> == mach-ii.xml ==
> <event-handler event="loginPersonnel" access="public">
> <event-mapping event="loginSucceeded" mapping="adminHome"
> redirect="true" />
> <event-mapping event="loginFailed" mapping="login" redirect="true" />
> <notify listener="myagrilifeListener" method="authenticatePersonnel" /
>
> </event-handler>
>
Don't know where you saw "redirect="true" on event-mappings, however
this does not exist in the framework. If you found it on the wiki (it
may be mentioned as a new feature in some comments), let us know so it
can be removed.
See more below on what on how to do a redirect.
>
> == Listener ==
> <cffunction name="authenticatePersonnel" access="public"
> output="false" returntype="void">
> <cfargument name="event" type="MachII.framework.Event"
> required="true" />
> <cfset variables.results =
> variables.myagrilifeGateway.authenticatePersonnel
> (uin=arguments.event.getArg("uservalue"),
> authentication=arguments.event.getArg("password") ) />
> <cfif variables.results.ResultCode EQ 200>
> <cfset exitEvent = "loginSucceeded" />
> <cfset getProperty("sessionFacade").setLoginStatus(true) />
> <cfset getProperty("sessionFacade").setUserID
> (variables.results.UserID) />
> <cfelse>
> <cfset exitEvent = "loginFailed" />
> <cfset arguments.event.setArg("ResultMessages",
> variables.results.ResultMessages) />
> <cfset arguments.event.setArg("ResultCode",
> variables.results.ResultCode) />
> </cfif>
> <cfset announceEvent(exitEvent, arguments.event.getArgs()) />
> </cffunction>
>
If you're developing on M2 1.8 (which you probably should as the release
candidate release is imminent), you can use the use redirectEvent()
method. Also, you're need to var scope your "results" return --
otherwise it will be in the global variables scope of your CFC. This
will cause thread issue -- causing one person's results to leak into
another person's results. I highly suggest you read the CFCs: A Primer
series on the wiki (especially part 3 which talks about var scoping):
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/CFCPrimerPart1
Here's some modified code:
<cffunction name="authenticatePersonnel" access="public" output="false"
returntype="void">
<cfargument name="event" type="MachII.framework.Event" required="true"
/>
<cfset var results =
variables.myagrilifeGateway.authenticatePersonnel(XXXXXX) />
<cfif results.ResultCode EQ 200>
<cfset getProperty("sessionFacade").setLoginStatus(true) />
<cfset getProperty("sessionFacade").setUserID(results.UserID) />
<cfset redirectEvent("loginSucceded") />
<cfelse>
<cfset
arguments.event.setArg("ResultMessages",results.ResultMessages) />
<cfset arguments.event.setArg("ResultCode",results.ResultCode)
/>
<cfset announceEvent("loginFailed", arguments.event.getArgs())
/>
</cfif>
</cffunction>
Info on all the redirectEvent() method options are here (because you can
do persists with it):
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/MachII1.8Redirect
Hth,
.Peter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
SVN: http://greatbiztoolsllc.svn.cvsdude.com/mach-ii/
Wiki / Documentation / Tickets:
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/
-~----------~----~----~----~------~----~------~--~---