Get the logged in user and see if they have a role

  • Created: Feb 16, 2012
  • Author: David Higginbotham
  • Title: Java/Web Developer
  • Company: DRH Consulting, L.L.C.
  • Tags: users 

Description

This code will retrieve the user id of the logged in user. It will then check to see if the user has the Cms Administrator role. I used this logic with a custom field so I could control the ability to edit.

Code

${esc.hash}set (${esc.dollar}foundUser = ${esc.dollar}cmsuser.getUserByUserId(${esc.dollar}session.getAttribute("USER_ID"))) 

${esc.hash}if(${esc.dollar}foundUser) 
    ${esc.hash}if(${esc.dollar}cmsuser.isUserRole(${esc.dollar}foundUser, "CMS Administrator"))
        yes
    ${esc.hash}end
${esc.hash}end