【发布时间】:2013-05-22 06:20:33
【问题描述】:
当我以 role_user 身份登录我的网站时,当我尝试编辑我的个人资料时,我尝试将我的登录名更改为我的数据库中的某个登录名,我看到错误 - “此登录名已被使用”,好的,但是当我刷新我的页面我看到我授权为新登录,它不好
我有这个表单生成器:
namespace User\WalletBundle\Form;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class EditForm extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('username', null, array('attr' => array('placeholder' => 'Login')));
$builder->add('email', 'email', array('attr' => array('placeholder' => 'E-mail')));
$builder->add('mobile', 'number', array('attr' => array('placeholder' => 'Mobile','maxlength' => 10)));
$builder->add('password', 'repeated', array(
'type' => 'password',
'invalid_message' => 'Пароли не совпадают',
'options' => array('label'=>'','required' => false, 'always_empty' => false)));
$builder->add('old_pass','password',array('attr' => array('placeholder' => 'Old pass')));
}
public function getName() {
return 'edit_form';
}
public function getDefaultOptions(array $options) {
return array(
'data_class' => 'User\WalletBundle\Entity\User',
);
}
}
我想我不知道这个系统是如何工作的(安全性),也许我可以阅读我的问题,请链接。非常感谢
对我的英语非常非常抱歉
在我的控制器中,为了测试,我编写了这段代码
/**
* @Secure(roles="ROLE_USER")
* @Template("UserWalletBundle:Wallet:settings.html.twig")
*/
public function settingsAction(Request $request) {
$user_edit = $this->getDoctrine()->getRepository('UserWalletBundle:User')->findOneById($this->get('security.context')->getToken()->getUser()->getId());
$form = $this->createForm(new EditForm(), $user_edit);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
// Now i have login Alice, and i want change my profile, set login Test, but Test is created some user in DB, ofcours i see error This login is already used
if ($form->isValid()) {
//Do anything
} else {
// There i see error This login is already used
return array('form' => $form->createView());
}
} else
return array('form' => $form->createView());
}
现在我刷新我的页面,我看到我授权为用户名(登录)“测试”,为什么以及如何解决这个问题?
【问题讨论】:
-
请说出一个正确的问题/标题.. 安全不起作用不是问题。
-
请删除您的实体并在答案中包含您的表单类型以及您的树枝模板的一部分,您可以在其中生成“编辑”表单的网址..看起来您正在使用在这里创建表单!
-
现在看起来好多了?我认为这是实体的问题。因为我不太了解 Symfony2。