Hi,

I've created a new content type called "deals" which can be created by registered users. In my template I've added a link to node/add/deals which is fine for registered users. However, anoymous users are directed to a Access Denied page. How can I create a link for visitors to create an account or login if they haven't already, or for the node/add/deals link to appear if they are logged in?

Thanks for any help.

Comments

pbarnett’s picture

I started using LoginToboggan, and have never looked back :-)

http://drupal.org/project/logintoboggan

Pete.

yelvington’s picture

global $user;
if ($user->uid) print("you are logged in");
else print("you are not logged in");

Anonymous user is always 0.

pbarnett’s picture

This would probably work -

global $user;

$dest = drupal_get_destination();
if ($user->uid < 1) {
  print "<div id=\"user-login-text\"><a href=\"/user/login?$dest\" \" title=\"Log in\">login</a> / <a href=\"/user/register?$dest\" \" title=\"Register\">register</a></div>";
}

Pete.

Jboo’s picture

Great, thanks Pete. I've managed to get what I needed with just this code, although the LoginToboggan module looks quite useful too.

Thanks again.

My new EasySnoozing, Nursing and BusinessEgghead websites on D7!

Vc Developer’s picture

Pete, how can I make this into a function to call from the template.php?

pbarnett’s picture

You could try something like -

<?php
function yourfunction() {
  global $user;
  $ret = '';
  $dest = drupal_get_destination();
  if ($user->uid < 1) {
    $ret =  "<div id=\"user-login-text\"><a href=\"/user/login?$dest\" \" title=\"Log in\">login</a> / <a href=\"/user/register?$dest\" \" title=\"Register\">register</a></div>";
  }
  return $ret;
}
?>

though you'd be better off using Drupal's Swiss Army switchblade of a link generator (see http://api.drupal.org/api/function/l/6)

If coding is like a box of chocolates, all I can say is that it's a shame most of the options are Coffee Cremes :-)

Pete.

Vc Developer’s picture

Thanks Pete!

...that's a good one! :-)