var USER_LANG = "FR";
var waitMessage = "Veuillez patienter..";
var conErrorMessage = "Impossible d'établire une connexion au serveur.";
function alertGen(message, type){
return '
' + message + '
';
}
let apiV1 = class {
constructor() {
this.endPoint = "//fileservice.bhd-tuning-files.com/api/v1/" + USER_LANG + "/";
}
login(captcha){
$("#ajaxAlert").removeClass("alert-danger alert-success").addClass("alert-info").html(waitMessage);
var email = $("#email").val();
var password = $("#password").val();
if(email != "" && password != ""){
$("#loginBtn").prop("disabled",true);
$.ajax({
url : this.endPoint + "login",
type : 'post',
data : {captcha: captcha, email: email, password: password},
dataType : 'json',
success: function(d) {
$("#loginBtn").prop("disabled",false);
grecaptcha.reset();
if(d.success){
if(USER_LANG == "FR"){
var message = "Vous êtes authentifié(e), redirection..";
}else{
var message = "You are authenticated, redirecting..";
}
$("#ajaxAlert").removeClass("alert-info alert-danger").addClass("alert-success").html(message);
setTimeout(location.reload(), 2000);
}else{
$("#ajaxAlert").removeClass("alert-info alert-success").addClass("alert-danger").html(d.message);
}
$("#captchaImage").attr("src", d.newCaptcha);
},
error: function(e, i) {
grecaptcha.reset();
$("#loginBtn").prop("disabled",false);
$("#ajaxAlert").removeClass("alert-info alert-success").addClass("alert-danger").html(conErrorMessage);
}
});
}else{
$("#loginBtn").prop("disabled",false);
setTimeout(grecaptcha.reset(), 2000);
if(USER_LANG == "FR"){
var errorMessage = "Veuillez remplire tout les champs.";
}else{
var errorMessage = "Please complete all fields.";
}
$("#ajaxAlert").removeClass("alert-info alert-success").addClass("alert-danger").html(errorMessage);
}
}
};
const api = new apiV1();
function recaptchaValidate(token){
api.login(token);
}