Skip to main content
Inspiring
July 12, 2023
Question

Show default landing page after login and show loginpage.cfm after user logs out.

  • July 12, 2023
  • 0 replies
  • 155 views

Hi ,

Please let me know how to display  a default .cfm file after user logs in to the application . And user should be taken to  the login page when he/she logs out. Please let me know how to write logic for this. My application.cfc is ,

 

<cfcomponent>

<cfset This.name = "USERS">
<cfset This.Sessionmanagement="True">
<cfset This.loginstorage="session">
<cfset This.sessiontimeout="#createtimespan(0,0,10,0)#">
<cfset This.applicationtimeout="#createtimespan(5,0,0,0)#">

<cffunction name="onApplicationStart"  returntype="boolean">
    <cfreturn True>
</cffunction>

<cffunction name="onSessionStart">

</cffunction>

<cffunction name="OnSessionEnd">
    <cfargument name = "SessionScope" required=true/>
    <cfargument name = "ApplicationScope" required=true/>
</cffunction>

<cffunction name="OnRequestStart">
    <cfargument name = "request" required="true"/>

<cfif IsDefined("Form.logout")>
    <cflogout>
</cfif>

<cflogin>
    <cfif NOT IsDefined("cflogin")>
        <cfinclude template="Login.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="Login.cfm">
            <cfabort>
        <cfelse>
            <cfquery name="loginQuery" dataSource="tdweb">
                SELECT username,password,roles
                FROM LoginInfo
                WHERE
                username = '#cflogin.name#'
                AND password = '#cflogin.password#'
            </cfquery>

        <cfif loginQuery.roles NEQ "">
            <cfloginuser name="#cflogin.name#" Password = "#cflogin.password#"
            roles="#loginQuery.roles#">
        <cfelse>
            <cfoutput>
                <H2>Your login information is not valid.<br>
                Please Try again</H2>
            </cfoutput>
            <CFINCLUDE TEMPLATE="Login.cfm">
            <cfabort>
        </cfif>
    </cfif>
</cfif>
</cflogin>

<cfif GetAuthUser() NEQ "">
    <cfoutput>
        <form action="UserList.cfm" method="Post">
            <input type="submit" Name="Logout" value="Logout">
        </form>
    </cfoutput>
</cfif>
</cffunction>

<cffunction name="onRequestEnd">
    <cfargument type="String" name="targetPage" required=true/>

</cffunction>

<cffunction name="onApplicationEnd">
    <cfargument name="ApplicationScope" required=true/>

</cffunction>
</cfcomponent>
 
And my login.cfm is ,
<H2>Please Log In</H2>
<cfoutput>
    <form action="#CGI.script_name#?#CGI.query_string#" method="Post">
        <table>
            <tr>
                <td>user name:</td>
                <td><input type="text" name="j_username"></td>
            </tr>
            <tr>
                <td>password:</td>
                <td><input type="password" name="j_password"></td>
            </tr>
        </table>
        <br>
        <input type="submit" value="Log In">
    </form>
</cfoutput>
 

Please help, thanks

 

 

    This topic has been closed for replies.