ColdFusion - Determine whether an authenticated user belongs to the specified role

IsUserInRole() - determine whether an authenticated user belongs to the specified role

IsUserInRole.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IsUserInRole function example: how to determine whether an authenticated user belongs to the specified role</title>
</head>

<body>
<h2 style="color:Crimson">IsUserInRole Function Example</h2>

<cfset UserRoles=GetUserRoles()>

<cfoutput>
 <cfif IsUserInRole("admin")>
        <b>Current user is in role</b>: admin
    <cfelseif IsUserInRole("superadmin")>
        <b>Current user is in role</b>: superadmin
 <cfelse>
     <b>Current user is not in roles: admin, superadmin</b>        
    </cfif>
</cfoutput>
</body>
</html>






More ColdFusion example