gpt4 book ai didi

security - Symfony2 SonataAdminBundle 密码字段加密

转载 作者:行者123 更新时间:2023-12-02 22:11:01 24 4
gpt4 key购买 nike

我有 FOSUserBundle 来管理我的用户,SonataAdminBundle 来管理我的网站...我有一个问题,每当我尝试更改/添加任何用户的密码时,密码都不会编码到 sha512,但当用户在 fosuserbundle 注册页面内注册自己时,它就会发生...

所以 Symfony2 配置和 fosuserbundle 配置都没有任何问题,它可能在 SonataAdminBundle 的某个地方,或者可能在我的管理类中......

<?php
// src/Acme/DemoBundle/Admin/PostAdmin.php

namespace Web\DificilBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Web;

class UserAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('firstname')
->add('lastname')
->add('username')
->add('email')
->add('password', 'password') // -> I WANT THIS TO BE ENCODED INTO SHA512!
->add('roles','choice',array('choices'=>$this->getConfigurationPool()->getContainer()->getParameter('security.role_hierarchy.roles'),'multiple'=>true ));

//->add('body')
;
}

// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('firstname')
->add('lastname')
->add('username')
->add('email')
->add('password')
;
}

// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('firstname')
->add('lastname')
->add('username')
->add('password')
->add('email')
->add('facebookid')
->add('roles');

//->add('password', 'password')
;
}
}

最佳答案

为每个与我有同样问题的人找到了一个解决方案,只需在您的管理类中定义您的创建/更新表单,使用它,您的密码将被完美加密并准备好登录您的新用户;)

protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
->add('plainPassword', 'repeated', array(
'type' => 'password',
'options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
))
;
}

关于security - Symfony2 SonataAdminBundle 密码字段加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21002036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com