how to check if this user is logged in?

Author Message

zaxofeel .v

Sunday 10 July 2005 3:02:22 am

hey ppl, how are you all? :)
as usual, i need ur help,
i want to check if the current user is logged in or not, so, i found this piece of code in one of the ez templates:

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

      <a class="menuitem" href={"/user/login/"|ezurl}>{"Login"|i18n("design/standard/layout")}</a>

      {section-else}

      <a class="menuitem" href={"/user/logout/"|ezurl}>{"Logout"|i18n("design/standard/layout")}</a> ({content_view_gui view=text_linked content_object=$current_user.contentobject})

      {/section}

when i used this code, i found that it always displays "login", and it never displayes logout even if i am already signed in.

i really hope if someone can tell me what's wrong with that or if there is another way to implement this, i'll be very thankful.
thanks all

Pål J Didriksen

Sunday 10 July 2005 5:48:07 am

Hi!

I think you need to fetch the current user first, for example:

{default current_user=fetch('user','current_user')}

Then you can show different content, depending on wether the user is logged in or not:

{default current_user=fetch('user','current_user')}
{section show=$current_user.is_logged_in}
    Hello, {$current_user.contentobject.name}, you are now logged in!   
{section-else}
    Please log in first.
{/section}
{/default}

Hope this works for you too!

Pål J.

zaxofeel .v

Monday 11 July 2005 12:49:28 am

thank you very much dear friend
the line of fetching the current user was what i am missing
problem solved.
thanks again :)

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 04:29:54
Script start
Timing: Jan 31 2025 04:29:54
Module start 'layout'
Timing: Jan 31 2025 04:29:54
Module start 'content'
Timing: Jan 31 2025 04:29:54
Module end 'content'
Timing: Jan 31 2025 04:29:54
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.0045 588.2500151.2266
Module start 'layout' 0.00450.0028 739.476636.6641
Module start 'content' 0.00730.0045 776.140690.2656
Module end 'content' 0.01180.0012 866.406333.9922
Script end 0.0130  900.3984 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002116.4191140.0002
Check MTime0.00107.9863140.0001
Mysql Total
Database connection0.00075.196110.0007
Mysqli_queries0.002821.201730.0009
Looping result0.00000.091510.0000
Template Total0.00097.210.0009
Template load0.00075.746910.0007
Template processing0.00021.374010.0002
Override
Cache load0.00053.944710.0005
General
dbfile0.00086.226280.0001
String conversion0.00000.062240.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