0

I realize that there are many ways and modules to accomplish this with, but this is the one particular way I need it and I'm having trouble finding a good solution. So here is what I'd like to achieve:

A custom block on a page with username and password fields. After entering the right combination (it'll be just one pair probably), the form would redirect the visitor to a content page that is unpublished.

Logged in visitors should not be Drupal users, nor should they go through a registration process. Certain people will know the right user/pass combo and only they should be able to access the protected page.

The Protected Pages module doesn't create a login block, password input only possible on the actual page that is protected.

I tought about creating a custom module with a form that would redirect after entering the right user/pass combo, but if the destination node is unpublished, it won't work anyway.

Do you have any good ideas for this one?

Thank you, Bálint

1 Answer 1

1

Giving users permission to view unpublished content could potentially be a security risk, and it's not (easily) possible to restrict it to just viewing a particular content type.

Why not publish the node, but only allow users with a certain role be able to view them using the Content Access module.

Then create a few accounts with this role, setting the usernames and passwords yourself.

Then just use the standard Drupal login form but then alter the redirect once logged in with hook_user_login:

function hook_user_login(&$edit, $account) {
    if (in_array('your_role', $account->roles)) {
        $edit['redirect'] = 'node/123';
    }
}

By creating the accounts this way it means you can use the main Drupal authentication system so reducing the amount of work that you need to do...

5
  • I probably should've mentioned this (will edit the description), logged in visitors should not be Drupal users, nor should they go through a registration process. Certain people will know the right user/pass combo and only they should be able to access the protected page. Commented Apr 8, 2014 at 13:11
  • Arr - that changes thing a bit!
    – Felix Eve
    Commented Apr 8, 2014 at 13:14
  • Sorry about that! Commented Apr 8, 2014 at 13:16
  • Updated my answer
    – Felix Eve
    Commented Apr 8, 2014 at 13:23
  • 1
    Whoa, that was simpler than I tought. I was so involved with finding a module or creating a custom solution that I haven't seen this one. Thank you! Commented Apr 8, 2014 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.