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

DataExtension to Member ignored for changePassword?


Go to End


4 Posts   1391 Views

Avatar
mbernst

Community Member, 3 Posts

22 February 2013 at 8:37pm

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.

Avatar
Devlin

Community Member, 344 Posts

22 February 2013 at 9:22pm

Edited: 22/02/2013 9:27pm

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

Avatar
mbernst

Community Member, 3 Posts

22 February 2013 at 9:56pm

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?

Avatar
Devlin

Community Member, 344 Posts

22 February 2013 at 10:41pm

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