Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Registering New Users - User Module / Registration Module

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 4499 Views
  • timcole
    Avatar
    Community Member
    32 Posts

    Registering New Users - User Module / Registration Module Link to this post

    I was loving silverstripe, but I am rapidly going off it!!
    I want to do something which I think is pretty simply - but I am having ENDLESS problems. Maybe I am being stupid and missing something... what I require is:

    1. Simple registration page with First Name, Last Name, Email, Password, State, Country and Mobile (Cell) number.
    2. Simple page for user to amend those details.

    That's it - seems pretty fundamental and pretty basic to me. I have tried working with the two unsupported modules available to do this but have found MASSIVE problems with both.

    Aside from the fact that at points it doesn't actually seem to save anything into the DB - the biggest issue is that neither of them seem to perform any checks on whether a user already exists!! If someone tries to register using the same email address as one already registered it seems to just replace the existing user account. Not good. I would have thought user registration was a pretty fundamental module really, I am surprised it isn't part of the core, supported module or at very least some better documentation.

    If anyone can point me towards some examples on this I'd be very grateful.

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Registering New Users - User Module / Registration Module Link to this post

    Good points. The registration module has these issues just because it was built as a simple demo of the features. The forum member registration is probably the more robust code for looking how signup works. When we look at using the registration module to work in the forum we'll probably give that module a good going over to make sure its up to scratch.

    In the mean time the issues you're having with the module.

    First thing - the checking that an email doesn't exist. You could add this code in the 'register' function at the top.

    $email = Convert::raw2sql($data['Email']);
    if($member = DataObject::get_one("Member", "`Email` = '$email'")) {
       // Add a error message
       $form->addErrorMessage("Email",'Sorry, that email address already exists. Please choose another.',"bad");
                
       // Load errors into session and post back
       Session::set("FormInfo.Form_Form.data", $data);

       // Redirect back to form
       return Director::redirectBack();
    }

    Next thing - its not saving? That seems strange as the code is pretty simple. I'm looking at the code on http://open.silverstripe.org/browser/modules/registration/trunk/code/RegisterPage.php - it writes to the db on line 53 you might want to check that code get run. Also note that you won't see the member in the CMS since it doesn't add the user to a group.

    To add a user to a group (which you probably want). You need to add this line after line 53 - Group::addToGroupByName($member, 'registered-members'); - and if you're using 2.3 then you will need to make a group in the CMS named 'Registered Members' for it to save into.

  • timcole
    Avatar
    Community Member
    32 Posts

    Re: Registering New Users - User Module / Registration Module Link to this post

    Thanks for your reply Willr - appreciate you taking the time.

    When I calmed down a little and de-stressed ;-) I managed to get it going by "fixing" one of the existing modules. I've kind of made it specific to my needs so not much use sharing it - but it seems to me that those two existing modules need the code to check if an email already exists and that this functionality really should be added to the the core. A basic registration and profile editing page are pretty vital to a lot of sites these days.

    You were right about the group thing - I spotted that too. Opening the database in phpMyAdmin gave me a clue as to what was happening... I couldn't see the new users in the CMS so assumed they were not being saved. As you rightly point out, the issue was there was no group assigned.

    Thanks for the post.

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Registering New Users - User Module / Registration Module Link to this post

    I've kind of made it specific to my needs so not much use sharing it

    Thats why the functionality of the module itself is pretty pour - whenever we work on a registration based site we do custom code since its easier . I'll add that code I posted to check for emails and code to add a user to a group to at least make it 'work'.

    If you have even little snippet fixes / enhancements feel free to make a ticket on open.silverstripe.org.

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Registering New Users - User Module / Registration Module Link to this post

    this may come in handy for anybody who wants to easily include forms in a sidebar or any other area of the site, without controlling a hidden page:

    http://www.clickheredigital.co.uk/blog/how-to-include-a-silverstripe-form-on-any-every-page/

    4499 Views
Page: 1
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.