Skip to main content
March 3, 2011
Question

content not displaying.

  • March 3, 2011
  • 1 reply
  • 696 views

I built a login form and put an Application.cfc file in the folder i want to restrict and it's not displaying the simple text i put in the index.cfm for testing purposes.

======= Application.cfc code (in folder name "admin_section")==========

<cfcomponent>

  <cffunction name="onRequest">
    <cflogin>
      <cfif IsDefined("FORM.Login_btn")>
        <cfquery name="qLogin" datasource="poll">
        SELECT UserLogin, UserPassword, UserRoleID
        FROM Users
        WHERE UserLogin = <cfqueryparam value="#FORM.UserName#" cfsqltype="cf_sql_varchar">
        AND UserPassword = <cfqueryparam value="#FORM.Password#" cfsqltype="cf_sql_varchar">
        </cfquery>
        <cfif FORM.username IS "#qLogin.UserLogin#" AND FORM.password IS "#qLogin.UserPassword#">
          <cfloginuser name="#FORM.username#"
                       password="#FORM.password#"
                       roles="#qLogin.UserRoleID#">
        <cfelse>
        <cfset request.errorMsg = "Incorrect login; please try again">
          <cfinclude template="../login/login.cfm">
            <cfreturn>   
        </cfif>
      <cfelse>
        <cfinclude template="../login/login.cfm">
          <cfreturn>
      </cfif>
        </cflogin>
  </cffunction>
 
</cfcomponent>

======= Application.cfc End =======

====== Login Form (in folder name "Login" ====

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<cfform action="../admin_section/" method="post">
  <table width="250">
  <tr align="center">
    <td colspan="2">
      <cfif IsDefined('Request.errorMsg')>
        <cfoutput>#Request.errorMsg#</cfoutput>
      <cfelse>
        Please Log in.
      </cfif>
    </td>
  </tr>
    <tr>
      <td>
        <font size="-1">User Name:</font>
      </td>
      <td>
        <cfinput type="text"
                 name="UserName"
                 required="yes"
                 message="- You must enter a user name!">
      </td>
    </tr>
    <tr>
      <td>
        <font size="-1">Password:</font>
      </td>
      <td>
        <cfinput type="password"
                 name="Password"
                 required="yes"
                 message="- You must enter a password!">
      </td>
    </tr>
    <tr>
      <td> </td>
      <td>
        <cfinput type="submit" name="login_btn" value="Log me in!" >
      </td>
    </tr>
  </table>
</cfform>
</body>
</html>

It takes me to the page, but nothing displays. Again i have simple text for testing purposes.

Any help would be great.

    This topic has been closed for replies.

    1 reply

    Community Expert
    March 4, 2011

    Your problem is that you're using onRequest, which replaces the default page rendering event. There are two ways you could fix this.

    1. Use onRequestStart instead. This will happen before your page is processed, rather than instead of your page being processed. This is the approach I'd recommend.

    2. Add code at the bottom of your onRequest to include the page to be processed. You'd identify this page by using the targetPage argument and including it:

    <cffunction name="onRequest">

         <cfargument name="targetPage" required="true">

         ...

         <cfinclude template="#targetPage#">

    </cffunction>

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC
    March 4, 2011

    I used the OnRequestStart and it shows the page just fine. Now i got one more problem. When i enter the incorrect username and/or password it gives me the error message (which is what i want) and redirects me  back to the login form, but it will also show the "index.cfm" page in the admin section right under the login form. Any idea why that happened?

    Thanks

    --- Update ---

    I changed the <cfreturn> with <cfabort> and it fixed my new problem.

    Thanks for your help yet again Dave.

    March 8, 2011

    I have found a new problem when i was trying to make sure all 3 roles in the D. They all work just fine, but when i logout (using the cflogout) from the admin role and then log in as a lower role i can see everything the admin can see. I thought the cflogout fully logs people out, but not this time and i'm not sure why. It does fully logout when i close the brower, but thats not what i want someone to do. Any ideas why? My Appilcation.cfc code hasn't changed other then changing the OnRequest to OnRequestStart.