$.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content') } }); $.ajaxPrefilter(function(options, originalOptions, jqXHR){ if (options.type.toLowerCase() === "post") { if(typeof options.data === "object") { options.data.append("csrf_token", $('meta[name="csrf_token"]').attr('content')); } else { // initialize `data` to empty string if it does not exist options.data = options.data || ""; // add leading ampersand if `data` is non-empty options.data += options.data?"&":""; // add _token entry options.data += "csrf_token=" + encodeURIComponent($('meta[name="csrf_token"]').attr('content')); } } }); var forgotpass = (function ($, window, jQuery) { return { "validate" : { "email" : function(){ var email = $('#email').val().trim(); if(email == '') { $('#email').focus(); $('#emailerror').html('Ce champ est obligatoire'); } else { $.ajax({ url : authentication.get_vars().baseurl+"check_email", type : "POST", data : { email : email }, beforeSend : function(){ $('#loading').addClass('loader'); $("#email").prop('disabled', true).css("cursor", "wait"); $("#sendemail").prop('disabled', true).css("cursor", "wait"); }, success : function(result){ $('#loading').removeClass('loader'); if(result.mtype == 'error'){ $('#emailerror').html(""+result.message+""); $('#loading').removeClass('loader'); $("#email").prop('disabled', false).css("cursor", "text"); $("#sendemail").prop('disabled', false).css("cursor", "pointer"); } else { $('#emailerror').hide(); $('div#forgotpass-content').html("").html( '
'+ '
'+ '

Message envoyé avec succè!

'+ '
'+ '
'+ '

Vérifier votre adresse électronique afin de réinitialiser votre mot de passe

' + '' + authentication.get_vars().login.back_to_homepage + '' + '
'+ '
' ); } } }); } }, "_code" : function(){ var code = $('#code').val().trim(), email = $("#reset_code_form").data("email"); if(code == '') { $('#codeerror').html('Inscrivez le code qui se trouve sur votre email'); } else { $.ajax({ url : authentication.get_vars().baseurl+"check_code", type : "POST", data : { code : code, email : email }, success : function(result){ if(result.mdata == 1){ window.location.href = authentication.get_vars().baseurl+"reset_password_page?email="+email; } else if(result.mdata == 0){ alert(result.message); } else { $('#codeerror').html(result.message); } } }); } } }, "update_password" : function(){ var password = $("#password").val().trim(); var password2 = $("#confirmpass").val().trim(), email = $("#reset_password_form").data("email"); if(password != '' && password2 != ''){ if(password != password2){ $("#error-mismatch").html("Les mots de passe ne correspondent pas"); } else { $.ajax({ url : authentication.get_vars().baseurl+"new_password", type : "POST", data : { email : email, password : password }, success : function(result){ $('#reset-password').html( '
'+ '
'+ "

Le mot de passe a été modifié!

" + '
'+ '
'+ "

Redirection vers la page de connexion

"+ '
'+ '
' ); setTimeout(function(){ window.location.href = authentication.get_vars().baseurl+"login"; }, 5000); } }); } } } }; // Pass in jQuery. })(jQuery, this); $(function() { $('#email').focus(); // Send Email $("#sendemail").click(function(){ // $this.disabled = true; forgotpass.validate.email(); }); // Submit Code $("#submitcodebtn").click(function(){ forgotpass.validate._code(); }); // Reset Password $("#submit-newpassword").click(function(){ forgotpass.update_password(); }); });