Copy link to clipboard
Copied
Hi, all. I'm trying to make use of the client name that's signed in. You will find the application.cfm and loginform.cfm files below. What I can't figure out is how to use the exact user that is logged in. The usernames are in a database, and each user has their own directory (to store their pictures in). I don't know how to call up the user name that's logged in. Specifically, I want the user to see only those images that exist in his folder (and are associated with them in the DB). How do I do this?
Thank you, and thank you for putting up with a noob.
application.cfm
<!---from http://www.adobe.com/livedocs/coldfusion/6.1/htmldocs/appsec27.htm--->
<cfapplication name="Orders" clientmanagement="yes" sessionmanagement="Yes" loginStorage="Session">
<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="omfoto">
SELECT UserLogin, Role
FROM People
WHERE
UserLogin = '#cflogin.name#'
AND UserPassword = '#cflogin.password#'
</cfquery>
<cfif loginQuery.Role NEQ "">
<cfloginuser name="#cflogin.name#" Password = "#cflogin.password#"
roles="#loginQuery.Role#">
<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 "">
<cflocation url="securitytest.cfm">
</cfif>
--->
<cfif GetAuthUser() NEQ "">
<cfoutput>
<form action="../index.cfm" method="Post">
<input type="submit" Name="Logout" value="Logout">
</form>
</cfoutput>
</cfif>
loginform.cfm
<H2>Please Log In</H2>
<cfoutput>
<!--- CGI.script_name/CGI.query_string are used to recreate the URL used to call the requested page
takes you to loginform.cfm--->
<form action="#CGI.script_name#?#CGI.query_string#" method="Post">
<table>
<tr>
<td>username:</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>
Copy link to clipboard
Copied
You could try storing part of path to the user's directory in the people table. Retrieve this when performing the authentication and then add it to the session scope so it is available in future page requests without having to re-query the database.
You could also consider just putting all the files in one directory and renaming them. You would then have to store the new file name and user id together in a new database table.
Copy link to clipboard
Copied
OK....How would I go about adding it to the session scope?
And thank you for your reply.
R
P.S. As for the advice of having all the images in one directory: I appreciate the advice, but it took me too long to set up the upload process as it is, so, I'll stick to what I have. I'm storing the image name, location, url, and client in the DB, so retrieval should be easy...
Copy link to clipboard
Copied
<cfscript>
session.varName = xyz;
</cfscript>
The doc on sessions can explain it better then me:
Spending a few hours with the docs will be time well spent.
Regarding you application, what are you going to do when the user uploads a file with the same name later?