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.

All other Modules /

Discuss all other Modules here.

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

Registering New Users - User Module / Registration Module


Reply


5 Posts   4636 Views

Avatar
timcole

Community Member, 32 Posts

6 January 2010 at 5:10am

Edited: 06/01/2010 5:11am

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.

Avatar
Willr

Forum Moderator, 5513 Posts

6 January 2010 at 9:47am

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.

Avatar
timcole

Community Member, 32 Posts

7 January 2010 at 4:05am

Edited: 07/01/2010 4:07am

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.

Avatar
Willr

Forum Moderator, 5513 Posts

7 January 2010 at 9:00am

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 :D. 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.

Avatar
CHD

Community Member, 218 Posts

11 June 2011 at 4:03am

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/