Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

Creating login & logout button


Go to End
Reply


4 Posts   4034 Views

Avatar
monnick

Community Member, 6 Posts

22 November 2010 at 2:22am

I am just starting with Silverstripe and I am having a (very simple?) problem. What I want to do is simply create a login / logout button somewhere on the site, the default menubar would be a good place. This should be very easy I guess, but I don't know how to do it...

On the back-end I could simply create a new menu-item which refers to /Security/login, but then it will still say "Login" after logging it, I would like it to disappear or change to logout. What is the best and simplest way to realize this?

I have searched the SilverStripe documentation, but I couldn't find it. Can somebody please explain how this works or provide me a link to a page where it is described? Thanks in advance! :-D

Avatar
purplespider

Community Member, 84 Posts

22 November 2010 at 2:34am

Edited: 22/11/2010 2:35am

In your template:

<% if CurrentMember %> 
// Show logout button 
<% else %> 
// Show login button 
<% end_if %>

See http://spdr.me/qrVz for more info.

Hope that helps!

Avatar
dhensby

Community Member, 247 Posts

22 November 2010 at 2:44am

The links would be:

<a href="/Security/login">Log in</a>

and

<a href="/Security/logout">Log out</a>

Avatar
pbt

Community Member, 3 Posts

11 January 2015 at 4:31am

I found that it is possible to programaticaly put login/logout buttons in header (in Silverstripe CMS) with this code.

<% if CurrentMember %>
<a href="/Security/login">Log in</a>
<% else %>
<a href="/Security/logout">Log out</a>
<% end_if %>

If I put "/Security/login" and "/Security/logout" in page name then it works, But if I put it in page template Page.ss then I cant see it (after sitename/dev/build and sitename/?flish=all)

Can someone help with Silverstripe 3.1 and "simple" template. Or give me any other clue.