Jump to:

23355 Posts in 17873 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Issue with Member.php duplicate user.

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

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

Page: 1
Go to End
Author Topic: 2776 Views
  • nimeso
    Avatar
    Community Member
    17 Posts

    Issue with Member.php duplicate user. Link to this post

    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

  • janulka
    Avatar
    Community Member
    80 Posts

    Re: Issue with Member.php duplicate user. Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: Issue with Member.php duplicate user. Link to this post

    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?

  • janulka
    Avatar
    Community Member
    80 Posts

    Re: Issue with Member.php duplicate user. Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: Issue with Member.php duplicate user. Link to this post

    couldn't have put it better myself

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Issue with Member.php duplicate user. 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/

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

  • MonkeyBen
    Avatar
    Community Member
    25 Posts

    Re: Issue with Member.php duplicate user. Link to this post

    That works great thanks CHD

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