I have enabled the Facebook re-authentication for my site (done in codeigniter) when the user is visiting a specific page. Here is my code :
$(window).load(function() {
$("a.facebook_reauth_login").on("click", function(e) {
var t = $(this);
e.preventDefault();
FB.usingButton = !0;
var n = base_url;
FB.login(function(e) {
if (e.authResponse) {
FB.api("/me", function(e) {
var t = n + "fbreauth";
$.ajax({
type: "POST",
data: $.param(e),
url: t,
dataType: "html",
success: function(e) { console.log(e);
},
error: function() {
alert("Some error occurred,please try after some time!")
}
})
})
} else {
alert("User cancelled login or did not fully authorize.")
}
}, { auth_type: 'reauthenticate' });
return false
})
});
Now the problem is that the e.authResponse is returning true even if the user dismisses the re-authentication popup without entering the password. How do I verify that the user has entered the password?
Related
I´m traying to do logging in my web with ajax. But i need generated google key when i do click in login, and before to do login. I have this function:
$('#main-login-form').on('submit', function(e){
renewKeyRecaptcha();
//e.preventDefault();
let key = $("#recaptchaResponse").val();
console.log(key);
if(key != null || key != ""){
var $this = $(this);
$(this).find('input').removeClass('is-invalid');
$(this).find('.error').html('');
var data = $this.serializeArray();
data.push({name: 'currentName', value: config.url.currentName});
$.ajax({
type: $this.attr('method'),
url: $this.attr('action'),
data: data,
dataType: $this.data('type'),
success: function (response) {
if(response.success) {
$(location).attr('href', response.redirect);
}
console.log(response);
},
error: function (jqXHR) {
var response = JSON.parse(jqXHR.responseText);
if (response.errors.password) {
$($this).find('input[name="password"]').addClass('is-invalid');
$($this).find('.password-error').html(response.errors.password);
} else if (response.errors.email) {
$($this).find('input[name="email"]').addClass('is-invalid');
$($this).find('.email-error').html(response.errors.email);
} else if (response.errors.gRecaptchaResponse) {
$($this).find('input[name="g-recaptcha-response"]').addClass('is-invalid');
$($this).find('.g-recaptcha-response-error').html(response.errors.gRecaptchaResponse);
}
}
});
}
});
this function call to renewKeyRecaptcha(); that generated key, but i need to do click login twice and before i´m login... i need to do once click in login and generate key and login... But i can´t. I don´t know if i´m doing well or i would do to another way.
My function that generate key:
function renewKeyRecaptcha(){
// add key google to input
var key = config.url.recaptchaGoogle;
grecaptcha.ready(function() {
grecaptcha.execute(key, {action: 'login'}).then(function(token) {
$("#recaptchaResponse").val(token);
$("#recaptchaResponseRegister").val(token);
});
});
}
this function run ok.
Thanks for help.
I resolve my question with:
$("#submitLogin").on("click", function(e){
renewKeyRecaptcha();
e.preventDefault();
setTimeout(function(){
$(this).find('input').removeClass('is-invalid');
$(this).find('.error').html('');
$this = $('#main-login-form');
var data = $this.serializeArray();
data.push({name: 'currentName', value: config.url.currentName});
$.ajax({
type: $this.attr('method'),
url: $this.attr('action'),
data: data,
dataType: $this.data('type'),
success: function (response) {
if(response.success) {
$(location).attr('href', response.redirect);
}
console.log(response);
},
error: function (jqXHR) {
var response = JSON.parse(jqXHR.responseText);
if (response.errors.password) {
$($this).find('input[name="password"]').addClass('is-invalid');
$($this).find('.password-error').html(response.errors.password);
} else if (response.errors.email) {
$($this).find('input[name="email"]').addClass('is-invalid');
$($this).find('.email-error').html(response.errors.email);
} else if (response.errors.gRecaptchaResponse) {
$($this).find('input[name="g-recaptcha-response"]').addClass('is-invalid');
$($this).find('.g-recaptcha-response-error').html(response.errors.gRecaptchaResponse);
}
}
});
}, 3000);
I'm trying to validate an designation name with a remote rules.
On first time form submit by entering test value, form submitted and value bind by ajax. but after second time without refresh page i m trying to submit form by adding same value test which i added. i m not getting error for existing name.
here is the js code
$("#designationaddedit").validate({
rules: {
designation_name: {
required: true,
},
designation_copy_name: {
remote: {
url: base_url + 'Designation/designation_name_exists',
type: "post",
data: {
designation_copy_name: function() {
console.log("1");
return $( "#designation_copy_name" ).val();
}
}
}
},
},
messages: {
designation_name: {
required: "Enter Designation name"
},
designation_copy_name: {
remote: 'Designation name is already exists.'
},
},
});
$(document).on('submit', '#designationaddedit', function(event) {
event.preventDefault();
var designation_id = $('#designation_id').val();
var designation_name = $('#designation_name').val();
var action = $('#action').val();
var table = $('#designationTable').DataTable();
var info = table.page.info();
var currentpage = info.start;
if ($("#designationaddedit").valid()) {
$('.preloader').show();
$.ajax({
url: base_url + 'designation/add',
type: 'POST',
dataType: 'json',
data: { submit: 1, designation_id: designation_id, designation_name: designation_name, action: action },
success: function(response) {
$('.preloader').hide();
if (response.success == 1) {
$("#designation_model").modal('hide');
} else {
}
}
});
}
})
below code fixed my issue. I hope it's help you.
remote: { url: "http:url.com", type: "post", data: { USER_ID: userid }, async: false, // set async = false }
I want to show a notification modal when i submit a form.but unfortunately the modal is not popping up here is the code
$("#submitmodalRetailer").submit(function() {
var FirstName = $('#FirstNameRetailer').val();
var LastName = $('#LastNameRetailer').val();
var QRCodeRetailer = $('#QRCodeRetailer').val();
var prefixNumberRetailers = $('#prefixNumberRetailer').val();
var Retailer7Digits = $('#Retailer7Digit').val();
$.ajax({
type: "POST",
url: "addRetailer.php",
data: $('form.form-modal-retailer').serialize(),
success: function(msg) {
$("#RetailerAdd").modal('hide');
location.reload();
if (msg == 'Valid') {
$("#RetailerAddshow").modal('show');
} else if (msg == 'AlreadyExists') {
$("#BarcodeExists").modal();
} else if (msg == 'Invalid') {
alert('Your Barcode number is invalid. \n User only 100001 to 199999')
}
},
error: function() {
alert("failure");
}
});
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
You may remove
location.reload();
in Ajax success method to avoid page reload that hinder popup from showing up.
and also you can add
e.preventDefault();
in the button click event to prevent the form submit to cause reloading that may also hinder popup from showing.
and you need to add e as a parameter to event.
$("#submitmodalRetailer").submit(function(e) {.
e.preventDefault();
var FirstName = $('#FirstNameRetailer').val();
var LastName = $('#LastNameRetailer').val();
var QRCodeRetailer = $('#QRCodeRetailer').val();
var prefixNumberRetailers = $('#prefixNumberRetailer').val();
var Retailer7Digits = $('#Retailer7Digit').val();
$.ajax({
type: "POST",
url: "addRetailer.php",
data: $('form.form-modal-retailer').serialize(),
success: function(msg) {
$("#RetailerAdd").modal('hide');
// location.reload();
if (msg == 'Valid') {
$("#RetailerAddshow").modal('show');
} else if (msg == 'AlreadyExists') {
$("#BarcodeExists").modal();
} else if (msg == 'Invalid') {
alert('Your Barcode number is invalid. \n User only 100001 to 199999')
}
},
error: function() {
alert("failure");
}
});
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
You need to prevent the default action of the submit button.
Use preventDefault().
Read about it here: https://api.jquery.com/event.preventdefault/
$("#submitmodalRetailer").submit(function (e) {
e.preventDefault();
});
I integrate google and Facebook login to my website. And set a condition either a person can log in with FB or with google. Now the problem is my google login function automatically works if my gmail account is open in the same browser.
function loggedOut(href){
gapi.load('auth2', function() {
gapi.auth2.init();
});
setTimeout(function(){
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
//console.log('User signed out.');
document.location = href;
});
}, 2000);
}
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
var fullName = profile.getName(),
imageUrl = profile.getImageUrl(),
email = profile.getEmail(),
provider = 'Google';
$.ajax({
url: 'includes/google-login.php',
type: 'POST',
data: { provider: provider, fullName :fullName, imageUrl : imageUrl, email: email },
success: function(data){
console.log(data);
if(data == 1){
location.reload();
} else if(data.trim().match("^Entered")){
alert(data);
loggedOut('This Page URL');
}
}
});
};
$('#log-out').on('click', function(e){
e.preventDefault();
var href = $(this).attr('href');
loggedOut(href);
});
var auth2 = gapi.auth2.getAuthInstance();
Put this inside a function , called login and call it only on user click on login button. That should prevent google from automatically detecting user . Or you can remove this line totally.
I am having an issue trying to keep a cretin window toggled opened after AJAX retrieves data, to show a proper message to denote weather or not the user has logged in or not.
My Javascript is as follows:
function validLogin(){
var username=$('#username').val();
var password=$('#password').val();
var dataString = 'username='+ username + '&password='+ password;
$("#flash").show();
$("#flash").fadeIn(400).html('<img src="images/loading.gif" width="32px" height="32px" />');
$.ajax({
type: "POST",
url: "login.php",
data: dataString,
cache: true,
success: function(result){
var result=trim(result);
$("#flash").hide();
if(result=='correct'){
$("fieldset#signin_menu").show(); // <-- This will not work!
}else{
$("#errorMessage").html(result);
}
}
After I get the informatoin the window should stay open; however, the page refreshes and the window closes. This is an onclick event once you press "Sign In". A window will pop down. Here is the code for that window popping down:
$(document).ready(function() {
$(".signin").click(function(e) {
e.preventDefault();
$("fieldset#signin_menu").toggle();
$(".signin").toggleClass("menu-open");
});
$("fieldset#signin_menu").mouseup(function() {
return false
});
$(document).mouseup(function(e) {
if($(e.target).parent("a.signin").length==0) {
$(".signin").removeClass("menu-open");
$("fieldset#signin_menu").hide();
}
});
Is there a better work around for this? Am I doing this wrong?
use this jquery instead
$(document).ready(function() {
$("fieldset#signin_menu").show(function() {
$(".signin").toggleClass("menu-open");
});
});
$("fieldset#signin_menu").mouseup(function() {
return false
});
$(document).mouseup(function(e) {
if($(e.target).parent("a.signin").length==0) {
$(".signin").removeClass("menu-open");
$("fieldset#signin_menu").hide();
}
});