• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Logging into a directory with application.cfc?

Contributor ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

Hello;
I currently upgraded a log in that I made to a directory in my web site. I used application.cfm to lock it down and it worked nice. I upgraded my code to work on application.cfc. and it seems to keep me out of the directory, but my log in code doesn't work now. Can anyone help me? I attached the code so you can see what is going on.

Right now, my log in won't allow me to log in. I don't understand why.

Can anyone help me out?
Thank you.

Phoenix
TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Feb 27, 2008 Feb 27, 2008
Ok, I did some reading and found a way to make the main application.cfc file work with the application.cfc file in the sub directory. I added a ProxyApplication.cfc with this code in it:

<cfcomponent extends="Application">
</cfcomponent>

and put this code in my application.cfc file in my sub directory:

<cfcomponent output="false" extends="ProxyApplication">

<cffunction name="onRequestStart" returnType="void" output="false">
</cffunction>


<cffunction name="onRequest" returntype="void">
<cfi...

Votes

Translate

Translate
LEGEND ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

What's on this page?
<cflocation url="../sitemanager.cfm" addtoken="yes">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

that is the log in page. (I attached it's code) I set it up so if your rejected, it sends you back to the log in and tells you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

What actually happens when you log in correctly?

Also, do you have an onRequestStart function?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

When I try and log in properly, it just kicks me back to the sitemanager.cfm file and that page isn't saying weather or not I am logged in or didn't provide the proper username and password.

No I do not have an onRequestStart function. Where would I put that and how would I write it? I don't think it is getting to the application.cfc file yet, I think my problem is on the login.cfm file.

Could this site being on an ip address be the problem?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

Sounds like your onSessionStart is running on every page request. Test this by having it output some text.

The onRequestStart function goes into your application.cfc. You write it the same way to write any other function.

By the way, it's a good practice to use the var keyword when setting varialbles inside a function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

I was wrong, I do have an onRequestStart I took the code out of cffunction session and put it into onRequestStart. It locks down my directory still, but it doesn't allow me to log in, I had it thrown an error, so it is reading the code. It boots me back to the sitemanager.cfm and adds the token to the url.

Would it make a difference if there are 2 application.cfc files in this site. one is in the main directory of the site, and this one I am working on is in the directory I am trying to lock down and log into. I know application.cfm didn't have a problem with this, but does .cfc see it differently?

Also, if I do a cfdump what would the variable be I would want to find out where the information is getting lost?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

<cfdump variable="#variables#"> will always give you something, usually more than you had hoped for. Putting "this is function whatever <br />" in each function might be more useful.

Two application.cfc files would probably make matters worse.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

how about if we make matters more simple? What would I use to make a directory in cf 8 locked down so you need a password to access it instead of an application.cfm inside the directory? Would I put it all on the main application.cfc file? if so How would that be written?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

I would put it in the application.cfc.

Look at your cgi variables. See if any of them help you see what directory you are in.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

It is my application.cfc file causing the problem. I have gotten that figured out. What I did wrong in the code on this file is beyond me. Now, it doesn't lock down the directory, nor does it log me in. and in my book it says this is how it is supposed to be written.

<cfcomponent output="false">
<cfset this.name="mySite">
<cfset this.sessionmanagement=true>


<cffunction name="onApplicationStart" returntype="void" output="false">
<cfset request.datasource = "myDB">
<cfset APPLICATION.companyname = "myCompany">
</cffunction>

<cffunction name="onRequestStart" output="false" returntype="void">
<cfif NOT IsDefined("SESSION.user.firstname")>
<cflocation url="../sitemanager.cfm" addtoken="yes">
</cfif>

<cfif IsDefined("COOKIE.CFID") AND IsDefined("COOKIE.CFTOKEN")>
<cfset cfid_local = COOKIE.CFID>
<cfset cftoken_local = COOKIE.CFTOKEN>

<cfcookie NAME="CFID" VALUE="#cfid_local#">
<cfcookie NAME="CFTOKEN" VALUE="#cftoken_local#">
</cfif>
</cffunction>
</cfcomponent>

Any ideas? It is this page causing the problems.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

Now I can see it.

The onRequestStart runs before any code in any .cfm template, including the template that accepts your login form. That means session.user.firstname never gets defined.

Your 1st post had this in the onSessionStart function. Hence my confusion.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

What do I do to fix it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

Add some logic for that directory you want to protect.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 26, 2008 Feb 26, 2008

Copy link to clipboard

Copied

How would I write that. Please forgive me, I am learning, don't know what logic to add, would that also solve the log in problem?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 27, 2008 Feb 27, 2008

Copy link to clipboard

Copied

LATEST
Ok, I did some reading and found a way to make the main application.cfc file work with the application.cfc file in the sub directory. I added a ProxyApplication.cfc with this code in it:

<cfcomponent extends="Application">
</cfcomponent>

and put this code in my application.cfc file in my sub directory:

<cfcomponent output="false" extends="ProxyApplication">

<cffunction name="onRequestStart" returnType="void" output="false">
</cffunction>


<cffunction name="onRequest" returntype="void">
<cfif NOT IsDefined("SESSION.user.firstname")>
<cflocation url="../sitemanager.cfm" addtoken="yes">
</cfif>

<cfif IsDefined("COOKIE.CFID") AND IsDefined("COOKIE.CFTOKEN")>
<cfset cfid_local = COOKIE.CFID>
<cfset cftoken_local = COOKIE.CFTOKEN>

<cfcookie NAME="CFID" VALUE="#cfid_local#">
<cfcookie NAME="CFTOKEN" VALUE="#cftoken_local#">
</cfif>
</cffunction>

<cffunction name="onRequestEnd" returnType="void" output="true">
</cffunction>

</cfcomponent>

Now it locks down my directory, BUT it still kicks me out when I log in properly. WHY? I don't understand why it is not reading this code properly. No errors, just won't let me log in.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation