I use the login script from this site for many separate areas of my websites. It's a great script, but I've always wanted some form of admin area to easily add, modify, and delete users. This tutorial uses six files that create a small admin area which allows someone to add, change password, and delete users. If you are using the original login script and haven't changed the table name or field names, then the only thing you need to change is your DSN on the last file, variables.cfm.
The original login area shouldn't be hard to find, it is always the highest viewed tutorial. It is located at http://tutorial8.easycfm.com/
<!--- This is the index.cfm file --->
<cfinclude template="variables.cfm">
<!--- Include the variables file so one change updates all templates --->
<!--- Get all records from the database that match this users credentials --->
<cfquery name="qList" datasource="#dsn#">
SELECT *
FROM #tablename#
</cfquery>
<html>
<head>
<title>Admin</title>
</head>
<body>
<!--- Simple HTML form at the top to insert a user into the database --->
<form method="POST" action="adduser.cfm">
<p align="center">
<font size="2" face="Century Gothic">add user:</font><br>
<input type="text" name="user_name" size="20">
</p>
<p align="center">
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2">
</p>
</form>
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="35%">
<tr>
<td width="25%" bgcolor="#000000" align="center">
<font color="#FFFFFF" face="Century Gothic" size="2">User</font>
</td>
<td width="25%" bgcolor="#000000" align="center">
<font color="#FFFFFF" face="Century Gothic" size="2">Details</font>
</td>
<td width="25%" bgcolor="#000000" align="center">
<font color="#FFFFFF" face="Century Gothic" size="2">Delete User</font>
</td>
</tr>
<cfoutput query="qList">
<tr>
<td width="25%">
<font face="Century Gothic" size="2"> #user_name#</font>
</td>
<td width="25%" align="center">
<a href="user_info.cfm?user_name=#user_name#"><font face="Century Gothic" size="2">info</font></a>
</td>
<td width="25%" align="center">
<a href="deluser.cfm?user_name=#user_name#"><font face="Century Gothic" size="2">del</font></a>
</td>
<!--- List all the current users and provide two options for each, info and del --->
</tr>
</cfoutput>
</table>
</center>
</body>
</html>
<!--- NEW FILE: adduser.cfm --->
<!--- This file receives a user_name from the HTML form in the index.cfm then ADDS it to the db and goes back to the index --->
<!--- Since there is nothing on this file, all you'll see is the index.cfm page blink and then the new username appears --->
<cfinclude template="variables.cfm">
<cfquery name="addusers" datasource="#dsn#">
INSERT INTO #tablename# (user_name )
VALUES ('#user_name#')
</cfquery>
<CFLOCATION URL="index.cfm">
<!--- NEW FILE: deluser.cfm --->
<!--- This file receives a user_name from the HTML form in the index.cfm then DELETES it from the db and goes back to the index --->
<!--- Since there is nothing on this file as well, all you'll see is the index.cfm page blink and then the new username disappear --->
<cfinclude template="variables.cfm">
<cfquery name="delusers" datasource="#dsn#">
DELETE FROM #tablename# WHERE user_name = '#url.user_name#'
</cfquery>
<CFLOCATION URL="index.cfm">
<!--- NEW FILE: user_info.cfm --->
<!--- This file receives a user_name from the link on the index.cfm then QUERIES info from the db --->
<cfinclude template="variables.cfm">
<cfquery name="user_info" datasource="#dsn#">
select *
from #tablename#
where user_name = '#url.user_name#'
</cfquery>
<html>
<head>
<title>Admin</title>
</head>
<body>
<form method="POST" action="user_info_update.cfm?user_name=<cfoutput>#user_info.user_name#</cfoutput>">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="40%">
<!--- The form fields are populated from the query and then sent to the next file which actually updates the database with the changes--->
<tr>
<td width="47%" align="right">user:</td>
<td width="4%"> </td>
<td width="49%">
<input type="text" name="user_name" size="20" value="<cfoutput>#trim(user_info.user_name)#</cfoutput>">
</td>
</tr>
<tr>
<td width="47%" align="right">pass:</td>
<td width="4%"> </td>
<td width="49%">
<input type="text" name="user_pass" size="20" value="<cfoutput>#trim(user_info.user_pass)#</cfoutput>">
</td>
</tr>
</table>
<br>
<p align="center">
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2">
</p>
</form>
</body>
</html>
<!--- NEW FILE: user_info_update.cfm --->
<!--- This file receives the update info from user_info.cfm then UPDATES the db and goes back to the index --->
<CFSET user_name = form.user_name>
<CFSET user_pass = form.user_pass>
<cfinclude template="variables.cfm">
<cfquery
name="user_info" datasource="#dsn#">
UPDATE #tablename#
SET
user_pass='#user_pass#'
where user_name = '#url.user_name#'
</cfquery>
<CFLOCATION URL="index.cfm">
<!--- NEW FILE: variables.cfm --->
<!--- If you are using the original login script without any changes all you have to change is your DSN in this file. --->
<CFSET dsn = "[your-datasource]">
<CFSET tablename = "tblAdmins">
Date added: Mon. March 29, 2004
Posted by: Rhino | Views: 12338 | Tested Platforms: CF5 | Difficulty: Intermediate
Full Applications
 |
Form with 2 Submit Buttons
An easy way to have a form with 2 or more submit buttons where each one does a different thing. One can count a rows in a DB, then next can actually submit the query. Possibilities are limitless. - Date added: Mon. October 9, 2006
Enter-Update same form
I hate creating duplicate forms where one is for entry and an identical one is for udpating. This code lets you use one form for both purposes. - Date added: Wed. April 7, 2004
Use checkboxes on update pages
Do you have an update page and want to use checkboxes on the page? This tutorial will go over the two steps needed. - Date added: Wed. March 31, 2004
Form processor with individual link email
This tutorial shows how to process a form and generate a random string that is put on the end of a link. When the user clicks the link it goes to their personal page. - Date added: Wed. March 31, 2004
Website Monitor
Do you have a website that you'd like to monitor but would rather not pay outrageous fees to some company? This simple script will monitor uptime for you website. It is the barebones version and can be easily modified into something highly useful. - Date added: Wed. March 24, 2004
· Column View Output
· Auto Event Emailer
· IP checker
· Count Down
|
Security
That's really kool but what stops people from simply typing in deluser.cfm?user=loui567
You need an if statement in there that makes sure the user is logged in or is an admin.
Posted by: louis
Posted on: 02/12/2007 11:54 PM
|
|