M
M
Max2019-10-12 21:13:46
symfony
Max, 2019-10-12 21:13:46

How to get or change user password (FOSUserBundle) in symfony 3.4?

Hello!
I need to make a list of users where the admin can edit any data of these users including passwords.
I installed and configured FOSUserBundle, but when I try to change plainPassword, I get an error:

An exception occurred while executing 'UPDATE fos_user SET pass = ?, password = ? WHERE id = ?' with params [null, "$2y$13$xfuD.3aPBh0oSNn2eCPf2eylUnM6807jFFgwfhYvkMnLTAZ9BIH1.", 5]:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'pass' cannot be null

the form:
class UserType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('enabled', null, [
                'required' => false,
                'label' => 'Актианый',
            ])
            ->add('username')
            ->add('email')
//            ->add('password')
            ->add('plainPassword')
            ->add('last_login', DateTimeType::class)
            ->add('roles', ChoiceType::class,
                [
                    'label' => 'Группа',
                    'multiple' => true,
                    'choices'  => [
                        'Зарегистрированный пользователь' => 'ROLE_USER',
                        'Администратор' => 'ROLE_SUPER_ADMIN',
                        ]
                ]
            )
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundle\Entity\User'
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'appbundle_user';
    }
}

Ideally, I need to write my own encryptor and decryptor so that I can get and change the password of any user.
Or at least make sure that the password is stored in the database in unencrypted form.
Well, accordingly, so that authorization and registration at FOSUserBundle do not fly off.
Tell me how best to implement this?
How do I change passwords?
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question