简体   繁体   中英

FOSUserBundle register without password

I am creating an application where visitors can upload some stuff (it will be for invited people only). At the end, if they are not logged in, they are asked to log in or create a user. If they create a new user, I only want to ask them to fill in their name and email.

a password will be generated, and a mail will be sent to the user with the links to change their password if they want to (only to make the procedure as low level as possible).

I can't seem to remove the password fields from the registration form. Can someone help me out. I create a custom form type, service and registered it. I also put custom templates in the app/Resource folder etc. Although my custom Form type AND the templates are being used, the password still appears ...

class RegistrationFormType extends BaseType {

  public function buildForm(FormBuilderInterface $builder, array $options) {
    parent::buildForm($builder, $options);

    // add your custom field
    $builder->add('username');
    $builder->add('email');
  }

  public function getName() {
    return 'val_user_registration';
  }

}

You don't need to extend your parent form ... and you're better off not doing it in this case.

just create a Username/Email form and create the new User entity yourself in a custom registration method then persisting it into database ( don't forget to set the usernameCanonical property on your newly created User ).

FOSUserBundle calls several password-related things during the registration process which you don't need and can't easily circumvent in this case.

You can pass the entity ( with newly created password ) to the update method of FOSUserBundle's UserManager service after you have completed the password/email step then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM