I am currently configuring a front-end user authentication check using Parsley.js and Django. Here is my view:
@requires_csrf_token
def password_check(request):
email = request.POST.get('email')
password = request.POST.get('password1')
user = authenticate(email=email, password=password)
if request.is_ajax():
if user and user.is_active:
res = "These password and e-mail are ok."
ajax_vars_login = {'response': res, 'email': email, 'password': password}
json_data_login = json.dumps(ajax_vars_login)
else:
res = "The e-mail or the password field aren't correct."
ajax_vars_login = {'response': res, 'email': email, 'password': password}
json_data_login = json.dumps(ajax_vars_login)
return HttpResponse(json_data_login, content_type='application/json')
And here is the Parsley validator being used:
Parsley.addAsyncValidator(
'emailPwCombination', function (xhr) {
var password = $('#password').parsley();
var email = $('#email').parsley();
var response = xhr.responseText;
var jsonResponse = JSON.parse(response);
var jsonResponseText = jsonResponse["response"];
if(jsonResponseText == 'These password and e-mail are ok.')
return true;
if(jsonResponseText == '404')
return false;
}, '/password_check/'
);
The issue I am facing is that it seems like the email is not being sent to the server because I receive two XHR responses each time I submit. The first response is:
{password: null, response: "The e-mail or the password field aren't correct.",…}
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97f2eff6fae7fbf2d7f0faf6fefbb9f4f8fa">[email protected]</a>"
password: null
response: "The e-mail or the password field aren't correct."
And the second response is:
{password: "examplepassword", response: "The e-mail or the password field aren't correct.", email: null}
email: null
password: "examplepassword"
response: "The e-mail or the password field aren't correct."
I'm trying to figure out what I might be missing. Any insights?