Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. <div class="vb-registration-form">
  2. <form data-abide novalidate id="reg-form" class="registration-form">
  3. <!-- The form goes here. I have removed it from this post to avoid making the question too long. -->
  4. <div class="g-recaptcha" data-sitekey="my_sitekey_is_entered_here"></div>
  5. <fieldset class="large-6 columns">
  6. <button class="button" type="submit" id="btn-new-user" value="Submit" display="none">Submit</button>
  7. </fieldset>
  8. <fieldset class="large-6 columns">
  9. <button class="button" type="reset" value="Reset">Reset</button>
  10. </fieldset>
  11. </div>
  12. </div> <!-- close vb-reg form -->
  13. </form>
  14. <div class="row">
  15. <div class="medium-12 columns" id="successfulregistration" style="display:none">
  16. <div class="callout success">
  17. <h2>Thank you for registering.</h2>
  18. <p>Please look for an email from us confirming your registration. We will confirm your account within 3-5 business days.</p>
  19. </div>
  20. </div>
  21. <div class="medium-12 columns" id="unsuccessfulregistration" style="display:none;" >
  22. <div class="callout alert">
  23. <h2>There was a problem...</h2>
  24. <p class="responsemsg"></p>
  25. </div>
  26. </div>
  27. </div>
  28.  
  29. jQuery( document ).ready( function( $ ) {
  30. var form = document.getElementById('reg-form');
  31. /*** When user clicks on button... ***/
  32. $('#btn-new-user').click( function(event) {
  33. var elements = this.elements;
  34. /*** Prevent default action, so when user clicks button he doesn't navigate away from page**/
  35. if (event.preventDefault) {
  36. event.preventDefault();
  37. } else {
  38. event.returnValue = false;
  39. }
  40. // Collect data from inputs
  41. var reg_nonce = $('#vb_new_user_nonce').val();
  42. var reg_user = $('#vb_username').val();
  43. var reg_pass = $('#vb_pass').val();
  44. var reg_mail = $('#vb_email').val();
  45. var first_name = $('#vb_FirstName').val();
  46. var last_name = $('#vb_LastName').val();
  47. var inst_affil = $('#vb_institutionalaffiliation').val();
  48. var location = $('#vb_location').val();
  49. var twitter = $('#vb_twitter').val();
  50. var bio = $('#vb_bio').val();
  51. var captcha_response = $('#g-recaptcha-response').val();
  52. var checkboxValues = [];
  53. $('input[name=signup]:checked').map(function() {
  54. checkboxValues.push($(this).val());
  55. });
  56. console.log(checkboxValues);
  57. /**
  58. * AJAX URL where to send data
  59. * (from localize_script)
  60. */
  61. var ajax_url = vb_reg_vars.vb_ajax_url;
  62. // Data to send. The register_user action corresponds to the action in functions.php
  63. data = {
  64. action: 'register_user',
  65. nonce: reg_nonce,
  66. user: reg_user,
  67. pass: reg_pass,
  68. mail: reg_mail,
  69. firstname: first_name,
  70. lastname: last_name,
  71. institution: inst_affil,
  72. location: location,
  73. twitterhandle: twitter,
  74. userbio: bio,
  75. volunteerdates: checkboxValues,
  76. captcha: captcha_response
  77. };
  78. console.log(data);
  79. console.log(data.user);
  80. // Do AJAX request
  81. $.post( ajax_url, data, function(response) {
  82. // If we have response
  83. if( response ) {
  84. if( response === '1' ) {
  85. // If user is created
  86. $('.vb-registration-form').remove();
  87. $('#successfulregistration').show();
  88. console.log(response);
  89. } else {
  90. $('.vb-registration-form').remove();
  91. $('#unsuccessfulregistration').show();
  92. $('.responsemsg').append(response);
  93. console.log(response);
  94. }
  95. }
  96. });
  97. });
  98. });
  99.  
  100. function vb_reg_new_user() {
  101. $privatekey = 'private_key_is_entered_here'
  102. $args = array(
  103. 'body' => array(
  104. 'secret' => $privatekey,
  105. 'response' => stripslashes( esc_html ($_POST["captcha_response"] ) )
  106. ));
  107. $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $args);
  108. $response = json_decode( wp_remote_retrieve_body( $response ), true);
  109. // Verify nonce
  110. if( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'vb_new_user' ) ) {
  111. die( 'Ooops, something went wrong, please try again later.' );
  112. } elseif ( $response != 'True'){
  113. die( 'Captcha error');
  114. } else {
  115. // Post values
  116. $username = $_POST['user'];
  117. $password = $_POST['pass'];
  118. $email = $_POST['mail'];
  119. $fname = $_POST['firstname'];
  120. $lname = $_POST['lastname'];
  121. $instaffil = $_POST['institution'];
  122. $loc = $_POST['location'];
  123. $twitter = $_POST['twitterhandle'];
  124. $bio = $_POST['userbio'];
  125. $voldates = $_POST['volunteerdates'];
  126. $username = sanitize_text_field($username);
  127. $fname = sanitize_text_field($fname);
  128. $lname = sanitize_text_field($lname);
  129. $instaffil = sanitize_text_field($instaffil);
  130. $loc = sanitize_text_field($loc);
  131. $twitter = sanitize_text_field($twitter);
  132. $bio = sanitize_text_field($bio);
  133. $userdata = array(
  134. 'user_login' => $username,
  135. 'user_pass' => $password,
  136. 'user_email' => $email,
  137. 'first_name' => $fname,
  138. 'last_name' => $lname,
  139. 'description' => $bio,
  140. 'role' => 'pending'
  141. );
  142.  
  143. $user_id = wp_insert_user( $userdata ) ;
  144.  
  145. // Return
  146. if( !is_wp_error($user_id) ) {
  147. echo '1';
  148. echo $response['success'];
  149. notifyadmin($email, $username, $fname, $lname);
  150. notifyuser($email, $fname, $lname);
  151. } else {
  152. echo $user_id->get_error_message();
  153. echo $response['success'];
  154. }
  155. add_user_signupmeta($user_id, $voldates);
  156. die();
  157. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement