10

FOSUserBundleのパスワードの現在の検証を上書きしようとしています。いくつかのオプションを試しましたが、それでも解決策が見つかりません。

パスワードのMinLengthを増やすために、次のコマンドでvalidation.ymlを作成しました。

# src/Acme/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Entity\User:
    properties:
        username:
            - MinLength: { limit: 3, message: "Your username must have at least {{ limit }} characters." }
            - MaxLength: { limit: 255, message: "The username is too long" }
            - NotBlank: { message: "Please enter a username"}       

        plainPassword:
            - NotBlank: { message: "Please enter a password"}
            - MinLength: { limit: 8, message: "Your password must have at least {{ limit }} characters.", groups [Registration,Profile]}
                - MaxLength: { limit: 255, message: "The password is too long" }

Acme\UserBundle\Form\Model\ChangePassword:
  properties:  
      new:
          - NotBlank: { message: "Please enter a new password", groups [ChangePassword]}
          - MinLength: { limit: 8, message: "Your password must have at least {{ limit }} characters.", groups [ChangePassword]}
          - MaxLength: { limit: 255, message: "The password is too long", groups [ChangePassword]}  

Acme\UserBundle\Form\Model\ResetPassword:
        new:
            - NotBlank: { message: "Please enter a new password", groups [ResetPassword]}
            - MinLength: { limit: 8, message: "Your new password must have at least {{ limit }} characters.", groups [ResetPassword]}
            - MaxLength: { limit: 255, message: "The new password is too long", groups [ResetPassword]}

これは私にとっては問題なく機能しています/register/change-password、デフォルトではFOSUserBundleからの最小長の検証が所有権を取得しています。

私の質問をより明確に述べるために、FOSUserBundleでパスワードのMinLengthを設定して、どこでも検証されるようにする正しい方法は何ですか?

さらに、ChangePassword内でそれを確認するためのFOSUserBundleの正しいアプローチは何oldpassword != newpasswordですか?

4

2 に答える 2

4

validation.yml は、FOS ユーザー エンティティを上書きする同じバンドルにある必要があります。

Acme の代わりに FOS を使用する必要があり、必要な検証セットは 1 つだけです。

# src/Acme/UserBundle/Resources/config/validation.yml
FOS\UserBundle\Model\User:
   properties:
      username:
        - MinLength: { limit: 3, message: "Your username must have at least {{ limit }} characters." }
        - MaxLength: { limit: 255, message: "The username is too long" }
        - NotBlank: { message: "Please enter a username"}       

      plainPassword:
        - NotBlank: { message: "Please enter a password", groups:[Registration, ResetPassword, ChangePassword] }
        - MinLength: { limit: 8, message: "Your password must have at least {{ limit }} characters.", groups:[Registration, ResetPassword, ChangePassword] }
        - MaxLength: { limit: 255, message: "The password is too long", groups:[Registration, ResetPassword, ChangePassword] }

問題が発生した場合は、ソースにアクセスしてください: https://github.com/FriendsOfSymfony/FOSUserBundle/issues/987

于 2013-09-18T20:34:53.077 に答える
1

検証グループを使用できます

http://symfony.com/doc/2.0/book/validation.html#validation-groups

于 2012-02-09T08:26:10.270 に答える