Jasmo
Jasmo

Reputation: 828

Password protecting a page (node) in Drupal 7

I have Drupal 7 site and i need to add one page (node) that is password protected. Because this is one time thing, i'd prefer not to use those pretty complicated access control modules in Drupal.

Any ideas, how to restrict access for a node? Can i somehow use user roles for this? It would be perfect, but seems not to work out-of-box.

Upvotes: 0

Views: 2132

Answers (1)

Jasmo
Jasmo

Reputation: 828

function theme_preprocess_node( &$variables )
{
    $allowed_roles = array("administrator", "media");

    global $user;
    if($variables['nid'] == NODEID)
    {
        foreach($user->roles as $role)
        {
            if(in_array($role, $allowed_roles))
                return;
        }
        drupal_goto("user"); //  redirect to login
    }
}

I used solution above to handle this situation. It was best solution for me, although it's not very verbose for user :)

Upvotes: 1

Related Questions