Last active
October 2, 2023 15:24
-
-
Save antimech/d201742dc785eccc630de9f7f137595a to your computer and use it in GitHub Desktop.
JQuery smart auth script with Google reCAPTCHA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#sign-up form').submit(function (event) { | |
var $this = $(this), | |
email = $this.find("input[name='email']").val(), | |
password = $this.find("input[name='password']").val(), | |
repeatPassword = $this.find("input[name='repeatpassword']").val(), | |
captcha = grecaptcha.getResponse(widgetId1); | |
if (password !== repeatPassword) { | |
document.querySelector('#sign-up form input[name="repeatpassword"]').setCustomValidity('Passwords mismatch'); | |
event.preventDefault(); | |
return false; | |
} | |
$.ajax({ | |
type: $(this).attr('method'), | |
url: $(this).attr('action'), | |
data: { | |
email: email, | |
password: password, | |
captcha: captcha | |
} | |
}) | |
.then( | |
function success(data) { | |
$this.find("p.response").html(data); | |
$this.find('button[type="submit"]').prop('disabled', true); | |
}, | |
function fail(data, status) { | |
console.error(data + " " + status); | |
} | |
); | |
event.preventDefault(); | |
return false; | |
}); | |
$('#sign-in form').submit(function (event) { | |
var $this = $(this), | |
email = $this.find("input[name='email']").val(), | |
password = $this.find("input[name='password']").val(), | |
captcha = grecaptcha.getResponse(widgetId2); | |
$.ajax({ | |
type: $(this).attr('method'), | |
url: $(this).attr('action'), | |
data: { | |
email: email, | |
password: password, | |
captcha: captcha | |
} | |
}) | |
.then( | |
function success(data) { | |
$this.find("p.response").html(data); | |
$this.find('button[type="submit"]').prop('disabled', true); | |
}, | |
function fail(data, status) { | |
console.error(data + " " + status); | |
} | |
); | |
event.preventDefault(); | |
return false; | |
}); | |
$('#reset-password form').submit(function (event) { | |
var $this = $(this), | |
email = $this.find("input[name='email']").val(), | |
captcha = grecaptcha.getResponse(widgetId3); | |
$.ajax({ | |
type: $(this).attr('method'), | |
url: $(this).attr('action'), | |
data: { | |
email: email, | |
captcha: captcha | |
} | |
}) | |
.then( | |
function success(data) { | |
$this.find("p.response").html(data); | |
$this.find('button[type="submit"]').prop('disabled', true); | |
}, | |
function fail(data, status) { | |
console.error(data + " " + status); | |
} | |
); | |
event.preventDefault(); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment