Advertisement
cipher87

CSH Login Register

Apr 19th, 2019
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function custom_login_script(){
  2.   ?>
  3.   <script>
  4.     (function($){
  5.       jQuery(document).ready(function($) {
  6.    
  7.         if (jsPassData.generated_pass == 'on') {
  8.             $("#allow_pass").show();
  9.         }else {
  10.             $("#allow_pass").hide();
  11.         }
  12.  
  13.         $(".go_to_login_link").click(function(e) {
  14.             if (jsPassData.type_modal != 'LinkToDefault') {
  15.                 e.stopPropagation();
  16.                 e.preventDefault();
  17.                 var offset = $( this ).offset();
  18.  
  19.                 if ($("#csh-login-wrap").css("display") == "none") {
  20.                     var windowsize = $(window).width();
  21.                     if (jsPassData.type_modal == 'Dropdown') {
  22.                         $("#csh-login-wrap").css('position', 'absolute');
  23.                         $("#csh-login-wrap").css('top', offset.top + 30);
  24.                         $("#csh-login-wrap").css('left', offset.left);
  25.                     }
  26.  
  27.                     $("#csh-login-wrap").slideToggle(250);
  28.                     $(".login_form").show();
  29.                     $("#login_user").focus();
  30.                     $(".register_form").hide();
  31.                     $(".lost_pwd_form").hide();
  32.                     $(".back_login").hide();
  33.                     $(".alert_status").hide();
  34.                 }else {
  35.                     $("#csh-login-wrap").slideUp(200);
  36.                 }
  37.  
  38.                 //clear form fields
  39.                 //$(".login_form").find("input[type=text],input[type=email],input[type=password],textarea").val("");
  40.                 $(".register_form").find("input[type=text],input[type=email],input[type=password],textarea").val("");
  41.                 $(".lost_pwd_form").find("input[type=email],textarea").val("");
  42.  
  43.                 //clear validation.
  44.                 var login_validator = $(".login_form").validate();
  45.                 login_validator.resetForm();
  46.             }
  47.         });
  48.        
  49.         $(".menu_register_link").click(function(e) {
  50.             if (jsPassData.type_modal != 'LinkToDefault') {
  51.                 e.stopPropagation();
  52.                 e.preventDefault();
  53.                 var offset = $( this ).offset();
  54.                 var windowsize = $(window).width();
  55.                 if (jsPassData.type_modal == 'Dropdown') {
  56.                     $("#csh-login-wrap").css('position', 'absolute');
  57.                     $("#csh-login-wrap").css('top', offset.top + 30);
  58.                     $("#csh-login-wrap").css('left', offset.left);
  59.                 }
  60.  
  61.                 $("#csh-login-wrap").slideToggle(250);
  62.                 $(".login_form").hide();
  63.                 $(".register_form").show();
  64.                 $("#register_user").focus();
  65.                 $(".lost_pwd_form").hide();
  66.                 $(".back_login").show();
  67.                 $(".alert_status").hide();
  68.                 //clear form fields
  69.                 $(".register_form").find("input[type=text],input[type=email],input[type=password],textarea").val("");
  70.                 $(".lost_pwd_form").find("input[type=email],textarea").val("");
  71.  
  72.                 //clear validation.
  73.                 var register_validator = $(".register_form").validate();
  74.                 register_validator.resetForm();
  75.  
  76.             }
  77.         });
  78.  
  79.         $(document).keydown(function(e) {
  80.             if (e.keyCode === 27) {
  81.                 e.stopPropagation();
  82.                 $("#csh-login-wrap").slideUp(200);
  83.             }
  84.         });
  85.  
  86.         var mouse_is_inside = false;
  87.         $('.login_dialog').hover(function() {
  88.             mouse_is_inside = true;
  89.         }, function() {
  90.             mouse_is_inside = false;
  91.         });
  92.  
  93.         $("body").mousedown(function(e) {
  94.             if (e.which == 1) {
  95.                 if (!mouse_is_inside) {
  96.                     $('#csh-login-wrap').slideUp(200);
  97.                 }
  98.             }
  99.         });
  100.  
  101.         $('.boxclose').click(function() {
  102.             $("#csh-login-wrap").slideUp(200);
  103.         });
  104.         //Login form
  105.         $(".go_to_register_link").click(function(e) {
  106.             e.preventDefault();
  107.             e.stopPropagation();
  108.             $(".login_form").hide();
  109.             $(".lost_pwd_form").hide();
  110.             $(".register_form").show();
  111.             $("#register_user").focus();
  112.             $(".back_login").show();
  113.             $(".alert_status").hide();
  114.  
  115.             //clear validation.
  116.             var register_validator = $(".register_form").validate();
  117.             register_validator.resetForm();
  118.         });
  119.  
  120.         $(".go_to_lostpassword_link").click(function(e) {
  121.             e.preventDefault();
  122.             e.stopPropagation();
  123.             $(".login_form").hide();
  124.             $(".lost_pwd_form").show();
  125.             $("#lost_pwd_user_email").focus();
  126.             $(".register_form").hide();
  127.             $(".back_login").show();
  128.             $(".alert_status").hide();
  129.  
  130.             //clear validation.
  131.             var lostpwd_validator = $(".lost_pwd_form").validate();
  132.             lostpwd_validator.resetForm();
  133.         });
  134.  
  135.         $(".back_login").click(function(e) {
  136.             e.preventDefault();
  137.             e.stopPropagation();
  138.             $(".login_form").show();
  139.             $("#login_user").focus();
  140.             $(".register_form").hide();
  141.             $(".lost_pwd_form").hide();
  142.             $(".back_login").hide();
  143.             $(".alert_status").hide();
  144.         });
  145.         //validate form.
  146.         $('.login_form').removeData('validator');
  147.         $('.register_form').removeData('validator');
  148.         $('.lost_pwd_form').removeData('validator');
  149.  
  150.         $('.login_form').removeData('unobtrusiveValidation');
  151.         $('.register_form').removeData('unobtrusiveValidation');
  152.         $('.lost_pwd_form').removeData('unobtrusiveValidation');
  153.  
  154.         var login_form = $(".login_form");
  155.         login_form.validate({
  156.             invalidHandler: function(form, validator) {
  157.                 var errors = validator.numberOfInvalids();
  158.                 if (errors) {
  159.                     $('.alert_status').show();  
  160.                     $('.alert_status').val(validator.errorList[0].message);
  161.                     validator.errorList[0].element.focus(); //Set Focus
  162.                 }
  163.             },
  164.             rules: {
  165.                 login_user: {
  166.                     required: true,
  167.                 },
  168.                 pass_user: {
  169.                     required: true,
  170.                     minlength: 6
  171.                 },
  172.             },
  173.             messages: {
  174.                 login_user: {required: "Enter your name"},
  175.                 pass_user: {required: "Enter your Password", minlength:"At least 6 characters"}                        
  176.             },
  177.             errorPlacement: function(error, element) {
  178.                 //Nothing
  179.             }
  180.         });
  181.  
  182.         var register_form = $(".register_form");
  183.         register_form.validate({
  184.             invalidHandler: function(form, validator) {
  185.                 var errors = validator.numberOfInvalids();
  186.                 if (errors) {
  187.                     $('.alert_status').show();  
  188.                     $('.alert_status').val(validator.errorList[0].message);
  189.                     validator.errorList[0].element.focus(); //Set Focus
  190.                 }
  191.             },
  192.             rules: {
  193.                 register_user: {
  194.                     required: true,
  195.                 },
  196.                 register_email: {
  197.                     required: true,
  198.                     email: true,
  199.                 },
  200.                 register_pass: {
  201.                     required: true,
  202.                     minlength: 6
  203.                 },
  204.                 confirm_pass: {
  205.                     required: true,
  206.                     minlength: 6,
  207.                     equalTo: "#register_pass",
  208.                 },
  209.             },
  210.             messages: {
  211.                 register_user: {required: "Enter your name"},
  212.                 register_email: {required: "Enter the email",email: "Invalid email address" },
  213.                 register_pass: {required: "Enter the password.",minlength:"At least 6 characters"},
  214.                 confirm_pass: {required: "Enter the password confirm.",equalTo:"Confirm password not match"}                        
  215.             },
  216.             errorPlacement: function(error, element) {
  217.                 //
  218.             }
  219.         });
  220.  
  221.         var lost_pwd_form = $(".lost_pwd_form");
  222.         lost_pwd_form.validate({
  223.             invalidHandler: function(form, validator) {
  224.                 var errors = validator.numberOfInvalids();
  225.                 if (errors) {
  226.                     $('.alert_status').show();  
  227.                     $('.alert_status').val(validator.errorList[0].message);
  228.                     validator.errorList[0].element.focus(); //Set Focus
  229.                 }
  230.             },
  231.             rules: {
  232.                 lost_pwd_user_email: {
  233.                     required: true,
  234.                 },
  235.             },
  236.             messages: {
  237.                 lost_pwd_user_email: {required: "Enter your E-mail"},                    
  238.             },
  239.             errorPlacement: function(error, element) {
  240.                 //
  241.             }
  242.         });
  243.         //login form ajax.
  244.         $(".login_submit").click(function(e) {
  245.             e.preventDefault();
  246.             e.stopPropagation();
  247.             if (login_form.valid()) {
  248.                 var user = $("#login_user").val();
  249.                 var password = $("#pass_user").val();
  250.                 var rememberme = $("#rememberme").val();
  251.                 var arlet_string = '';
  252.                 $(".alert_status").hide();
  253.                 $.ajax({
  254.                     type: 'POST',
  255.                     data: {
  256.                         'action': 'cshlg_login_submit',
  257.                         'user': user,
  258.                         'password': password,
  259.                         'rememberme': rememberme,
  260.                     },
  261.                     url: jsPassData.ajax_url,
  262.                     success: function(data) {
  263.                         if (data.login_status == "OK") {
  264.                             arlet_string = jsPassData.login_success;
  265.                             $(".alert_status").val(arlet_string);
  266.                             $(".alert_status").addClass('alert-success');
  267.                             $(".alert_status").show();
  268.  
  269.                             if (jsPassData.get_login_redirect == 'Home Page') {
  270.                                 $(".login_form").attr('action', jsPassData.login_redirect);
  271.                                 $(".login_form").submit();
  272.                             }
  273.  
  274.                             if (jsPassData.get_login_redirect == 'Current Page') {
  275.                                 $(".login_form").attr('action', "");
  276.                                 $(".login_form").submit();
  277.                             }
  278.  
  279.                             if (jsPassData.get_login_redirect == 'Custom URL') {
  280.                                 window.location.href = jsPassData.login_redirect;
  281.                             }
  282.                         }else {
  283.                             console.log(data.login_status);
  284.                             arlet_string = jsPassData.login_error;
  285.                             $(".alert_status").val(arlet_string);
  286.                             $(".alert_status").addClass('alert-error');
  287.                             $(".alert_status").show();
  288.                         }
  289.                     },
  290.                     error: function(jqXHR, textStatus, errorThrown) {
  291.                         // Handle any errors
  292.                     }
  293.                 });
  294.             }
  295.         });
  296.  
  297.         //register form ajax.
  298.         $("#register_submit").click(function(e) {
  299.             e.preventDefault();
  300.             e.stopPropagation();
  301.             if (register_form.valid()) {
  302.                 var register_user = $("#register_user").val();
  303.                 var register_email = $("#register_email").val();
  304.                 var password_register = $("#register_pass").val();
  305.                 var repass_register = $("#confirm_pass").val();
  306.  
  307.                 //gcaptcha data
  308.                 var dataArray = $("#register_form").serializeArray(),
  309.                     len = dataArray.length,
  310.                     dataObj = {};
  311.                 for (i=0; i<len; i++) {
  312.                 dataObj[dataArray[i].name] = dataArray[i].value;
  313.                 }
  314.  
  315.                 var arlet_string = '';
  316.                 $(".alert_status").hide();
  317.                 $.ajax({
  318.                     type: 'POST',
  319.                     data: {
  320.                         'action': 'cshlg_register_submit',
  321.                         'register_user': register_user,
  322.                         'register_email': register_email,
  323.                         'password_register': password_register,
  324.                         'g-recaptcha-response': dataObj['g-recaptcha-response'],
  325.                     },
  326.                     url: jsPassData.ajax_url,
  327.                     success: function(data) {
  328.                         if (data.captcha == 'INCORRECT') {
  329.                             arlet_string = 'Captcha is required!';
  330.                             $(".alert_status").val(arlet_string);
  331.                             $(".alert_status").show();
  332.                         }else {
  333.                             if (data.register_status == "OK") {
  334.                                 if (jsPassData.generated_pass == 'on') {
  335.                                     arlet_string = 'Register Successfull!';
  336.                                 }else{
  337.                                     arlet_string = 'Register Successfull, Check your E-mail';
  338.                                 }
  339.  
  340.                                 $(".alert_status").val(arlet_string);
  341.                                 $(".alert_status").show();
  342.                                 setTimeout(function() {
  343.                                 window.location = jsPassData.register_redirect;
  344.                                 }, 2000);
  345.                             }else {
  346.                                 if (data.register_status == 'ERRORMAIL') {
  347.                                     arlet_string = 'Sorry! We cant sent email for you';
  348.                                 }else{
  349.                                     arlet_string = 'Email already exists';
  350.                                 }
  351.                                 $(".alert_status").val(arlet_string);
  352.                                 $(".alert_status").show();
  353.                             }
  354.                         }
  355.                        
  356.                     },
  357.                     error: function(jqXHR, textStatus, errorThrown) {
  358.                         // Handle any errors
  359.                     }
  360.                 });
  361.             }
  362.         });
  363.  
  364.         //lost password form.
  365.         $("#lost_pwd_submit").click(function(e) {
  366.             e.preventDefault();
  367.             e.stopPropagation();
  368.             if (lost_pwd_form.valid()) {
  369.                 var lost_pwd_user_email = $("#lost_pwd_user_email").val();
  370.                 var arlet_string = '';
  371.                 $(".alert_status").hide();
  372.                 $.ajax({
  373.                     type: 'POST',
  374.                     data: {
  375.                         'action': 'cshlg_lost_pwd_submit',
  376.                         'lost_pwd_user_email': lost_pwd_user_email,
  377.                     },
  378.                     url: jsPassData.ajax_url,
  379.                     success: function(data) {
  380.                         if (data.lost_pwd_status == "OK") {
  381.                             arlet_string = 'Check your email for a link to reset your password. ';
  382.                             $(".alert_status").val(arlet_string);
  383.                             $(".alert_status").show();
  384.                         }else {
  385.                             if (data.lost_pwd_status == 'ERRORMAIL') {
  386.                                 arlet_string = 'Cant sent Email';
  387.                             }else{
  388.                                 arlet_string = 'Not registered User or Email';
  389.                             }
  390.                             $(".alert_status").val(arlet_string);
  391.                             $(".alert_status").show();
  392.                         }
  393.                     },
  394.                     error: function(jqXHR, textStatus, errorThrown) {
  395.                         // Handle any errors
  396.                     }
  397.                 });
  398.             }
  399.         });
  400.  
  401.         //for login facebook.
  402.         if (window.location.hash == '#_=_'){
  403.             // Check if the browser supports history.replaceState.
  404.             if (history.replaceState) {
  405.                 // Keep the exact URL up to the hash.
  406.                 var cleanHref = window.location.href.split('#')[0];
  407.                 // Replace the URL in the address bar without messing with the back button.
  408.                 history.replaceState(null, null, cleanHref);
  409.  
  410.             }else {
  411.                 // Well, you're on an old browser, we can get rid of the _=_ but not the #.
  412.                 window.location.hash = '';
  413.  
  414.             }
  415.         }
  416.  
  417.         $(document).find('input.cshlg-inline-css[type=hidden]').each(function () {
  418.         var _this = $(this);
  419.             $('head').append("<style>"+_this.val()+"</style>");
  420.             _this.remove();
  421.         });
  422.  
  423.         });
  424.     })(jQuery);
  425.   </script>
  426.   <?php
  427. }
  428. add_action('wp_footer', 'custom_login_script');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement