Log Out Function
Permalink 3 users found helpful
Hi
I would like to place a "Sign Out" section into the footer of a C5 site I have built, does anyone know how to do this before I start drinking strong coffee and holding my eyes open with match sticks trying to do it myself?
Sorry but not a particularly great php coder but if anyone can point me in the right direction that would be awesome.
Thanks in advance
I would like to place a "Sign Out" section into the footer of a C5 site I have built, does anyone know how to do this before I start drinking strong coffee and holding my eyes open with match sticks trying to do it myself?
Sorry but not a particularly great php coder but if anyone can point me in the right direction that would be awesome.
Thanks in advance
<?php $u = new User(); if($u->isLoggedIn()) { ?> <a href="<?=View::url('/login','logout');?>">Logout</a> <?php }else{ ?> <a href="<?=View::url('/login','login');?>">Login</a> <?php } ?>
I copied that from what Tony suggested earlier...
And I agree with his method.
You don't want to logout while you are editing the particular page.
And I agree with his method.
You don't want to logout while you are editing the particular page.
Hi katz515
Perfect, absolutely spot on with what i was after, many thanks for your time and effort, very much appreciated.
Perfect, absolutely spot on with what i was after, many thanks for your time and effort, very much appreciated.
Ok, I'm seeing what you're doing with !$u->isRegistered() now. But I'm not sure you'd want to show a login link if the page is in edit mode. To be in edit mode the user must be logged in first, so in that case, if you don't want to show a logout link, you shouldn't show anything. Does that make sense?
So maybe something like this:
I think that should do it. That just seems a bit easier to read to me semantically.
So maybe something like this:
<?php $u = new User(); if($u->isLoggedIn() && !$c->isEditMode()) { ?> <a href="<?=View::url('/login','logout');?>">Logout</a> <?php }elseif(!$u->isLoggedIn()){ ?> <a href="<?=View::url('/login','login');?>">Login</a> <?php } ?>
I think that should do it. That just seems a bit easier to read to me semantically.
you just removed the exclamation mark and swapped the code..??
It looks like one shows the login if the user is guest, or if the page is in edit mode. The other just checks if they're logged in, but doesn't check for edit mode.
It's close to the same, but I was a bit confused at first glance on how he was using isRegistered() to basically check if the person is logged in. See my new comment above.
$cp = new Permissions($c);
if(!$cp->canWrite() && !$cp->canAddSubContent()){
}?>
the edit bar isn't up so we can display the link, otherwise we don't want to display it without an explicit logout through the toolbar.
This code is used in concrete5 themes to drop the body down so images aren't pushed down by the toolbar like so:
if(!$cp->canWrite() && !$cp->canAddSubContent()){
}?>
the edit bar isn't up so we can display the link, otherwise we don't want to display it without an explicit logout through the toolbar.
This code is used in concrete5 themes to drop the body down so images aren't pushed down by the toolbar like so:
$cp = new Permissions($c); if($cp->canWrite() && $cp->canAddSubContent()){ echo('<style type="text/css">body{background-position:0px 50px;}</style>'); }?>
I get a parse error on the if isRegistered line when using Katz's code.
Parse error: syntax error, unexpected T_STRING
Am I missing something? I placed in footer.php.
Thanks,
-mark
Parse error: syntax error, unexpected T_STRING
Am I missing something? I placed in footer.php.
Thanks,
-mark
Hi all,
I tried this code but for some reason it didn't seem to work. If I clicked on the Log Out link it didn't - log me out I mean!
I altered the code slightly and now it works great.
The code I used is:
Hope this helps.
Tony.
I tried this code but for some reason it didn't seem to work. If I clicked on the Log Out link it didn't - log me out I mean!
I altered the code slightly and now it works great.
The code I used is:
Hope this helps.
Tony.
Thanks Tony, your modification works great !
-mark
-mark
Hey I'd like if the user after login forwardss to a different page than the one you log onto. How do I do it?
login.php?rcID=<?$c->getCollectionID();?>
When you login it will return to the collectionID of the page that forwarded them to the login singlepage.
When you login it will return to the collectionID of the page that forwarded them to the login singlepage.
hey but I want this to be a completely different page. Not where you came from.
Where do I put the code that I get from you? I'm not so good in PHP, sorry!
Where do I put the code that I get from you? I'm not so good in PHP, sorry!
Franz kindly sent me a hack which I've teste and it works fine, give it a go, heres what he sent me,
1. Get the cID of the page you'd like to forward to. So, if it's a newly created page named "Congratulations" with a cID of 200 (the cID parameter in the URL that shows up when you edit the page) then that's the number you care about.
2. Make a directory named login in the root blocks directory. Copy packages/login/blocks/login/view.php to this new directory.
3. Change this line:
<? if($returnToSamePage ){ ?>
<input type="hidden" name="rcID" id="rcID"
value="<?=$c->getCollectionID(); ?>" />
<? } ?>
in the template to
<? if($returnToSamePage ){ ?>
<input type="hidden" name="rcID" id="rcID" value="200" /> <? } ?> (or whatever the cID is) Now, you've modified the login block so that, regardless of what page it's currently on, it will forward to the congratulations page. This is a hack, but it shouldn't fork any core concrete stuff or anything, and it should work.
Hope this helps.
1. Get the cID of the page you'd like to forward to. So, if it's a newly created page named "Congratulations" with a cID of 200 (the cID parameter in the URL that shows up when you edit the page) then that's the number you care about.
2. Make a directory named login in the root blocks directory. Copy packages/login/blocks/login/view.php to this new directory.
3. Change this line:
<? if($returnToSamePage ){ ?>
<input type="hidden" name="rcID" id="rcID"
value="<?=$c->getCollectionID(); ?>" />
<? } ?>
in the template to
<? if($returnToSamePage ){ ?>
<input type="hidden" name="rcID" id="rcID" value="200" /> <? } ?> (or whatever the cID is) Now, you've modified the login block so that, regardless of what page it's currently on, it will forward to the congratulations page. This is a hack, but it shouldn't fork any core concrete stuff or anything, and it should work.
Hope this helps.
Hi,
I'm suggesting yet another variation. (see code below)
There are really three states or conditions to LogIn/LogOut.
#1 Not Logged In, - show Login
#2 Logged-In, but Not in Edit Mode - show Logout
#3 Logged In and in Edit Mode - show message to Exit Edit Mode.
The issue I had with the original example was that during State#3, the Login was shown again. This was confusing.
Hope this helps,
Dennis
--------------------------------------------------------
<?php
$u = new User();
if (!$u->isRegistered()) {
print('<a href="'.$this->url('/login').'">Log In</a>');
} else {
print(' Hello: '.$u->getUserName().' ');
if (!$c->isEditMode()) {
print(' <a href="'.$this->url('/login','logout').'">Log Out</a>');
} else {
print(' Exit Edit Mode to logout ! ');
}
} ?>
I'm suggesting yet another variation. (see code below)
There are really three states or conditions to LogIn/LogOut.
#1 Not Logged In, - show Login
#2 Logged-In, but Not in Edit Mode - show Logout
#3 Logged In and in Edit Mode - show message to Exit Edit Mode.
The issue I had with the original example was that during State#3, the Login was shown again. This was confusing.
Hope this helps,
Dennis
--------------------------------------------------------
<?php
$u = new User();
if (!$u->isRegistered()) {
print('<a href="'.$this->url('/login').'">Log In</a>');
} else {
print(' Hello: '.$u->getUserName().' ');
if (!$c->isEditMode()) {
print(' <a href="'.$this->url('/login','logout').'">Log Out</a>');
} else {
print(' Exit Edit Mode to logout ! ');
}
} ?>
I am trying to add Login and Logout links to the AutoNav.
I would like these to show the appropriate link based on the status of the user ie. Logged in or Logged Out.
I see that this function works in the footer but would like it in the Nav section.
Any suggestions where to add this code?
I would like these to show the appropriate link based on the status of the user ie. Logged in or Logged Out.
I see that this function works in the footer but would like it in the Nav section.
Any suggestions where to add this code?
Is it possible to keep the user on the same page once they have logged out? I have managed this for logging in, but the same procedure doesn't work for logging out (i.e. adding getCollectionPath() to the end of the login URL. Here's what I have:
An old post that I found when trying to figure out how to get this to work in version 5.7. Lifted from the core file `concrete/elements/panels/dashboard.php` to log a user out properly use following:
Thank you for the 5.7 update. You saved me having to wade through the source myself, which is always appreciated when deadlines approach.
Thanks mikemiller! That is just what I needed for my 5.7.5.1 version.
Here's a combination of the above (including the check and a reminder to exit if in edit mode, as well as the actual working (in 5.7.5.3) Log Out link.
<?php $u = new User(); if (!$u->isRegistered()) { ?> <a href="<?= $this->url('/login'); ?>">Log In</a> <?php } else { print(' Hello ' . $u->getUserName() . ' '); if (!$c->isEditMode()) { ?> <a href="<?php echo URL::to('/login', 'logout', Loader::helper('validation/token')->generate('logout')) ?>"><?php echo t('Log Out.') ?></a> <?php } else { print(' Exit Edit Mode before logging out. '); } } ?>
Awesome! Was wondering why my custom login/logout weren't working in 5.8 :-)