Finding out whether a user is logged in or not

Author Message

Eirik Alfstad Johansen

Tuesday 11 November 2003 11:34:13 am

Hi,

[EDIT]: Apparently I was a little bit too quick to post. It hit me that there probably existed an is_logged_in attribute for the current_user, and that was of course correct.

What's the best way to find out (in a template) whether a user is logged in or not? I've read about using "current_user" for the fetch function, but that doesn't give me the anonymous user id to compare with.

Up until now, I've been using the following in my pagelayout.tpl:

{section show=eq($current_user.contentobject_id,$anonymous_user_id)}

Though there's no documentation of the variable $anonymous_user_id being passed to pagelayout.tpl, this works like a charm. For the other templates, however, this variable seems to be unavailable.

So, what is the best way to detect whether a user is logged in or not?

Thanks in advance !

Sincerely,

Eirik Johansen
Netmaking AS

http://www.netmaking.no/

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Bruce Morrison

Tuesday 11 November 2003 2:31:13 pm

Hi Eirik

I've used the following on a number of sites...

{let thisuser=fetch('user','current_user')}
{section show=$thisuser.is_logged_in}
<p>Welcome. You are logged in as {$thisuser.contentobject.name}</p>
<p><a href="/user/logout">Logout</a></p>
{section-else}

<!-- login form goes here -->

{/section}
{/let}

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 06:13:28
Script start
Timing: Jan 31 2025 06:13:28
Module start 'layout'
Timing: Jan 31 2025 06:13:28
Module start 'content'
Timing: Jan 31 2025 06:13:28
Module end 'content'
Timing: Jan 31 2025 06:13:28
Script end

Main resources:

Total runtime0.0130 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0041 588.2656151.2266
Module start 'layout' 0.00410.0019 739.492236.6797
Module start 'content' 0.00600.0053 776.171990.1875
Module end 'content' 0.01130.0017 866.359433.9922
Script end 0.0129  900.3516 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002317.7214140.0002
Check MTime0.00107.7552140.0001
Mysql Total
Database connection0.00064.644310.0006
Mysqli_queries0.001914.325930.0006
Looping result0.00000.069810.0000
Template Total0.00129.510.0012
Template load0.00097.108810.0009
Template processing0.00032.317610.0003
Override
Cache load0.00075.107110.0007
General
dbfile0.001410.467680.0002
String conversion0.00000.049640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs