Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modular Access

Login function with CF

Modular Access

by  webmigit  Posted    (Edited  )
I've recently been part of a cf mailing list and someone asked a question I hear all the time...

"How do I do modular access so that some users can access certain parts of a site while other users cannot?"

[red]mGranted[/red] is going to be our access flag. We're going to assume that [red]AdminFlag[/red] is our field that contains whether or not the user is a global admin (for instance, you might assign intranet users certain responsibilities but you would want certain people to have access to everything, like yourself so that you can stay on top of features.

We'll call the variable that has the users access levels [red]AccessLevels[/red].

This code works on the basis of modular controls and folder names.. IE the conrol for access level 1 is in the folder m1, level 2 = m2, level 13 = m13.

A user with access to levels 21.2.13 would be able to access those levels and they'd be in folders m21, m2, m13.

Code:
<cfset mgranted = 0>
<CFIF AdminFlag eq 1>
 <cfset mGranted = 1>
<CFELSE>
 <cfset nlevel = ListGetAt(cgi.script_Name,listlen(cgi.script_name,"/")-1,"/")>
 <CFIF listFind(AccessLevels,Right(nLevel,len(nLevel)-1)>
   <cfset mgranted = 1>
 </CFIF>
</CFIF>

And that would parse out the folder name that contained the level. You check for mGranted to equal 1.

Now code to configure links to custom controls...

Code:
<cfif not isDefined("Application.ArrControls")>
 <cfset Application.ArrControls = ArrayNew(2)>
 <cfset Application.ArrControls[1][1] = "<A...>Link for Access Level 1</A>">
 <cfset Application.ArrControls[1][2] = "<A...>Link for Access Level 1</A>">
 <cfset Application.ArrControls[1][3] = "<A...>Link for Access Level 1</A>">
 <cfset Application.ArrControls[2][1] = "<A...>Link for Access Level 2</A>">
 <cfset Application.ArrControls[3][1] = "<A...>Link for Access Level 3</A>">
 <cfset Application.ArrControls[3][2] = "<A...>Link for Access Level 3</A>">
 <cfset Application.ArrControls[4][1] = "<A...>Link for Access Level 4</A>">
 <cfset Application.ArrControls[4][2] = "<A...>Link for Access Level 4</A>">
</cfif>
<cfset AppControls = Application.ArrControls>

Now the code to get the right links for the right users.

Code:
<cfoutput><cfloop from="1" to="#ArrayLen(AppControls)#" index="a1">
 <cfif (ListFind(AccessLevels,a1) or Admin_Identifier_Field eq 1) and
ArrayLen(AppControls[a1])>
   &middot; <cfloop from="1" to="#ArrayLen(AppControls[a1])#" index="a2">
     #AppControls[a1][a2]# &middot;
   </cfloop><br>
 </cfif>
</cfloop></cfoutput>
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top