Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Member Login

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

Page: 1 2
Go to End
Author Topic: 7185 Views
  • Juerg Sommer
    Avatar
    Community Member
    2 Posts

    Member Login Link to this post

    Hi

    I started with SilverStripe two days ago and the system works - the greatest CMS I've seen. Very good to customize and good tutorial.

    Now I'm configuring the member section: the pages works well and also the login works fine, but there's no tutorial about this section (or I didn't find it).

    My Problem is the "status" of the user (and his name/profile). What I would is an information on each page like this forum

    "Login"
    or
    "You're logged in as {firstname} {lastname} | Log Out | Profile"

    But how can I know if a user's logged in (and with what loginname, firstname, lastname, ...), so that I can display these informations in the layout-template?

    I also want to change the login-form, is there a better way than modify the MemberLoginForm.php? (there are layout-changes, textes I could change in the language-folder).

    Last Question: is there an existing "user-profile" page I could modify for my users or have I to build a own one (wouldn't be a problem, if I know where I can get the user informations).

    Thanks a lot for every answer!

    Greetings,
    Juerg

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Member Login Link to this post

    Hi Juerg, welcome to silverstripe

    Firstly, accessing the current member is easy.

    In the controller (or model) something like:

    if($member = member::currentUser()){
    return $member.FirstName;
    }


    Or in the template you can use something like:

    <% if CurrentMember %>
    <p>Logged in as: $CurrentMember.FirstName </p>
    <% end_if %>

    To change the login form you can extend the MemberLoginForm class. To do this create a file called CustomLoginForm.php in your mysite/code folder and put something like:

    class CustomLoginForm extends MemberLoginForm {

       public function dologin($data) {
    [some code]
    }

    }

    Then in your _config.php file you can specify that you want SS to use your custom class in place of teh standard login by adding this line:

    Object::useCustomClass('MemberLoginForm', 'CustomLoginForm');

    This also ensures that if you upgrade your SS version you wont have to worry about overwriting your changes.

    As for your final question I am not entirely sure, I don't think there is an actual member page, but you can easily create one using the currentMember functions above. for reference look at the forum module which does have a member profile page and also adds a load of fields (Nickname, occupation, country etc). if you are going to add fields to teh member class then I think the best way to do it is using the data object decorator, but someone else may be able to give you more info on that as I have not actually used them yet.

    Anyway hope that gets you someway to where you want to be

    Aram

  • Juerg Sommer
    Avatar
    Community Member
    2 Posts

    Re: Member Login Link to this post

    Hi Aram

    Thanks for your very fast und informative answer. I'll try it and I'm sure this will solve my problem.

    Juerg

  • webgeek
    Avatar
    Community Member
    2 Posts

    Re: Member Login Link to this post

    Silverstripe is way beyond the competition. Thanks for the post, I am also looking for a solution to this problem.

    Regards,
    Junrey

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Member Login Link to this post

    Your welcome And yes, it's fabulous ins't it!

  • webgeek
    Avatar
    Community Member
    2 Posts

    Re: Member Login Link to this post

    Absolute Fabulous! Elegant!

    Silverstripe has helped me beat the deadline not only for 1 website but 2 and impressed both clients at the same time. It could have been a disaster if I haven't found Silverstripe.

  • micahsheets
    Avatar
    Community Member
    164 Posts

    Re: Member Login Link to this post

    I am also wanting to create a custom login however I don't want to replace the current MemberLogin Class I want to have two different login forms. The current MemberLogin Form that allows logging into the CMS Admin section would stay the same but I want a login for a front end public members section on a different page. The difference between my Member Login and Admin Login is the page the member gets redirected to.

    I have tried making my own Authenticator by extending Authenticator just like MemberAuthenticator and registering it using Authenticator::register_authenticator(); in my _config.php, then I added my own LoginForm() function to my page controller like this:

       public function LoginForm(){
          $authenticator = 'CustomAuthenticator';
          $authenticators = Authenticator::get_authenticators();
          if(in_array($authenticator, $authenticators)) {
             return call_user_func(array($authenticator, 'get_login_form'), $this);
          }
       }

    However when I look at the generated form the Action is always MemberAuthenticator so it doesn't seem to work.

    Any help or tips on how this all works would be appreciated.

  • sorich87
    Avatar
    Community Member
    14 Posts

    Re: Member Login Link to this post

    micahsheets, this tutorial may be useful for you :
    http://www.ssbits.com/custom-login-form-with-group-based-redirection/

    7185 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.