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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Issue with Member.php duplicate user.


Go to End


7 Posts   5365 Views

Avatar
nimeso

Community Member, 17 Posts

5 December 2010 at 10:27pm

Hi All,

I'm really hoping someone can help me. A huge launch has been put on hold until I can fix this but It's out of my league and maybe is a bigger problem at hand?

I have got Will's Facebook connect plugin working a-ok and it's been great! BUT!

One of the testers has found quite a big glitch, I'm not sure if its Member.php or something that needs changing in the Facebook plugin code.

1. Log in as a user into the front-end using the standard SS login form
2. Click the Facebook login button
3. Enter a different user details that are both SS and Facebook registered.
4. When Facebook popup closes and refreshes the page I get the following errors.

[User Error] Uncaught ValidationException:
GET /dashboard

Line 612 in C:\wamp\www\guardian\sapphire\security\Member.php

It's cocking up here in Member.php (note the comments)

// If a member with the same "unique identifier" already exists with a different ID, don't allow merging.
// Note: This does not a full replacement for safeguards in the controller layer (e.g. in a registration form),
// but rather a last line of defense against data inconsistencies.
$identifierField = self::$unique_identifier_field;
if($this->$identifierField) {

etc etc

Whats crazy is that if I comment out the following like so:

if($existingRecord) {
/*
throw new ValidationException(new ValidationResult(false, sprintf(
_t(
'Member.ValidationIdentifierFailed',
'Can\'t overwrite existing member #%d with identical identifier (%s = %s))',
PR_MEDIUM,
'The values in brackets show a fieldname mapped to a value, usually denoting an existing email address'
),
$existingRecord->ID,
$identifierField,
$this->$identifierField
)));
*/
}

It works fine!!!!! and merges the members correctly?

Am I nutz! why is this so... someone please explain why I need the ValidationException when it seems to do what I want without this code?

Please please please someone before I loose all my hair.. lol

Cheers Everyone, great work!
Jamie

Avatar
janulka

Community Member, 80 Posts

8 February 2011 at 1:08am

I have same problem when user is registering with email adress which is already registered.

Registration Form:

<?php

class RegistrationFormProdusent extends Page {
	
	static $icon = "/cms/images/treeicons/task";
}
 
class RegistrationFormProdusent_Controller extends Page_Controller {
 
	// Make sure you set this to the right group.
	// See http://doc.silverstripe.com/doku.php?do=show&id=recipes%3Aforms
	private $defaultGroupID = 5;
 
	/**
	* This function lets you put a form on your page, using $Form.
	*/
	function Form() {
		return new Form($this, "Form", new FieldSet(
 
			// List your fields here
			new TextField("FirstName", "Fornavn"),
			new TextField("Surname", "Etternavn"),
			new EmailField("Email", "E-post adresse"),
			new TextField("Telefon"),
			new TextField("Adresse"),
			new TextField("Postnummer"),
			new TextField("Sted"),
			new ConfirmedPasswordField("Password", "Passord")
 
		), new FieldSet(
 
			// List the action buttons here
			new FormAction("SignupAction", "Registrer")
 
		), new RequiredFields(
 
			// List the required fields here: "Email", "FirstName"
 
		));
	}
 
	/**
	* This function is called when the user submits the form.
	*/
	function SignupAction($data, $form) {
 
		// Create a new Member object and load the form data into it
		$member = new Member();
		$form->saveInto($member);
 
		// Write it to the database.  This needs to happen before we add it to a group
		$member->write();
 
		// Add the member to group. (Check if it exists first)
		if($group = DataObject::get_one('Group', "ID = $this->defaultGroupID")) { 
 
			$member->Groups()->add($group);
			// Redirect to a page thanking people for registering
			Director::redirect('takk-for-registrering/');
 
		}else{
 
			// Redirect to a failure page
			Director::redirect('registrering-mislyktes/');
 
		}
 
	}
}
?>

Error:

User Error] Uncaught ValidationException:

POST /for-produsentar/registrering-produsent/Form

Line 628 in /home/hardarrf/public_html/sapphire/security/Member.php

Source

619                         'Member',

620                         sprintf(

621                                 "\"%s\" = '%s' %s",

622                                 $identifierField,

623                                 Convert::raw2sql($this->$identifierField),

624                                 $idClause

625                         )

626                  );

627                  if($existingRecord) {

628                         throw new ValidationException(new ValidationResult(false, sprintf(

629                                 _t(

630                                         'Member.ValidationIdentifierFailed',

631                                         'Can\'t overwrite existing member #%d with identical identifier (%s = %s))',

632                                         PR_MEDIUM,

633                                         'The values in brackets show a fieldname mapped to a value, usually denoting an existing email address'

634                                 

Would it be possible to display "nicer" error to user in form of "user with this email adress already" exists instead of this ugly nasty SQL error?

Thanks :)

Avatar
swaiba

Forum Moderator, 1899 Posts

8 February 2011 at 1:53am

I'd suspect your site is in dev mode - so you get dev errors - is this the case? if so what happens when you are in live mode?

Avatar
janulka

Community Member, 80 Posts

8 February 2011 at 9:53am

Yes, it is in dev mode, and I need to have it in dev mode for a while longer..

Anyway, I made new page called registration-failed, and included this as first thing in "function Signup":

		$email = Convert::raw2sql($data['Email']);
		
		if($member = DataObject::get_one("Member", "`Email` = '$email'")) {
		Director::redirect('registration-failed');
		}
		else {

                // ............ etc and all other stuff here

so now, instead of displaying error message (which would not show up in dev mode), I redirect user to error page called registration-failed

and it works, and it is perfectly good enough for me :)

Avatar
swaiba

Forum Moderator, 1899 Posts

8 February 2011 at 10:52am

couldn't have put it better myself

Avatar
CHD

Community Member, 219 Posts

11 June 2011 at 4:05am

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/

it also has an easy "query database for existing member" function that isn't covered in the form tutorials...

Avatar
monkeyben

Community Member, 25 Posts

15 June 2011 at 10:04pm

That works great thanks CHD :)