You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
241 lines
9.7 KiB
241 lines
9.7 KiB
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
|
|
}
|
|
});
|
|
$.ajaxPrefilter(function(options, originalOptions, jqXHR){
|
|
if (options.type.toLowerCase() === "post") {
|
|
// 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 authentication = (function ($, window, jQuery) {
|
|
var _vars_ = {};
|
|
return {
|
|
|
|
"set_vars" : function (options) {
|
|
$.extend(_vars_, options || {});
|
|
},
|
|
|
|
"get_vars" : function(){
|
|
return _vars_;
|
|
},
|
|
|
|
"validation" : {
|
|
|
|
"login" : function(){
|
|
//your ajax code or DOM manipulation codes here
|
|
var email = $('#email').val().trim();
|
|
var password = $('#password').val().trim();
|
|
if(email != "" && password != "")
|
|
{
|
|
$('#error-email').html('');
|
|
$.ajax({
|
|
url : authentication.get_vars().baseurl+"authenticate",
|
|
type : "POST",
|
|
data : {
|
|
email: email,
|
|
password: password,
|
|
csrf_protection: $('meta[name="csrf_protection"]').attr('content'),
|
|
remember_me : $("input#rememberme_login").prop("checked")
|
|
},
|
|
success : function(result) {
|
|
|
|
switch(result.mdata.redirect)
|
|
{
|
|
case 0: $('#error-password').html(result.message).show();
|
|
$('#error-email').hide();
|
|
$('#password').val('');
|
|
$("#loginbtn").prop("disabled", false);
|
|
break;
|
|
case 1:
|
|
window.location.href = result.mdata.path
|
|
break;
|
|
case 2:
|
|
window.location.href = authentication.get_vars().baseurl;
|
|
break;
|
|
case 5:
|
|
$.notifyDefaults({
|
|
type: "warning",
|
|
allow_dismiss: true,
|
|
z_index: 2031,
|
|
positon : "top"
|
|
});
|
|
$.notify({
|
|
message: result.message,
|
|
icon: "glyphicon glyphicon-exclamation-sign"
|
|
});
|
|
$("#loginbtn").off('click');
|
|
$("#loginbtn").prop("disabled", true);
|
|
window.setTimeout(function(){window.location.href = "https://secure.lemonde.fr/sfuser/connexion";},3000);
|
|
break;
|
|
default: $('#error-password').html(authentication.get_vars().login.err_request);
|
|
}
|
|
}
|
|
}).fail(function() {
|
|
$("#loginbtn").prop("disabled", false);
|
|
});
|
|
}
|
|
else if(email != "" && password == "")
|
|
{
|
|
$("#password").focus();
|
|
$('#error-email').hide();
|
|
$('#error-password').html(authentication.get_vars().login.pwd_required).show();
|
|
$("#loginbtn").prop("disabled", false);
|
|
}
|
|
else if(email == "" && password != "")
|
|
{
|
|
$("#email").focus();
|
|
$('#error-password').html('').hide();
|
|
$('#error-email').html(authentication.get_vars().login.email_request).show();
|
|
$("#loginbtn").prop("disabled", false);
|
|
}
|
|
else {
|
|
$("#email").focus();
|
|
$('#error-email').html(authentication.get_vars().login.email_request).show();
|
|
$('#error-password').html(authentication.get_vars().login.pwd_required).show();
|
|
$("#loginbtn").prop("disabled", false);
|
|
}
|
|
}
|
|
},
|
|
|
|
"create_account" : function() {
|
|
|
|
var first = $('#first_name').val();
|
|
var last = $('#last_name').val();
|
|
var email = $('#email').val();
|
|
var username = $('#username').val();
|
|
|
|
|
|
$.ajax({
|
|
url : authentication.get_vars().baseurl + "signup1",
|
|
type : "POST",
|
|
data : {
|
|
first_name : first,
|
|
last_name : last,
|
|
email : email,
|
|
username : username,
|
|
password : password,
|
|
csrf_protection: $('meta[name="csrf_protection"]').attr('content'),
|
|
},
|
|
success : function(result) {
|
|
alert(result.message);
|
|
$('#first_name').val('');
|
|
$('#last_name').val('');
|
|
$('#email').val('');
|
|
$('#username').val('');
|
|
|
|
}
|
|
});
|
|
},
|
|
|
|
"prevent_page_load" : function(){
|
|
var _cookie_data = decodeURIComponent(authentication.getCookie("_sdllmea"));
|
|
if(_cookie_data.indexOf("logged_in") != -1 && _cookie_data.indexOf("LeMondeFO") != -1){
|
|
history.pushState(null, null, document.url);
|
|
//window.location.href = authentication.get_vars().baseurl;
|
|
}
|
|
else if(_cookie_data.indexOf("logged_in") != -1 && _cookie_data.indexOf("LeMondeBO") != -1){
|
|
history.pushState(null, null, document.url);
|
|
//window.location.href = authentication.get_vars().baseurl;
|
|
}else if(_cookie_data.indexOf("first_logged_in") <= -1){
|
|
//history.pushState(null, null, document.url);
|
|
//window.location.href = authentication.get_vars().baseurl;
|
|
}
|
|
|
|
//history.pushState(null, null, document.url);
|
|
window.addEventListener('popstate', function () {
|
|
var referrer = document.referrer;
|
|
//history.pushState(null, null, document.url);
|
|
var _cookie_data = decodeURIComponent(authentication.getCookie("_sdllmea"));
|
|
|
|
if(_cookie_data.indexOf("logged_in") != -1 && _cookie_data.indexOf("LeMondeFO") != -1){
|
|
window.location.href = authentication.get_vars().baseurl;
|
|
}
|
|
else if(_cookie_data.indexOf("first_logged_in") != -1 && _cookie_data.indexOf("LeMondeFO") != -1){
|
|
window.location.href = authentication.get_vars().baseurl+"set_preference";
|
|
}else{
|
|
//window.location.href = authentication.get_vars().baseurl+"login";
|
|
}
|
|
});
|
|
},
|
|
|
|
"getCookie" : function(name) {
|
|
var value = "; " + document.cookie;
|
|
var parts = value.split("; " + name + "=");
|
|
if (parts.length == 2) return parts.pop().split(";").shift();
|
|
}
|
|
};
|
|
// Pass in jQuery.
|
|
})(jQuery, this);
|
|
|
|
$(function() {
|
|
authentication.prevent_page_load();
|
|
//focus the first field of the form
|
|
// $("#email").focus();
|
|
$('#email').focus('input',function() {
|
|
// $('#email').val(' ');
|
|
// $('#password').val('');
|
|
});
|
|
|
|
$('#loginbtn').bind('click keypress',function(e){
|
|
authentication.validation.login();
|
|
});
|
|
|
|
// Login Button
|
|
// $("#loginbtn").on('click', function(e){
|
|
// $(e.target).prop("disabled", true);
|
|
// authentication.validation.login();
|
|
// $(e.target).prop("disabled", false);
|
|
// });
|
|
//
|
|
// $("#login-form :input").on('keypress', function(e){
|
|
// if(e.keyCode == 13) {
|
|
// $("#login-form :input").blur();
|
|
// authentication.validation.login();
|
|
// }
|
|
// });
|
|
|
|
$("input[type='password'][data-eye]").each(function(i) {
|
|
var $this = $(this);
|
|
|
|
$this.wrap($("<div/>", {
|
|
style: 'position:relative'
|
|
}));
|
|
$this.css({
|
|
paddingRight: 60
|
|
});
|
|
$this.after($("<div/>", {
|
|
html: 'Show',
|
|
class: 'btn btn-primary btn-sm',
|
|
id: 'passeye-toggle-'+i,
|
|
style: 'position:absolute;right:10px;top:50%;transform:translate(0,-50%);padding: 2px 7px;font-size:12px;cursor:pointer;'
|
|
}));
|
|
$this.after($("<input/>", {
|
|
type: 'hidden',
|
|
id: 'passeye-' + i
|
|
}));
|
|
$this.on("keyup paste", function() {
|
|
$("#passeye-"+i).val($(this).val());
|
|
});
|
|
$("#passeye-toggle-"+i).on("click", function() {
|
|
if($this.hasClass("show")) {
|
|
$this.attr('type', 'password');
|
|
$this.removeClass("show");
|
|
$(this).removeClass("btn-outline-primary");
|
|
}else{
|
|
$this.attr('type', 'text');
|
|
$this.val($("#passeye-"+i).val());
|
|
$this.addClass("show");
|
|
$(this).addClass("btn-outline-primary");
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|