define user vars in session
Hi all,
I am trying to set some session.user.* variables when user logs in and it works somewhat. When user first logs in it works fine but if session expires and user logs in again then it doesn't work. User would have to logout manulay in order for it to work again. I am using j2ee for session management.
I've also tried doing the user session set in the onSessionStart but that didn't work. Here is my code:
<cffunction name="OnRequestStart" >
<cfargument name = "request" required="true"/>
<cfif IsDefined("URL.logout")>
<cflogout>
<cflocation url="/index.cfm" addtoken="no">
</cfif>
<cflogin>
<cfif NOT IsDefined("cflogin")>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfif cflogin.name IS "" OR cflogin.password IS "">
<cfoutput>
<h2>You must enter text in both the User Name and Password fields.</h2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfquery name="loginQuery" dataSource="#Application.DNS#">
SELECT UserID, UserLevel, news, calendar, site, marketing, account, users
FROM Users
WHERE
UserID = '#cflogin.name#'
AND Password = '#cflogin.password#'
</cfquery>
<cfif loginQuery.UserLevel NEQ "">
<cfloginuser name="#cflogin.name#" Password = "#cflogin.password#" roles="#loginQuery.UserLevel#">
<cfscript>
session.user.news = loginQuery.news;
session.user.calendar = loginQuery.calendar;
session.user.account = loginQuery.account;
session.user.site = loginQuery.site;
session.user.marketing = loginQuery.marketing;
session.user.users = loginQuery.users;
</cfscript>
<cfelse>
<cfoutput>
<H2>Your login information is not valid.<br>
Please Try again</H2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
</cfif>
</cfif>
</cfif>
</cflogin>
</cffunction>
