2012-02-08 12 views
9

मैं FOSUserBundle में पासवर्ड के लिए वर्तमान सत्यापन को ओवरराइड करने का प्रयास कर रहा हूं। मैंने कुछ विकल्पों की कोशिश की है, लेकिन मुझे अभी भी समाधान नहीं मिल रहा है।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 सेट करने का सही तरीका क्या है यह सुनिश्चित करने के लिए कि यह हर जगह मान्य है?

इसके अलावा, FOSUserBundle के साथ सही दृष्टिकोण क्या है जो oldpassword != newpassword में चेंजपासवर्ड के भीतर सत्यापित करने के लिए है?

उत्तर

1

आप मान्यकरण समूह

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

+0

यह कुछ मुझे लगता है कि अगर मेरे मुद्दों का कारण था देखने के लिए प्रयास में हटा दिया है। मैंने उन्हें सत्यापित करने के लिए अभी वापस रखा है, ऐसा कोई फर्क नहीं पड़ता है। मैं ऊपर स्पष्ट रूप से उन्हें शामिल करने के लिए संपादित कर दूंगा। – MadManMonty

4

validation.yml एक ही बंडल कि FOS उपयोगकर्ता इकाई

एक्मे के बजाय आप FOS का उपयोग करना चाहिए

अधिलेखित कर देता है में होना चाहिए का उपयोग कर सकते हैं और आप केवल आवश्यकता चाहिए एक सत्यापन सेट।

# 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

+1

यह http://symfony.com/doc/current/reference/constraints/Length.html पर आधारित लंबाई सत्यापन के लिए सही वाक्यविन्यास प्रतीत नहीं होता है – gondo

संबंधित मुद्दे