0
Symfony 2.4에서 사용자 비밀번호의 유효성 검사에 문제가 있습니다. 나뭇 가지 안에 html 코드로 만든 양식이 있고 양식 작성기를 사용하지 않습니다. 양식을 ajax를 통해 제출하기 때문에 양식 빌더를 사용하지 않습니다.ajax 양식의 Symfony UserPassword 유효성 확인
양식은 암호 변경 양식이며 사용자 암호와 일치해야하는 암호 필드가 있습니다.
코드 :
형태의Html.twig 코드 :
<form id="changePassword" name="changePassword">
<label id="labelPassword">Write your current password </label>
<input type="password" id="CurrentPassword" name="CurrentPassword" />
<label id="labelNewPassword">Write your new password </label>
<input type="password" id="NewPassword" name ="NewPassword" />
<label id="labelNewPassword2">Repeat your new password</label>
<input type="password" id="NewPassword2" name ="NewPassword2" />
<input type="submit" class="btn-primary btn" value="Change"/>
</form>
아약스 코드 : 컨트롤러의
var ServerData;
$(document).ready(function() {
$("form").submit(function(e) {
e.preventDefault();
var data = $(this).serialize();
var url = $(this).attr("name");
var id = $(this).attr("id");
if(validates(url)){
$.ajax({
url: url+"/" ,
method: "post",
dataType: "json",
data: data,
success: function (ServerData){
successFunction();
},
error: function(){
errorFunction();
}
});
}
else{
novalidFunction();
}
});
});
function validate(url){
//Just length and matching new password with repeat new password validations
}
// succesFunction(), errorFunction() and novalidFunction() and all this code are
//working great
PHP 코드 :
public function changePasswordAction ($request Request){
$user= $this->getUser();
$password = $user->getPassword();
$currentPassword = $request->get("CurrentPassword");
$newPassword = $request->get("NewPassword");
//here is where i need the code to compare $password with $currentPassword;
//the problem is that $password is encoded
//then i got the code to insert new values in Users table and its working;
}
감사에서 내 engl에 대해 사전에 미안하다. ish