Forums / Setup & design / Top Login box

Top Login box

Author Message

Neo Pixel

Wednesday 18 February 2009 8:35:24 am

Hi,

I've designed an ezpublish site with a login box at the top using the form from the login page.

ie:

Username: TEXTBOX
Password: TEXTBOX
forgotten password <-- link

Once a user logs into their account is it possible for the form to be replaced with the logout link?

How would I go about doing this?

Thanks in advance :-)

Asking stupid questions so you don't have to!

Norbert Wagner

Wednesday 18 February 2009 8:55:25 am

You could check wich user is actually logged in, if it is the anonymous user show the login form, else the logout link.

Regards,
Norbert

Neo Pixel

Wednesday 18 February 2009 10:40:52 am

Hi Norbert,

Yes that's what I am after but how do I achieve it?

Do I need to create a .tpl file and reference it in the pagelayout.tpl

if so, what code do I put into the new loginbox.tpl ?

Asking stupid questions so you don't have to!

Norbert Wagner

Wednesday 18 February 2009 12:33:17 pm

You can put everything right inside the template where you put the form.
Just use a if statement like

{if eq(user,anonymous)}
// form code here
{else}
// logout
{/if}

Check the manual for how to get the current user, perhaps there is a pagelayout variable?

Norbert

Yannick Komotir

Friday 20 February 2009 4:18:02 am

Hi,

  {if $current_user.is_logged_in}
     <a href={"/user/logout"|ezurl} >Logout</a>
  {else}
     {*your login form here*}
  {/if}
 

<|- Software Engineer @ eZ Publish developpers -|>
@ http://twitter.com/yannixk

Neo Pixel

Saturday 21 February 2009 10:07:00 am

Thanks Yannick that works perfectly!


{if $current_user.is_logged_in}      
	<a href={"/user/logout"|ezurl} >Logout</a>   
	{else}      
	
<form method="post" action="/eng/user/login" name="loginform">
<table cellpadding="5" cellspacing="5" width="250">
<tr>
	<td align="right">Username</td>
	<td><input class="box" type="text" size="15" name="Login" id="id1" value="" tabindex="1" /></td>
</tr>
<tr>
	<td align="right">Password</td>
	<td><input class="box" type="password" size="15" name="Password" id="id2" value="" tabindex="1" /></td>
</tr>
<tr>
	<td align="right">&nbsp;</td>
	<td><input class="defaultbutton" type="submit" name="LoginButton" value="Login" tabindex="1" /> <a href="/eng/user/forgotpassword">forgotten password?</a></td>
</tr>
</table>
</form>	

   {/if} 

Asking stupid questions so you don't have to!