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.

General Questions /

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

How to save Member Password manually?


Reply


3 Posts   593 Views

Avatar
novaweb

Community Member, 115 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, 1799 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, 115 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