Jump to:

23455 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » DataExtension to Member ignored for changePassword?

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: 632 Views
  • mbernst
    Avatar
    Community Member
    3 Posts

    DataExtension to Member ignored for changePassword? Link to this post

    I need to keep SS passwords in sync with another system. So I defined a SyncedMember class in a SyncedMember.php file. I then set up my own custom changePassword:

    class SyncedMember extends DataExtension {
       public function changePassword($password) {
          $valid = $this->owner->changePassword($password);

          if ($valid) {
             // do my actual logic here to update the password in my other system
             }
          }
          
          return $valid;
       }
    }

    It's not getting called when I run through the dialog in /Security/changepassword. I have tried making the first line of the function in the extension 'garbagecall();' to see if it was a problem with the details of my code, but there's no error. The extension's changePassword isn't getting called at all.

    I have several other DataObject extensions working successfully. In my _config.php I have:

    Object::add_extension('Member', 'SyncedMember');

    I ran dev/build and flushed before trying my changes. I am on SS 3.0. If I directly edit the changePassword definition in framework/security/Member.php it works as expected.

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: DataExtension to Member ignored for changePassword? Link to this post

    I'm afraid, you cannot overload Member->changePassword with a DataExtension. You need to subclass Member.

    Object::useCustomClass("Member", "SyncedMember");

    http://doc.silverstripe.org/framework/en/3.1/reference/member

    Though, this might not completely work out of the box... Object::useCustomClass ist somewhat mysterious... Maybe you need a DataExtension for Member too, which changes Member to SyncedMember via the onBeforeWrite, onAfterWrite or augmentWrite method.

    http://doc.silverstripe.org/framework/en/3.1/reference/dataextension

  • mbernst
    Avatar
    Community Member
    3 Posts

    Re: DataExtension to Member ignored for changePassword? Link to this post

    Thanks! Did I misunderstand how data extensions are used? I thought I could customize any class's functions this way if the parent descends from Object. And even the online manual extends Member as its example for DataExtension. Is there an easy way to tell when you must subclass instead of extend?

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: DataExtension to Member ignored for changePassword? Link to this post

    With a DataExtension you can add functionality to a DataObject (only). You can add DB fields and methods, further you can augment write methods (@see $this->extend()). But you cannot replace/overload a method.

    And even the online manual extends Member as its example for DataExtension.

    Nope. There is a example for subclassing Member ("the least desirable way") and subclassing DataExtension.

    Please read the docs carefully and then choose how to proceed. This is a sensitive matter.

    Hint:
    If you subclassing Member, "you have to make sure that those with login-capabilities have unique email-addresses".
    http://doc.silverstripe.org/framework/en/3.1/reference/member#extending-member-or-dataobject

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