function for_login(){ $('#login_msg').removeClass('success-message').removeClass('fail-message'); dataString = "action=user__LOGIN_EMAIL&email="+encodeURIComponent($("#login_email").val())+"&login_pw="+encodeURIComponent($("#login_pw").val()); $.ajax({ type: "POST", url: "/caj/sign_ajax.php", data: dataString, cache: false, success: function(data){ if (data == "true"){ $('#login_msg').addClass('success-message').html("Login Success"); setTimeout(function(){ window.location.href = "/"; }, 1000); }else if (data == "true_but_email_not_verified"){ window.location.href = "/general/email_verification.php"; } else if (data == "false"){ $('#login_msg').addClass('fail-message').html("Login Failed. Please try again."); } } }); } function basicAPIRequest() { FB.api('/me', { fields: "id, name, age_range, gender, locale, picture.width(500).height(500), timezone, email, friends" }, function(response) { dataString = "action=facebook_login_N_registration&facebook_email="+response.email+"&display_name="+response.name+"&gender="+response.gender+"&fb_id="+response.id+"&age_max="+response.age_range.max+"&age_min"+response.age_range.min; $.ajax({ type: "POST", url: "/caj/fb_ajax.php", data: dataString, cache: false, success: function(data){ window.location.reload(); } }); } ); } $(document).ready(function(){ window.fbAsyncInit = function() { FB.init({ appId : 249933008675785, xfbml : true, version : 'v2.6', cookie : true, oauth: true }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); $("#login_fb").click(function(e){ if(typeof(FB) == "undefined") { alert("Facebook SDK not yet loaded please wait."); } FB.getLoginStatus(function(response) { if (response.status === 'connected') { basicAPIRequest(); } else { FB.login(function(response) { if (response.authResponse) { basicAPIRequest(); } else { window.location.reload(); } }, { scope: 'email' }); } }); }); forgot_pw(); $('#email_login_button').click(function(){ var email = $('#login_email').val(); var is_email_check = email.indexOf("@"); if (is_email_check > 0){ if (loginAttempt() == true){ for_login(); } else{ return loginAttempt(); } } else{ for_login(); } }); }) $(document).keypress(function(e) { if(e.which == 13) { loginAttempt(); } }) function loginAttempt(){ $('.pop-message').html(''); var email = $('#login_email').val(); var password = $('#login_pw').val(); if(validateEmail(email)){ /* login with php function if success, redirect immediately if failed, load below js: $('.pop-meesage').addClass('fail-message').html("Login Failed. Please try again.") $('#login-email').val(''); $('#login-pw').val(''); */ return true; } else{ $('#login_msg').addClass('fail-message').html("Please enter correct email.") $('#login_email').val(''); $('#login_pw').val(''); return false; } } function validateEmail(email){ var emailRegex = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i; var emailValid = emailRegex.test(email); if(emailValid){ return true; }else{ return false; } } function forgot_pw(){ $('#forgot_pw').click(function(){ $('#forgot_pw_modal').fadeIn(); }) $('#cancel_pw_button, .modal-close').click(function(){ $('#email_for_reset').val(''); $('#forgot_pw_modal').fadeOut(); $('.pop-message').html(''); }) $('#send_pw_button').click(function(){ $('.pop-message').html(''); var email = $('#email_for_reset').val(); console.log('forget'); if(validateEmail(email)){ /* send reset password email with php function */ console.log(true); dataString = "action=user__forgetPW_N_sendEmail&email="+$("#email_for_reset").val(); console.log(dataString); $.ajax({ type: "POST", url: "/caj/sign_ajax.php", data: dataString, cache: false, success: function(data){ if(data){ alert('Reset password email is successfully sent.'); $('#email_for_reset').val(''); $('#forgot_pw_modal').fadeOut(); }else{ console.log('Something wrong'); } } }); } else{ $('#forgot_pw_msg').addClass('fail-message').html("Please enter correct email.") $('#email_for_reset').val(''); } }) }