Jump to:

21309 Posts in 5738 Topics by 2603 members

General Questions

SilverStripe Forums » General Questions » creating a logout link

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

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 4471 Views
  • ijasnijas
    Avatar
    Community Member
    1 Post

    Re: creating a logout link Link to this post

    Hi,

    I think this is more simple and helped me alot.

    // mysite/code/Page.php -> Page_Controller

       public function IsLoggedIn(){
          if(Member::currentUserId()){
             return true;
          }
       }   

       public function CurrentUser(){
          return Member::currentUser();      
       }

    // In your template File

       <% if IsLoggedIn %>
          <li id="logged-in" class="mainmenu">
             <% control CurrentUser %>
                <span>You are logged in as </span>
                <strong>
                   <% if FirstName && Surname %>
                      $FirstName $Surname
                   <% else_if FirstName %>
                      $FirstName
                   <% else %>
                      $Email
                   <% end_if %>
                </strong>
                (<a href="Security/logout" id="LogoutLink">Logout</a>)
             <% end_control %>
          </li>
       <% else %>
          <li id="login" class="mainmenu"><a href="Security/login?BackURL=$Link">Login</a></li>
       <% end_if %>

    4471 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.