Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Conditional display of login/logout/register links
I am heavily modifying the default vanilla theme and I need to know how to show a register link only if the user is a guest or a profile link only if the user is logged in, etc.
Essentially I want to make my own version of the "Guest Box" (the box that allows guests to sign in or register) in the header.
Any help would be greatly appreciated
Essentially I want to make my own version of the "Guest Box" (the box that allows guests to sign in or register) in the header.
Any help would be greatly appreciated
Tagged:
0
Comments
$Session = Gdn::Session(); if ($this->Menu) { $this->Menu->AddLink('Dashboard', T('Dashboard'), '/dashboard/settings', array('Garden.Settings.Manage')); // regarding this -- it checks for Garden.Settings.Manage permissions -- only admins have that, so only admins get to see this button $Authenticator = Gdn::Authenticator(); if ($Session->IsValid()) { //if the Session is VALID -- this is what you are interested in $Name = $Session->User->Name; $CountNotifications = $Session->User->CountNotifications; if (is_numeric($CountNotifications) && $CountNotifications > 0) $Name .= ' <span>'.$CountNotifications.'</span>'; $this->Menu->AddLink('User', $Name, '/profile/{UserID}/{Username}', array('Garden.SignIn.Allow'), array('class' => 'UserNotifications')); $this->Menu->AddLink('SignOut', T('Sign Out'), $Authenticator->SignOutUrl(), FALSE, array('class' => 'NonTab SignOut')); } else { // GUEST $Attribs = array(); if (C('Garden.SignIn.Popup') && strpos(Gdn::Request()->Url(), 'entry') === FALSE) $Attribs['class'] = 'SignInPopup'; $this->Menu->AddLink('Entry', T('Sign In'), $Authenticator->SignInUrl($this->SelfUrl), FALSE, array('class' => 'NonTab'), $Attribs); }
Let me know if something is unclear.
/cd
I also tried to print the signing link elsewhere using this syntax:
<?php echo Anchor(T('Sign In'), Gdn::Authenticator()->SignInUrl($this->_Sender->SelfUrl), 'class'.(SignInPopup() ? ' SignInPopup' : '')); ?>
..but the redirect URL doesn't show up when you sign in. What am I doing wrong and is there any easier way to print these links?
Thanks, cd
$this->Menu
entries. The list of chained available functions is inapplications/dashboard/modules/class.menumodule.php
I haven't tried but maybe this works
echo Anchor(T('Sign In'), Gdn::Authenticator()->SignInUrl($this->_Sender->SelfUrl), 'Button'.(SignInPopup() ? ' SignInPopup' : ''));
/cd
/cd
Yup I'm using the PHP file.
Any ideas?
/cd
<ul> <?php $Session = Gdn::Session(); if ($Session->IsValid()) { ?> <li class="accounts hello">Hello, <?php $Name = $Session->User->Name; $CountNotifications = $Session->User->CountNotifications; if (is_numeric($CountNotifications) && $CountNotifications > 0) $Name .= ' <span>'.$CountNotifications.'</span>'; echo Anchor(T($Name), '/profile/', 'class'); ?> <ul> <li><a href="/community/profile">Profile</a></li> <li><?php echo Anchor(T('Sign out'), Gdn::Authenticator()->SignOutUrl(), 'class'); ?></li> </ul> </li> <?php } else { ?> <li class="accounts"><?php echo Anchor(T('Sign In'), Gdn::Authenticator()->SignInUrl($this->_Sender->SelfUrl), 'class'.(SignInPopup() ? ' SignInPopup' : '')); ?> | <?php $Url = Gdn::Authenticator()->RegisterUrl($this->_Sender->SelfUrl); if(!empty($Url)) echo ' '.Anchor(T('Join'), $Url, 'class'); ?></li> <?php }; ?>
<div id="Body">
and this is what I get... http://yfrog.com/9fscreenshotflp which is the normal thing. Maybe you have a broken CSS or something that doesn't show it (try changing the theme?).Or am I misunderstanding the problem? For you the "Sign In" doesn't show up, right? Does the "Join" appear?
/cd
To be more specific, the 'target' variable in the url does not have a value
eg. "http://mysite.com/community/discussions/entry/signin?target="
If you do get redirected, there might be other things that you do in your theme, that breaks it.
/cd