Link to home
Start Free TrialLog in
Avatar of loyaliser
loyaliserFlag for United States of America

asked on

cflogin example not working...

i am trying to get the first example in this link to work:

http://tinyurl.com/3rl6p

i have added code to application.cfm file and created the sample page securitytest.cfm.

problem is that when i test the securitytest page, all i get is this displayed:

Authentication data is missing.
Try to reload the page or contact the site administrator.

where am i supposed to login? running on IIS 5.1 w/ CF MX 6.1.

please advise on how to get this thing to work... thanks!
Avatar of sigmacon
sigmacon

Please post your code. The page you are referring to has lots of code on it, which part did you use?
Avatar of loyaliser

ASKER

i used the first 2 example code blocks:

Example: Application.cfm
and
Example: securitytest.cfm

thanks!
loyaliser...

have you tried to do some debugging in the form of <CFOUTPUT>   http://tinyurl.com/6k3ky   tags... and in btw each one, print all the variables... also, you can have <CFDUMP>  http://tinyurl.com/4o3g3  statements

<cfapplication name="Orders">

<cflogin>
  <cfif IsDefined( "cflogin" )>

   <CFOUTPUT><CFDUMP var = #cflogin#></CFOUTPUT>

    <cfif cflogin.name eq "admin">
      <cfset roles = "user,admin">
    <cfelse>
        <cfset roles = "user">
      </cfif>

   <CFOUTPUT> #cflogin.name#   #cflogin.password# </CFOUTPUT>
   
    <cfloginuser name = "#cflogin.name#" password = "#cflogin.password#"
      roles = "#roles#" />
  <cfelse>
    <!--- this should never happen --->
    <h4>Authentication data is missing.</h4>
      Try to reload the page or contact the site administrator.
  <cfabort>
  </cfif>
</cflogin>



somethign along those lines...
I would try a simpler example such as :

http://cfhub.com/examples/secure/

to get you started.
the code is fine... i just don't know how to get it to work. how and where does cflogin get populated w/ the username and password?

do i have to set something on the server so the user is prompted for login information?
The first two example code blocks rely on basic web server authentication. You have to enable that in whichever webserver you are using, otherwise, no authentication data is available ... which is what the error message states.
>>do i have to set something on the server so the user is prompted for login information?

Not in the administrator - but yes in your code.  Usually this is done in the application.cfm file.

>>how and where does cflogin get populated w/ the username and password?

You have to do this in your code yourself.


I think you either need to read the rest of the example you are using (although it basically is showwing snippets of code on how the theory works - it is not really a good tutorial to follow nor is it helpful in learning) or you should look at a tutorial like the other one I posted.

I would guess - since you did not post code - that you only have the snippets shown in the first two example sections of that document - these are incomplete and only shown to show how the framework works.  

The actual methods to log people in are in the longer examples later in that same page (loginform.cfm)

sigmacon:

exactly... how do i enable web server authentication on IIS 5.1 to get this code working?

thanks!
It is not a setting in IIS.

The reason the code is commented "This should never happen" is that your application.cfm file should catch that a user is not logged in and then present them with a login form.

You should try using the application.cfm example page further down in the url you posted.

Here is the code:
<cfapplication name="Orders" sessionmanagement="Yes">

<cfif IsDefined("Form.logout")>
  <cflogout>
</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="CompanyInfo">
      SELECT UserID, Roles
      FROM LoginInfo
      WHERE
        UserID = '#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="loginform.cfm">
        <cfabort>
      </cfif>
    </cfif>  
  </cfif>
</cflogin>


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


Note how it includes a login form so that in the even that authentication data is missing the user is prompted to enter that data and authenticate.
ASKER CERTIFIED SOLUTION
Avatar of sigmacon
sigmacon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial