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

How to save Member Password manually?


Go to End


3 Posts   1878 Views

Avatar
novaweb

Community Member, 116 Posts

3 April 2012 at 4:26pm

Greets,

I am trying to make a registration form for Members, but cannot use $form->saveInto($member) due to custom functionality.

This does not work: http://pastie.org/3718370

It gives me a server error and defaults to the blackcandy template.

Can anyone advise?

Cheers,
Nova

Avatar
swaiba

Forum Moderator, 1899 Posts

4 April 2012 at 5:13am

Hi,

I've done this in the past that should save you some lines of code too (assuming your form is setup correctly)...

$doMember = new Member($data);
$doMember->write();

alternativly if you check the docs you could make the member and then set the password with a fucntion...

http://api.silverstripe.org/2.4/sapphire/security/Member.html#methodchangePassword

Avatar
novaweb

Community Member, 116 Posts

4 April 2012 at 10:45am

Thanks Swaiba, I couldn't do you first method as I was not able to make the Form Field Names match the Names of the Fields in the Database due to third party applications relying on certain Field Names. However, your changePassword suggestion helped me do the following:

	function doRegister($data, $form) {

			// Write the new member to the SilverStripe Database
			$member = new Member();
			$member->FirstName = $data['GivenName'];
			$member->Surname = $data['FamilyName'];
			$member->Email = $data['EMail']['Home'];
			$password = $data['Password']['_Password'];
			$member->changePassword($password);
			$member->write();
			return Director::redirect('please-verify-your-account/');	
	}

Cheers,
Nova