Changeset 3826948
- Timestamp:
- 11/26/2026 12:42:46 PM (less than one hour ago)
- Location:
- ajax-login-registration
- Files:
-
- 16 edited
- 1 copied
-
tags/1.0.5 (copied) (copied from ajax-login-registration/trunk )
-
tags/1.0.5/README.txt (modified) (3 diffs)
-
tags/1.0.5/admin/partials/ajax-login-registration-setting.php (modified) (1 diff)
-
tags/1.0.5/ajax-login-registration.php (modified) (1 diff)
-
tags/1.0.5/includes/class-ajax-login-registration.php (modified) (1 diff)
-
tags/1.0.5/public/class-ajax-login-registration-public.php (modified) (18 diffs)
-
tags/1.0.5/public/js/ajax-login-registration-public.js (modified) (1 diff)
-
tags/1.0.5/public/templates/ajax-login-form.php (modified) (5 diffs)
-
tags/1.0.5/public/templates/ajax-registration-form.php (modified) (4 diffs)
-
trunk/README.txt (modified) (3 diffs)
-
trunk/admin/partials/ajax-login-registration-setting.php (modified) (1 diff)
-
trunk/ajax-login-registration.php (modified) (1 diff)
-
trunk/includes/class-ajax-login-registration.php (modified) (1 diff)
-
trunk/public/class-ajax-login-registration-public.php (modified) (18 diffs)
-
trunk/public/js/ajax-login-registration-public.js (modified) (1 diff)
-
trunk/public/templates/ajax-login-form.php (modified) (5 diffs)
-
trunk/public/templates/ajax-registration-form.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ajax-login-registration/tags/1.0.5/README.txt
r3277009 r3826948 3 3 Tags: ajax login, ajax registration, ajax login registration, wp ajax login, wp ajax registration 4 4 Requires at least: 6.5 5 Tested up to: 6.86 Requires PHP: 7. 27 Stable tag: 1.0. 45 Tested up to: 7.1 6 Requires PHP: 7.4 7 Stable tag: 1.0.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 32 32 33 33 == Changelog == 34 = 1.0.1 = 35 First release 34 = 1.0.5 = 35 * Security: Fixed password reset link poisoning vulnerability. 36 * Security: Fixed insecure password reset token validation. 37 * Security: Enforced server-side password reset token expiration. 38 * Security: Improved registration activation link security. 39 * Thanks to Muni Nitish Kumar Yaddala and the WPScan / Jetpack security team for reporting the vulnerabilities. 36 40 37 = 1.0. 2=41 = 1.0.4 = 38 42 Test compatibility of plugin with latest version of WordPress 39 43 … … 41 45 Add blueprints json file for plugin preview button 42 46 43 = 1.0. 4=47 = 1.0.2 = 44 48 Test compatibility of plugin with latest version of WordPress 49 50 = 1.0.1 = 51 First release 45 52 46 53 == Upgrade Notice == -
ajax-login-registration/tags/1.0.5/admin/partials/ajax-login-registration-setting.php
r2064898 r3826948 44 44 <th scope="row"><label for="registration_email">Registration Email</label></th> 45 45 <td><?php wp_editor( get_option('registration_email'), 'registration_email', array( 'textarea_rows' => 8 ) ); ?> 46 <p class="description">User get this email after registration. In the email template, you can use these mail-tags:<br /><code>[FIRSTNAME]</code> <code>[LASTNAME]</code> <code>[ACTIVATION_LINK]</code> <code>[USERNAME]</code> </p></td>46 <p class="description">User get this email after registration. In the email template, you can use these mail-tags:<br /><code>[FIRSTNAME]</code> <code>[LASTNAME]</code> <code>[ACTIVATION_LINK]</code> <code>[USERNAME]</code> <code>[USER_EMAIL]</code></p></td> 47 47 </tr> 48 48 <tr> -
ajax-login-registration/tags/1.0.5/ajax-login-registration.php
r3277009 r3826948 7 7 * Plugin URI: https://www.hktechnolab.com/ 8 8 * Description: Ajax login & registration with email template confirmation 9 * Version: 1.0. 49 * Version: 1.0.5 10 10 * Author: Ravi Gadhiya 11 11 * Author URI: https://profiles.wordpress.org/ravigadhiyawp -
ajax-login-registration/tags/1.0.5/includes/class-ajax-login-registration.php
r3260091 r3826948 59 59 { 60 60 $this->plugin_name = 'ajax-login-registration'; 61 $this->version = '1.0. 0';61 $this->version = '1.0.5'; 62 62 63 63 $this->load_dependencies(); -
ajax-login-registration/tags/1.0.5/public/class-ajax-login-registration-public.php
r3260091 r3826948 111 111 } 112 112 113 //Generate Random String 114 public function generateRandomString($length = 20) 115 { 116 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 117 $charactersLength = strlen($characters); 118 $randomString = ''; 119 for ($i = 0; $i < $length; $i++) { 120 $randomString .= $characters[rand(0, $charactersLength - 1)]; 121 } 122 return $randomString; 123 } 113 // Resolve a published shortcode page using WordPress-owned URLs only. 114 private function form_page_url( $field, $shortcode ) { 115 $id = absint( $this->request_string( $_POST, $field ) ); 116 $page = get_post( $id ); 117 if ( ! $page || 'publish' !== $page->post_status || ! has_shortcode( $page->post_content, $shortcode ) ) { 118 return ''; 119 } 120 $url = get_permalink( $page ); 121 $site = wp_parse_url( home_url( '/' ) ); 122 $target = wp_parse_url( $url ); 123 if ( ! $url || empty( $target['host'] ) || empty( $site['host'] ) || strtolower( $target['host'] ) !== strtolower( $site['host'] ) || ( $target['scheme'] ?? '' ) !== ( $site['scheme'] ?? '' ) || ( $target['port'] ?? null ) !== ( $site['port'] ?? null ) ) { 124 return ''; 125 } 126 return $url; 127 } 128 129 private function request_string( $source, $key ) { 130 return isset( $source[$key] ) && is_string( $source[$key] ) ? wp_unslash( $source[$key] ) : ''; 131 } 132 133 public function generateRandomString( $length = 20 ) { 134 return wp_generate_password( $length, false, false ); 135 } 136 137 // Shared by the reset form and AJAX handler. Legacy tokens are rejected. 138 private function validate_reset_token( $user_id, $token ) { 139 $user = get_user_by( 'id', $user_id ); 140 $issued = (int) get_user_meta( $user_id, 'alr_reset_issued', true ); 141 if ( ! $user || '' === $token || ! $issued || $issued > time() || time() - $issued >= HOUR_IN_SECONDS ) { 142 return false; 143 } 144 $key_parts = explode( ':', $user->user_activation_key, 2 ); 145 if ( count( $key_parts ) !== 2 || ! ctype_digit( $key_parts[0] ) || time() - (int) $key_parts[0] >= HOUR_IN_SECONDS || (int) $key_parts[0] > time() ) { 146 return false; 147 } 148 $verified = check_password_reset_key( $token, $user->user_login ); 149 return ! is_wp_error( $verified ) && (int) $verified->ID === (int) $user_id ? $verified : false; 150 } 124 151 125 152 /** … … 141 168 { 142 169 $response = array(); 143 $username = $ _POST['username'];144 $firstname = $ _POST['firstname'];145 $lastname = $ _POST['lastname'];146 $email = $ _POST['email'];147 $signup_page = $_POST['signup_page'];148 $signup_nonce = $ _POST['signup_nonce'];170 $username = $this->request_string( $_POST, 'username' ); 171 $firstname = $this->request_string( $_POST, 'firstname' ); 172 $lastname = $this->request_string( $_POST, 'lastname' ); 173 $email = $this->request_string( $_POST, 'email' ); 174 $signup_page = $this->form_page_url( 'signup_page', 'ajax-registration' ); 175 $signup_nonce = $this->request_string( $_POST, 'signup_nonce' ); 149 176 150 177 $response['errorStatus'] = false; … … 156 183 $response['emailWarning'] = false; 157 184 158 if ( ! wp_verify_nonce( $signup_nonce, 'signup-nonce' ) ){185 if ( ! $signup_page || !wp_verify_nonce( $signup_nonce, 'signup-nonce' ) ){ 159 186 $response['errorStatus'] = true; 160 187 $response['hiddenError'] = true; … … 204 231 if($response['errorStatus'] == false){ 205 232 $new_user_id = wp_insert_user(array( 206 'first_name' => ucfirst($firstname),207 'last_name' => ucfirst($lastname),233 'first_name' => sanitize_text_field( ucfirst($firstname) ), 234 'last_name' => sanitize_text_field( ucfirst($lastname) ), 208 235 'user_email' => $email, 209 236 'user_login' => $username, … … 213 240 if( !is_wp_error($new_user_id) ){ 214 241 if($new_user_id){ 215 $activation_token = $this->generateRandomString();216 $activation_page_url = $signup_page.'?account-activation=yes&user_id='.$new_user_id.'&activation_token='.$activation_token;217 $activation_link = '<a href="'. $activation_page_url.'">Active Account</a>';218 update_user_meta( $new_user_id, 'activation_token', $activation_token);242 $activation_token = $this->generateRandomString( 32 ); 243 $activation_page_url = add_query_arg( array( 'account-activation' => 'yes', 'user_id' => $new_user_id, 'activation_token' => $activation_token ), $signup_page ); 244 $activation_link = '<a href="'. esc_url( $activation_page_url ) .'">Active Account</a>'; 245 update_user_meta( $new_user_id, 'activation_token', hash( 'sha256', $activation_token ) ); 219 246 update_user_meta( $new_user_id, 'activation_token_time', time() ); 220 247 update_user_meta( $new_user_id, 'is_activated', 0 ); … … 237 264 if(get_option('registration_email')){ 238 265 $tokens = array( 239 'FIRSTNAME' => ucfirst($firstname),240 'LASTNAME' => ucfirst($lastname),266 'FIRSTNAME' => esc_html( ucfirst($firstname) ), 267 'LASTNAME' => esc_html( ucfirst($lastname) ), 241 268 'ACTIVATION_LINK' => $activation_link, 269 'USERNAME' => esc_html( $username ), 270 'USER_EMAIL' => esc_html( $email ), 242 271 ); 243 272 $mail_content .= $this->make_email_template( get_option('registration_email'), $tokens ); 244 273 } else { 245 $mail_content .= '<p>Hello '. ucfirst($firstname).' '.ucfirst($lastname).',</p><p>Thanks you for your registration.</p><p>Please click below link to active account.</p><p><a href="'. $activation_page_url.'">Active Account</a></p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>';274 $mail_content .= '<p>Hello '.esc_html( ucfirst($firstname) ).' '.esc_html( ucfirst($lastname) ).',</p><p>Thanks you for your registration.</p><p>Please click below link to active account.</p><p><a href="'. esc_url( $activation_page_url ) .'">Active Account</a></p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>'; 246 275 } 247 276 $mail_content .= $mail_footer; … … 255 284 $admin_headers[] = 'From: '. $admin_from; 256 285 $admin_headers[] = 'Content-Type: text/html; charset=UTF-8'; 257 $admin_email_msg = '<p>Hello Admin,</p><p>A new user is registered with follow details:</p><p><b>Name :</b> '. ucfirst($firstname).' '.ucfirst($lastname).'<br/><b>Email :</b> '.$email.'</p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>';286 $admin_email_msg = '<p>Hello Admin,</p><p>A new user is registered with follow details:</p><p><b>Name :</b> '.esc_html( ucfirst($firstname) ).' '.esc_html( ucfirst($lastname) ).'<br/><b>Email :</b> '.$email.'</p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>'; 258 287 $admin_mail_content = $mail_header; 259 288 $admin_mail_content .= apply_filters('alr_change_admin_registration_email_msg', $admin_email_msg); … … 285 314 { 286 315 $response = array(); 287 $username = $ _POST['username'];288 $password = $ _POST['password'];289 $signin_nonce = $ _POST['signin_nonce'];316 $username = $this->request_string( $_POST, 'username' ); 317 $password = $this->request_string( $_POST, 'password' ); 318 $signin_nonce = $this->request_string( $_POST, 'signin_nonce' ); 290 319 $response['redirecturl'] = ""; 291 320 $response['errorStatus'] = false; … … 326 355 } else { 327 356 $creds = array('user_login' => $user->data->user_login, 'user_password' => $password ); 328 $user2 = wp_signon( $creds, false ); 329 wp_set_auth_cookie($user2->ID, true, false ); 330 do_action( 'wp_login', $user2->user_login ); 357 $creds['remember'] = true; 358 $user2 = wp_signon( $creds, is_ssl() ); 331 359 if( !is_wp_error($user2) ) { 332 360 $response['redirecturl'] = ''; … … 353 381 { 354 382 $response = array(); 355 $username = $ _POST['username'];356 $forgot_password_page = $_POST['forgot_password_page'];357 $forgot_password_nonce = $ _POST['forgot_password_nonce'];383 $username = $this->request_string( $_POST, 'username' ); 384 $forgot_password_page = $this->form_page_url( 'forgot_password_page', 'ajax-login' ); 385 $forgot_password_nonce = $this->request_string( $_POST, 'forgot_password_nonce' ); 358 386 $response['redirecturl'] = ''; 359 387 $response['errorStatus'] = false; … … 363 391 $response['emailWarning'] = false; 364 392 365 if ( ! wp_verify_nonce( $forgot_password_nonce, 'forgot-password' ) ){393 if ( ! $forgot_password_page || ! wp_verify_nonce( $forgot_password_nonce, 'forgot-password' ) ){ 366 394 $response['errorStatus'] = true; 367 395 $response['hiddenError'] = true; … … 383 411 } 384 412 if ($user) { 385 $currentPageUrl = strtok( $forgot_password_page, '?' ); 386 $activation_token = $this->generateRandomString(); 387 $activation_page_url = $currentPageUrl.'?action=rp&user_id='.$user->ID.'&rp_activation_token='.$activation_token; 388 $activation_link = '<a href="'. $activation_page_url .'">Reset Password</a>'; 389 update_user_meta( $user->ID, 'rp_activation_token', $activation_token ); 390 update_user_meta( $user->ID, 'rp_activation_time', time() ); 391 update_user_meta( $user->ID, 'rp_password_reset', 0 ); 392 $mail_header = '<!DOCTYPE html> 413 $currentPageUrl = $forgot_password_page; 414 $activation_token = get_password_reset_key( $user ); 415 if ( is_wp_error( $activation_token ) ) { 416 $response['errorStatus'] = true; 417 $response['usersError'] = true; 418 $response['usersErrorMsg'] = __( 'Password reset is unavailable.', 'ajax-login-registration' ); 419 wp_send_json( $response ); 420 } 421 update_user_meta( $user->ID, 'alr_reset_issued', time() ); 422 $activation_page_url = add_query_arg( array( 'action' => 'rp', 'user_id' => $user->ID, 'rp_activation_token' => $activation_token ), $currentPageUrl ); 423 $activation_link = '<a href="' . esc_url( $activation_page_url ) . '">Reset Password</a>'; 424 $mail_header = '<!DOCTYPE html> 393 425 <html> 394 426 <head> … … 409 441 if(get_option('reset_password_email')){ 410 442 $tokens = array( 411 'FIRSTNAME' => ucfirst( $firstname),412 'LASTNAME' => ucfirst( $lastname),443 'FIRSTNAME' => esc_html( ucfirst( $firstname ) ), 444 'LASTNAME' => esc_html( ucfirst( $lastname ) ), 413 445 'RESET_PASSWORD_LINK' => $activation_link, 414 446 ); 415 447 $mail_content .= $this->make_email_template( get_option('reset_password_email'), $tokens ); 416 448 } else { 417 $mail_content .= '<p>Hello '. ucfirst($firstname).' '.ucfirst($lastname).',</p><p>You has requested a password reset for the '. get_bloginfo('name') .' account.</p><p>If you ingnore this message, password wonts be chnage. To reset your password, click on below link.</p><p><a href="'. $activation_page_url.'">Reset Password</a></p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>';449 $mail_content .= '<p>Hello '.esc_html( ucfirst($firstname) ).' '.esc_html( ucfirst($lastname) ).',</p><p>You has requested a password reset for the '. get_bloginfo('name') .' account.</p><p>If you ingnore this message, password wonts be chnage. To reset your password, click on below link.</p><p><a href="'. esc_url( $activation_page_url ) .'">Reset Password</a></p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>'; 418 450 } 419 451 $mail_content .= $mail_footer; … … 421 453 /********* User Reset Email Template End *********/ 422 454 if( $is_sent ){ 423 $response['redirecturl'] = $currentPageUrl.'?checkemail=confirm';455 $response['redirecturl'] = add_query_arg( 'checkemail', 'confirm', $currentPageUrl ); 424 456 $response['errorStatus'] = false; 425 457 $response['success'] = __('Check your email for the password reset link.', 'ajax-login-registration'); … … 442 474 { 443 475 $response = array(); 444 $user_password = trim( $_POST['new_password']);445 $user_repassword = trim( $_POST['renew_password']);446 $reset_password_nonce= trim( $_POST['reset_password_nonce']);447 $user_id = trim( $_POST['user_id']);448 $rp_activation_token = trim( $_POST['activation_token']);449 $reset_password_page = trim( $_POST['reset_password_page']);476 $user_password = $this->request_string( $_POST, 'new_password' ); 477 $user_repassword = $this->request_string( $_POST, 'renew_password' ); 478 $reset_password_nonce= $this->request_string( $_POST, 'reset_password_nonce' ); 479 $user_id = $this->request_string( $_POST, 'user_id' ); 480 $rp_activation_token = $this->request_string( $_POST, 'activation_token' ); 481 $reset_password_page = $this->form_page_url( 'reset_password_page', 'ajax-login' ); 450 482 451 483 $response['redirecturl'] = ""; … … 456 488 $response['errorRepassword']= false; 457 489 458 if ( ! wp_verify_nonce( $reset_password_nonce, 'reset-password' ) ){490 if ( ! $reset_password_page || ! wp_verify_nonce( $reset_password_nonce, 'reset-password' ) ){ 459 491 $response['errorStatus'] = true; 460 492 $response['hiddenError'] = true; … … 479 511 $response['errorRepassword'] = true; 480 512 $response['errorRepasswordMsg'] = __('Confirm new password is required.', 'ajax-login-registration'); 481 } else if( $user_repassword != $user_password){513 } else if( $user_repassword !== $user_password){ 482 514 $response['errorStatus'] = true; 483 515 $response['errorRepassword'] = true; … … 486 518 487 519 if($response['errorStatus'] == false){ 488 $currentPageUrl = strtok( $reset_password_page, '?' ); 489 $db_activation_token = get_user_meta( $user_id, 'rp_activation_token', 1 ); 490 if($db_activation_token == $rp_activation_token){ 491 $pass_reset = get_user_meta( $user_id, 'rp_password_reset', 1 ); 492 if( $pass_reset == 0 ) { 493 $userdata = array( 494 'ID' => $user_id, 495 'user_pass' => $user_password 496 ); 497 $updated_user_id = wp_update_user($userdata); 498 if($user_id == $updated_user_id) { 499 update_user_meta( $user_id, 'rp_password_reset', 1 ); 500 delete_user_meta($user_id, 'rp_activation_token'); 501 update_user_meta( $user_id, 'is_activated', 1 ); 502 $response['errorStatus'] = false; 503 $response['redirecturl'] = $currentPageUrl.'?success=rp'; 504 $response['success'] = __('Your password has been reset.', 'ajax-login-registration'); 505 } 506 } else { 507 $response['errorStatus'] = true; 508 $response['usersError'] = true; 509 $response['usersErrorMsg'] = __('Error: Please fill-up the form and submit it again', 'ajax-login-registration'); 510 } 511 } else { 512 $response['errorStatus'] = true; 513 $response['usersError'] = true; 514 $response['redirecturl'] = $currentPageUrl.'?action=lostpassword&error=invalidkey'; 515 $response['usersErrorMsg'] = __('Activation token is invalid.', 'ajax-login-registration'); 516 } 520 $user = $this->validate_reset_token( absint( $user_id ), $rp_activation_token ); 521 if ( $user ) { 522 reset_password( $user, $user_password ); 523 delete_user_meta( $user->ID, 'alr_reset_issued' ); 524 delete_user_meta( $user->ID, 'rp_activation_token' ); 525 delete_user_meta( $user->ID, 'rp_activation_time' ); 526 delete_user_meta( $user->ID, 'rp_password_reset' ); 527 $response['redirecturl'] = add_query_arg( 'success', 'rp', $reset_password_page ); 528 $response['success'] = __( 'Your password has been reset.', 'ajax-login-registration' ); 529 } else { 530 $response['errorStatus'] = true; 531 $response['usersError'] = true; 532 $response['redirecturl'] = add_query_arg( array( 'action' => 'lostpassword', 'error' => 'invalidkey' ), $reset_password_page ); 533 $response['usersErrorMsg'] = __( 'Activation token is invalid.', 'ajax-login-registration' ); 534 } 517 535 } 518 536 echo json_encode($response); 519 537 exit; 520 538 } 521 522 public function test(){523 echo 'Test';524 }525 539 } -
ajax-login-registration/tags/1.0.5/public/js/ajax-login-registration-public.js
r2064864 r3826948 189 189 } 190 190 } else { 191 console.log( 'response', response ); 192 191 193 jQuery("#frm_user_signin").trigger('reset'); 192 194 jQuery('#frm_user_signin #responce-messages .success-msg').text(response.success); 193 195 jQuery('#frm_user_signin #responce-messages').show(); 194 196 jQuery('#frm_user_signin #responce-messages .success-msg').css('display', 'inline-block'); 195 //location.reload(true);197 location.reload(true); 196 198 //window.location = response.redirecturl; 197 199 } -
ajax-login-registration/tags/1.0.5/public/templates/ajax-login-form.php
r3277009 r3826948 3 3 * Ajax Login Public View 4 4 */ 5 if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){ 6 $pageUrl = "https"; 7 } else { 8 $pageUrl = "http"; 9 } 10 $pageUrl .= "://"; 11 $pageUrl .= $_SERVER['HTTP_HOST']; 12 $pageUrl .= isset( $_SERVER['REDIRECT_URL'] ) ? rtrim($_SERVER['REDIRECT_URL'], '/') : ''; 5 $page_id = get_queried_object_id(); 6 $pageUrl = get_permalink( $page_id ); 13 7 ?> 8 <div class="form-container"> 14 9 <?php 15 10 if( isset($_REQUEST['action']) && $_REQUEST['action'] == 'lostpassword' ){ ?> 16 <div class="form-container">17 11 <form id="frm_forgot_password" method="post"> 18 12 <?php … … 28 22 </div> 29 23 <div class="form-group submit-button"> 30 <input type="hidden" name="forgot_password_page" id="forgot_password_page" value="<?php echo $pageUrl; ?>" />24 <input type="hidden" name="forgot_password_page" id="forgot_password_page" value="<?php echo esc_attr( $page_id ); ?>" /> 31 25 <input type="hidden" name="forgot_password_nonce" id="forgot_password_nonce" value="<?php echo wp_create_nonce('forgot-password'); ?>" /> 32 26 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> … … 44 38 </div> 45 39 </form> 46 </div>47 40 <?php } else if( isset($_REQUEST['action']) && $_REQUEST['action'] == 'rp' ){ ?> 48 41 <?php if( isset ( $_REQUEST['user_id']) && isset( $_REQUEST['rp_activation_token']) && !empty( $_REQUEST['user_id']) && !empty( $_REQUEST['rp_activation_token']) ){ ?> 49 42 <?php 50 $user_id = $_REQUEST['user_id']; 51 $activation_token = get_user_meta( $user_id, 'rp_activation_token', 1 ); 52 $activation_time = get_user_meta( $user_id, 'rp_activation_time', 1 ); 53 $timeDifference = time() - $activation_time; 54 if( ( $activation_token != $_REQUEST['rp_activation_token'] ) || ( $timeDifference > 3600 ) ){ ?> 55 <script type="text/javascript">window.location = "<?php echo $pageUrl; ?>?action=lostpassword&error=invalidkey";</script> 43 $user_id = absint( $this->request_string( $_GET, 'user_id' ) ); 44 $token = $this->request_string( $_GET, 'rp_activation_token' ); 45 if ( ! $this->validate_reset_token( $user_id, $token ) ) { ?> 46 <script type="text/javascript">window.location = <?php echo wp_json_encode( add_query_arg( array( 'action' => 'lostpassword', 'error' => 'invalidkey' ), $pageUrl ), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); ?>;</script> 56 47 <?php 57 48 } else { ?> 58 <div class="form-container"> 59 <form id="frm_reset_password" method="post"> 60 <div class="form-group"> 61 <input type="password" name="new_password" id="new_password" class="form-control" placeholder="<?php echo __('New password', 'ajax-login-registration'); ?>"> 62 </div> 63 <div class="form-group"> 64 <input type="password" name="renew_password" id="renew_password" class="form-control" placeholder="<?php echo __('Confirm new password', 'ajax-login-registration'); ?>"> 65 </div> 66 <div class="form-group submit-button"> 67 <input type="hidden" name="rp_activation_token" id="rp_activation_token" value="<?php echo $_REQUEST['rp_activation_token']; ?>" /> 68 <input type="hidden" name="user_id" id="user_id" value="<?php echo $_REQUEST['user_id']; ?>" /> 69 <input type="hidden" name="reset_password_page" id="reset_password_page" value="<?php echo $pageUrl; ?>" /> 70 <input type="hidden" name="reset_password_nonce" id="reset_password_nonce" value="<?php echo wp_create_nonce('reset-password'); ?>" /> 71 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> 72 <span class="ajax-loader"></span> 73 </div> 74 <div id="responce-messages"> 75 <div class="error-msg"></div> 76 <div class="success-msg"></div> 77 </div> 78 </form> 79 </div> 49 <form id="frm_reset_password" method="post"> 50 <div class="form-group"> 51 <input type="password" name="new_password" id="new_password" class="form-control" placeholder="<?php echo __('New password', 'ajax-login-registration'); ?>"> 52 </div> 53 <div class="form-group"> 54 <input type="password" name="renew_password" id="renew_password" class="form-control" placeholder="<?php echo __('Confirm new password', 'ajax-login-registration'); ?>"> 55 </div> 56 <div class="form-group submit-button"> 57 <input type="hidden" name="rp_activation_token" id="rp_activation_token" value="<?php echo esc_attr( $token ); ?>" /> 58 <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $user_id ); ?>" /> 59 <input type="hidden" name="reset_password_page" id="reset_password_page" value="<?php echo esc_attr( $page_id ); ?>" /> 60 <input type="hidden" name="reset_password_nonce" id="reset_password_nonce" value="<?php echo wp_create_nonce('reset-password'); ?>" /> 61 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> 62 <span class="ajax-loader"></span> 63 </div> 64 <div id="responce-messages"> 65 <div class="error-msg"></div> 66 <div class="success-msg"></div> 67 </div> 68 </form> 80 69 <?php } 81 70 ?> 82 71 <?php } ?> 83 72 <?php } else { ?> 84 <div class="form-container"> 73 <?php if ( is_user_logged_in() ) { ?> 74 <p><?php echo __( 'You are already logged in.', 'ajax-login-registration'); ?> <a href="<?php echo esc_url( wp_logout_url( get_permalink() ) ); ?>"><?php echo __( 'Log out', 'ajax-login-registration'); ?></a></p> 75 <?php } else { ?> 85 76 <form id="frm_user_signin" method="post"> 86 77 <div class="form-group"> … … 95 86 ?> 96 87 <div class="form-group forgotten-pass"> 97 <a href=" ?action=lostpassword"><?php echo $password_text; ?></a>88 <a href="<?php echo esc_url( add_query_arg( 'action', 'lostpassword', $pageUrl ) ); ?>"><?php echo $password_text; ?></a> 98 89 </div> 99 90 <?php } ?> 100 91 <div class="form-group submit-button"> 101 <input type="hidden" name="signin_page" id="signin_page" value="<?php echo $pageUrl; ?>" />92 <input type="hidden" name="signin_page" id="signin_page" value="<?php echo esc_attr( $page_id ); ?>" /> 102 93 <input type="hidden" name="signin_nonce" id="signin_nonce" value="<?php echo wp_create_nonce('signin-nonce'); ?>" /> 103 94 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> … … 117 108 </div> 118 109 </form> 110 <?php } ?> 111 <?php } ?> 119 112 </div> 120 <?php } ?> -
ajax-login-registration/tags/1.0.5/public/templates/ajax-registration-form.php
r3277009 r3826948 3 3 * Ajax Registration Public View 4 4 */ 5 if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){ 6 $pageUrl = "https"; 7 } else { 8 $pageUrl = "http"; 9 } 10 $pageUrl .= "://"; 11 $pageUrl .= $_SERVER['HTTP_HOST']; 12 $pageUrl .= isset( $_SERVER['REDIRECT_URL'] ) ? rtrim($_SERVER['REDIRECT_URL'], '/') : ''; 5 $page_id = get_queried_object_id(); 6 $pageUrl = get_permalink( $page_id ); 13 7 14 8 if(isset($_GET['account-activation']) && $_GET['account-activation'] == 'yes' ){ 15 9 if( isset ( $_GET['user_id']) && isset( $_GET['activation_token']) && !empty( $_GET['user_id']) && !empty( $_GET['activation_token']) ){ 16 $user_id = $_GET['user_id'];17 $activation_token = get_user_meta( $user_id, 'activation_token', 1);18 $activation_time = get_user_meta( $user_id, 'activation_token_time', 1);19 $timeDifference = time() - $activation_time;20 if( ($activation_token != $_GET['activation_token']) || ( $timeDifference > 3600 ) ){10 $user_id = absint( $this->request_string( $_GET, 'user_id' ) ); 11 $token = $this->request_string( $_GET, 'activation_token' ); 12 $activation_token = get_user_meta( $user_id, 'activation_token', true ); 13 $activation_time = (int) get_user_meta( $user_id, 'activation_token_time', true ); 14 if ( ! $user_id || '' === $token || ! is_string( $activation_token ) || ! hash_equals( $activation_token, hash( 'sha256', $token ) ) || ! $activation_time || $activation_time > time() || time() - $activation_time >= HOUR_IN_SECONDS || 'pending' !== get_user_meta( $user_id, 'user_active_status', true ) ) { 21 15 ?> 22 16 <div> … … 33 27 <?php 34 28 } else { 35 update_user_meta( $user_id, 'is_activated', 1 ); 29 if ( ! delete_user_meta( $user_id, 'activation_token', $activation_token ) ) { return; } 30 delete_user_meta( $user_id, 'activation_token_time' ); 31 update_user_meta( $user_id, 'is_activated', 1 ); 36 32 update_user_meta( $user_id, 'user_active_status', 'registered' ); 37 33 //delete_user_meta( $user_id, 'user_active_status'); … … 62 58 if(get_option('activation_email')){ 63 59 $tokens = array( 64 'FIRSTNAME' => ucfirst( $firstname),65 'LASTNAME' => ucfirst( $lastname),60 'FIRSTNAME' => esc_html( ucfirst( $firstname ) ), 61 'LASTNAME' => esc_html( ucfirst( $lastname ) ), 66 62 'NEW_PASSWORD' => $user_password, 67 63 ); 68 64 $mail_content .= $this->make_email_template( get_option('activation_email'), $tokens ); 69 65 } else { 70 $mail_content .= '<p>Hello '. ucfirst($firstname).' '.ucfirst($lastname).',</p><p>Your account is activated successfully.</p><p>Your password is : '. $user_password.'</p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>';66 $mail_content .= '<p>Hello '.esc_html( ucfirst($firstname) ).' '.esc_html( ucfirst($lastname) ).',</p><p>Your account is activated successfully.</p><p>Your password is : '. esc_html( $user_password ) .'</p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>'; 71 67 } 72 68 $mail_content .= $mail_footer; … … 91 87 } else { 92 88 ?> 93 <div class="form-container"> 94 <form id="frm_user_signup" method="post"> 95 <div class="form-group"> 96 <input type="text" name="signup_username" id="signup_username" class="form-control" placeholder="<?php echo __('Username', 'ajax-login-registration'); ?>"> 97 </div> 98 <div class="form-group"> 99 <input type="text" name="signup_firstname" id="signup_firstname" class="form-control" placeholder="<?php echo __('First Name', 'ajax-login-registration'); ?>"> 100 </div> 101 <div class="form-group"> 102 <input type="text" name="signup_lastname" id="signup_lastname" class="form-control" placeholder="<?php echo __('Last Name', 'ajax-login-registration'); ?>"> 103 </div> 104 <div class="form-group"> 105 <input type="text" name="signup_email" id="signup_email" class="form-control" placeholder="<?php echo __('Email Address', 'ajax-login-registration'); ?>"> 106 </div> 107 <div class="form-group submit-button"> 108 <input type="hidden" name="signup_page" id="signup_page" value="<?php echo $pageUrl; ?>" /> 109 <input type="hidden" name="signup_nonce" id="signup_nonce" value="<?php echo wp_create_nonce('signup-nonce'); ?>" /> 110 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> 111 <span class="ajax-loader"></span> 112 </div> 113 <div id="responce-messages"> 114 <div class="error-msg"></div> 115 <div class="success-msg"></div> 116 <div class="warning-msg"></div> 117 </div> 118 </form> 119 </div> 89 <?php if ( is_user_logged_in() ) { ?> 90 <p><?php echo __( 'You are already logged in.', 'ajax-login-registration'); ?> <a href="<?php echo esc_url( wp_logout_url( get_permalink() ) ); ?>"><?php echo __( 'Log out', 'ajax-login-registration'); ?></a></p> 91 <?php } else { ?> 92 <div class="form-container"> 93 <form id="frm_user_signup" method="post"> 94 <div class="form-group"> 95 <input type="text" name="signup_username" id="signup_username" class="form-control" placeholder="<?php echo __('Username', 'ajax-login-registration'); ?>"> 96 </div> 97 <div class="form-group"> 98 <input type="text" name="signup_firstname" id="signup_firstname" class="form-control" placeholder="<?php echo __('First Name', 'ajax-login-registration'); ?>"> 99 </div> 100 <div class="form-group"> 101 <input type="text" name="signup_lastname" id="signup_lastname" class="form-control" placeholder="<?php echo __('Last Name', 'ajax-login-registration'); ?>"> 102 </div> 103 <div class="form-group"> 104 <input type="text" name="signup_email" id="signup_email" class="form-control" placeholder="<?php echo __('Email Address', 'ajax-login-registration'); ?>"> 105 </div> 106 <div class="form-group submit-button"> 107 <input type="hidden" name="signup_page" id="signup_page" value="<?php echo esc_attr( $page_id ); ?>" /> 108 <input type="hidden" name="signup_nonce" id="signup_nonce" value="<?php echo wp_create_nonce('signup-nonce'); ?>" /> 109 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> 110 <span class="ajax-loader"></span> 111 </div> 112 <div id="responce-messages"> 113 <div class="error-msg"></div> 114 <div class="success-msg"></div> 115 <div class="warning-msg"></div> 116 </div> 117 </form> 118 </div> 119 <?php } ?> 120 120 <?php } ?> -
ajax-login-registration/trunk/README.txt
r3277009 r3826948 3 3 Tags: ajax login, ajax registration, ajax login registration, wp ajax login, wp ajax registration 4 4 Requires at least: 6.5 5 Tested up to: 6.86 Requires PHP: 7. 27 Stable tag: 1.0. 45 Tested up to: 7.1 6 Requires PHP: 7.4 7 Stable tag: 1.0.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 32 32 33 33 == Changelog == 34 = 1.0.1 = 35 First release 34 = 1.0.5 = 35 * Security: Fixed password reset link poisoning vulnerability. 36 * Security: Fixed insecure password reset token validation. 37 * Security: Enforced server-side password reset token expiration. 38 * Security: Improved registration activation link security. 39 * Thanks to Muni Nitish Kumar Yaddala and the WPScan / Jetpack security team for reporting the vulnerabilities. 36 40 37 = 1.0. 2=41 = 1.0.4 = 38 42 Test compatibility of plugin with latest version of WordPress 39 43 … … 41 45 Add blueprints json file for plugin preview button 42 46 43 = 1.0. 4=47 = 1.0.2 = 44 48 Test compatibility of plugin with latest version of WordPress 49 50 = 1.0.1 = 51 First release 45 52 46 53 == Upgrade Notice == -
ajax-login-registration/trunk/admin/partials/ajax-login-registration-setting.php
r2064898 r3826948 44 44 <th scope="row"><label for="registration_email">Registration Email</label></th> 45 45 <td><?php wp_editor( get_option('registration_email'), 'registration_email', array( 'textarea_rows' => 8 ) ); ?> 46 <p class="description">User get this email after registration. In the email template, you can use these mail-tags:<br /><code>[FIRSTNAME]</code> <code>[LASTNAME]</code> <code>[ACTIVATION_LINK]</code> <code>[USERNAME]</code> </p></td>46 <p class="description">User get this email after registration. In the email template, you can use these mail-tags:<br /><code>[FIRSTNAME]</code> <code>[LASTNAME]</code> <code>[ACTIVATION_LINK]</code> <code>[USERNAME]</code> <code>[USER_EMAIL]</code></p></td> 47 47 </tr> 48 48 <tr> -
ajax-login-registration/trunk/ajax-login-registration.php
r3277009 r3826948 7 7 * Plugin URI: https://www.hktechnolab.com/ 8 8 * Description: Ajax login & registration with email template confirmation 9 * Version: 1.0. 49 * Version: 1.0.5 10 10 * Author: Ravi Gadhiya 11 11 * Author URI: https://profiles.wordpress.org/ravigadhiyawp -
ajax-login-registration/trunk/includes/class-ajax-login-registration.php
r3260091 r3826948 59 59 { 60 60 $this->plugin_name = 'ajax-login-registration'; 61 $this->version = '1.0. 0';61 $this->version = '1.0.5'; 62 62 63 63 $this->load_dependencies(); -
ajax-login-registration/trunk/public/class-ajax-login-registration-public.php
r3260091 r3826948 111 111 } 112 112 113 //Generate Random String 114 public function generateRandomString($length = 20) 115 { 116 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 117 $charactersLength = strlen($characters); 118 $randomString = ''; 119 for ($i = 0; $i < $length; $i++) { 120 $randomString .= $characters[rand(0, $charactersLength - 1)]; 121 } 122 return $randomString; 123 } 113 // Resolve a published shortcode page using WordPress-owned URLs only. 114 private function form_page_url( $field, $shortcode ) { 115 $id = absint( $this->request_string( $_POST, $field ) ); 116 $page = get_post( $id ); 117 if ( ! $page || 'publish' !== $page->post_status || ! has_shortcode( $page->post_content, $shortcode ) ) { 118 return ''; 119 } 120 $url = get_permalink( $page ); 121 $site = wp_parse_url( home_url( '/' ) ); 122 $target = wp_parse_url( $url ); 123 if ( ! $url || empty( $target['host'] ) || empty( $site['host'] ) || strtolower( $target['host'] ) !== strtolower( $site['host'] ) || ( $target['scheme'] ?? '' ) !== ( $site['scheme'] ?? '' ) || ( $target['port'] ?? null ) !== ( $site['port'] ?? null ) ) { 124 return ''; 125 } 126 return $url; 127 } 128 129 private function request_string( $source, $key ) { 130 return isset( $source[$key] ) && is_string( $source[$key] ) ? wp_unslash( $source[$key] ) : ''; 131 } 132 133 public function generateRandomString( $length = 20 ) { 134 return wp_generate_password( $length, false, false ); 135 } 136 137 // Shared by the reset form and AJAX handler. Legacy tokens are rejected. 138 private function validate_reset_token( $user_id, $token ) { 139 $user = get_user_by( 'id', $user_id ); 140 $issued = (int) get_user_meta( $user_id, 'alr_reset_issued', true ); 141 if ( ! $user || '' === $token || ! $issued || $issued > time() || time() - $issued >= HOUR_IN_SECONDS ) { 142 return false; 143 } 144 $key_parts = explode( ':', $user->user_activation_key, 2 ); 145 if ( count( $key_parts ) !== 2 || ! ctype_digit( $key_parts[0] ) || time() - (int) $key_parts[0] >= HOUR_IN_SECONDS || (int) $key_parts[0] > time() ) { 146 return false; 147 } 148 $verified = check_password_reset_key( $token, $user->user_login ); 149 return ! is_wp_error( $verified ) && (int) $verified->ID === (int) $user_id ? $verified : false; 150 } 124 151 125 152 /** … … 141 168 { 142 169 $response = array(); 143 $username = $ _POST['username'];144 $firstname = $ _POST['firstname'];145 $lastname = $ _POST['lastname'];146 $email = $ _POST['email'];147 $signup_page = $_POST['signup_page'];148 $signup_nonce = $ _POST['signup_nonce'];170 $username = $this->request_string( $_POST, 'username' ); 171 $firstname = $this->request_string( $_POST, 'firstname' ); 172 $lastname = $this->request_string( $_POST, 'lastname' ); 173 $email = $this->request_string( $_POST, 'email' ); 174 $signup_page = $this->form_page_url( 'signup_page', 'ajax-registration' ); 175 $signup_nonce = $this->request_string( $_POST, 'signup_nonce' ); 149 176 150 177 $response['errorStatus'] = false; … … 156 183 $response['emailWarning'] = false; 157 184 158 if ( ! wp_verify_nonce( $signup_nonce, 'signup-nonce' ) ){185 if ( ! $signup_page || !wp_verify_nonce( $signup_nonce, 'signup-nonce' ) ){ 159 186 $response['errorStatus'] = true; 160 187 $response['hiddenError'] = true; … … 204 231 if($response['errorStatus'] == false){ 205 232 $new_user_id = wp_insert_user(array( 206 'first_name' => ucfirst($firstname),207 'last_name' => ucfirst($lastname),233 'first_name' => sanitize_text_field( ucfirst($firstname) ), 234 'last_name' => sanitize_text_field( ucfirst($lastname) ), 208 235 'user_email' => $email, 209 236 'user_login' => $username, … … 213 240 if( !is_wp_error($new_user_id) ){ 214 241 if($new_user_id){ 215 $activation_token = $this->generateRandomString();216 $activation_page_url = $signup_page.'?account-activation=yes&user_id='.$new_user_id.'&activation_token='.$activation_token;217 $activation_link = '<a href="'. $activation_page_url.'">Active Account</a>';218 update_user_meta( $new_user_id, 'activation_token', $activation_token);242 $activation_token = $this->generateRandomString( 32 ); 243 $activation_page_url = add_query_arg( array( 'account-activation' => 'yes', 'user_id' => $new_user_id, 'activation_token' => $activation_token ), $signup_page ); 244 $activation_link = '<a href="'. esc_url( $activation_page_url ) .'">Active Account</a>'; 245 update_user_meta( $new_user_id, 'activation_token', hash( 'sha256', $activation_token ) ); 219 246 update_user_meta( $new_user_id, 'activation_token_time', time() ); 220 247 update_user_meta( $new_user_id, 'is_activated', 0 ); … … 237 264 if(get_option('registration_email')){ 238 265 $tokens = array( 239 'FIRSTNAME' => ucfirst($firstname),240 'LASTNAME' => ucfirst($lastname),266 'FIRSTNAME' => esc_html( ucfirst($firstname) ), 267 'LASTNAME' => esc_html( ucfirst($lastname) ), 241 268 'ACTIVATION_LINK' => $activation_link, 269 'USERNAME' => esc_html( $username ), 270 'USER_EMAIL' => esc_html( $email ), 242 271 ); 243 272 $mail_content .= $this->make_email_template( get_option('registration_email'), $tokens ); 244 273 } else { 245 $mail_content .= '<p>Hello '. ucfirst($firstname).' '.ucfirst($lastname).',</p><p>Thanks you for your registration.</p><p>Please click below link to active account.</p><p><a href="'. $activation_page_url.'">Active Account</a></p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>';274 $mail_content .= '<p>Hello '.esc_html( ucfirst($firstname) ).' '.esc_html( ucfirst($lastname) ).',</p><p>Thanks you for your registration.</p><p>Please click below link to active account.</p><p><a href="'. esc_url( $activation_page_url ) .'">Active Account</a></p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>'; 246 275 } 247 276 $mail_content .= $mail_footer; … … 255 284 $admin_headers[] = 'From: '. $admin_from; 256 285 $admin_headers[] = 'Content-Type: text/html; charset=UTF-8'; 257 $admin_email_msg = '<p>Hello Admin,</p><p>A new user is registered with follow details:</p><p><b>Name :</b> '. ucfirst($firstname).' '.ucfirst($lastname).'<br/><b>Email :</b> '.$email.'</p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>';286 $admin_email_msg = '<p>Hello Admin,</p><p>A new user is registered with follow details:</p><p><b>Name :</b> '.esc_html( ucfirst($firstname) ).' '.esc_html( ucfirst($lastname) ).'<br/><b>Email :</b> '.$email.'</p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>'; 258 287 $admin_mail_content = $mail_header; 259 288 $admin_mail_content .= apply_filters('alr_change_admin_registration_email_msg', $admin_email_msg); … … 285 314 { 286 315 $response = array(); 287 $username = $ _POST['username'];288 $password = $ _POST['password'];289 $signin_nonce = $ _POST['signin_nonce'];316 $username = $this->request_string( $_POST, 'username' ); 317 $password = $this->request_string( $_POST, 'password' ); 318 $signin_nonce = $this->request_string( $_POST, 'signin_nonce' ); 290 319 $response['redirecturl'] = ""; 291 320 $response['errorStatus'] = false; … … 326 355 } else { 327 356 $creds = array('user_login' => $user->data->user_login, 'user_password' => $password ); 328 $user2 = wp_signon( $creds, false ); 329 wp_set_auth_cookie($user2->ID, true, false ); 330 do_action( 'wp_login', $user2->user_login ); 357 $creds['remember'] = true; 358 $user2 = wp_signon( $creds, is_ssl() ); 331 359 if( !is_wp_error($user2) ) { 332 360 $response['redirecturl'] = ''; … … 353 381 { 354 382 $response = array(); 355 $username = $ _POST['username'];356 $forgot_password_page = $_POST['forgot_password_page'];357 $forgot_password_nonce = $ _POST['forgot_password_nonce'];383 $username = $this->request_string( $_POST, 'username' ); 384 $forgot_password_page = $this->form_page_url( 'forgot_password_page', 'ajax-login' ); 385 $forgot_password_nonce = $this->request_string( $_POST, 'forgot_password_nonce' ); 358 386 $response['redirecturl'] = ''; 359 387 $response['errorStatus'] = false; … … 363 391 $response['emailWarning'] = false; 364 392 365 if ( ! wp_verify_nonce( $forgot_password_nonce, 'forgot-password' ) ){393 if ( ! $forgot_password_page || ! wp_verify_nonce( $forgot_password_nonce, 'forgot-password' ) ){ 366 394 $response['errorStatus'] = true; 367 395 $response['hiddenError'] = true; … … 383 411 } 384 412 if ($user) { 385 $currentPageUrl = strtok( $forgot_password_page, '?' ); 386 $activation_token = $this->generateRandomString(); 387 $activation_page_url = $currentPageUrl.'?action=rp&user_id='.$user->ID.'&rp_activation_token='.$activation_token; 388 $activation_link = '<a href="'. $activation_page_url .'">Reset Password</a>'; 389 update_user_meta( $user->ID, 'rp_activation_token', $activation_token ); 390 update_user_meta( $user->ID, 'rp_activation_time', time() ); 391 update_user_meta( $user->ID, 'rp_password_reset', 0 ); 392 $mail_header = '<!DOCTYPE html> 413 $currentPageUrl = $forgot_password_page; 414 $activation_token = get_password_reset_key( $user ); 415 if ( is_wp_error( $activation_token ) ) { 416 $response['errorStatus'] = true; 417 $response['usersError'] = true; 418 $response['usersErrorMsg'] = __( 'Password reset is unavailable.', 'ajax-login-registration' ); 419 wp_send_json( $response ); 420 } 421 update_user_meta( $user->ID, 'alr_reset_issued', time() ); 422 $activation_page_url = add_query_arg( array( 'action' => 'rp', 'user_id' => $user->ID, 'rp_activation_token' => $activation_token ), $currentPageUrl ); 423 $activation_link = '<a href="' . esc_url( $activation_page_url ) . '">Reset Password</a>'; 424 $mail_header = '<!DOCTYPE html> 393 425 <html> 394 426 <head> … … 409 441 if(get_option('reset_password_email')){ 410 442 $tokens = array( 411 'FIRSTNAME' => ucfirst( $firstname),412 'LASTNAME' => ucfirst( $lastname),443 'FIRSTNAME' => esc_html( ucfirst( $firstname ) ), 444 'LASTNAME' => esc_html( ucfirst( $lastname ) ), 413 445 'RESET_PASSWORD_LINK' => $activation_link, 414 446 ); 415 447 $mail_content .= $this->make_email_template( get_option('reset_password_email'), $tokens ); 416 448 } else { 417 $mail_content .= '<p>Hello '. ucfirst($firstname).' '.ucfirst($lastname).',</p><p>You has requested a password reset for the '. get_bloginfo('name') .' account.</p><p>If you ingnore this message, password wonts be chnage. To reset your password, click on below link.</p><p><a href="'. $activation_page_url.'">Reset Password</a></p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>';449 $mail_content .= '<p>Hello '.esc_html( ucfirst($firstname) ).' '.esc_html( ucfirst($lastname) ).',</p><p>You has requested a password reset for the '. get_bloginfo('name') .' account.</p><p>If you ingnore this message, password wonts be chnage. To reset your password, click on below link.</p><p><a href="'. esc_url( $activation_page_url ) .'">Reset Password</a></p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>'; 418 450 } 419 451 $mail_content .= $mail_footer; … … 421 453 /********* User Reset Email Template End *********/ 422 454 if( $is_sent ){ 423 $response['redirecturl'] = $currentPageUrl.'?checkemail=confirm';455 $response['redirecturl'] = add_query_arg( 'checkemail', 'confirm', $currentPageUrl ); 424 456 $response['errorStatus'] = false; 425 457 $response['success'] = __('Check your email for the password reset link.', 'ajax-login-registration'); … … 442 474 { 443 475 $response = array(); 444 $user_password = trim( $_POST['new_password']);445 $user_repassword = trim( $_POST['renew_password']);446 $reset_password_nonce= trim( $_POST['reset_password_nonce']);447 $user_id = trim( $_POST['user_id']);448 $rp_activation_token = trim( $_POST['activation_token']);449 $reset_password_page = trim( $_POST['reset_password_page']);476 $user_password = $this->request_string( $_POST, 'new_password' ); 477 $user_repassword = $this->request_string( $_POST, 'renew_password' ); 478 $reset_password_nonce= $this->request_string( $_POST, 'reset_password_nonce' ); 479 $user_id = $this->request_string( $_POST, 'user_id' ); 480 $rp_activation_token = $this->request_string( $_POST, 'activation_token' ); 481 $reset_password_page = $this->form_page_url( 'reset_password_page', 'ajax-login' ); 450 482 451 483 $response['redirecturl'] = ""; … … 456 488 $response['errorRepassword']= false; 457 489 458 if ( ! wp_verify_nonce( $reset_password_nonce, 'reset-password' ) ){490 if ( ! $reset_password_page || ! wp_verify_nonce( $reset_password_nonce, 'reset-password' ) ){ 459 491 $response['errorStatus'] = true; 460 492 $response['hiddenError'] = true; … … 479 511 $response['errorRepassword'] = true; 480 512 $response['errorRepasswordMsg'] = __('Confirm new password is required.', 'ajax-login-registration'); 481 } else if( $user_repassword != $user_password){513 } else if( $user_repassword !== $user_password){ 482 514 $response['errorStatus'] = true; 483 515 $response['errorRepassword'] = true; … … 486 518 487 519 if($response['errorStatus'] == false){ 488 $currentPageUrl = strtok( $reset_password_page, '?' ); 489 $db_activation_token = get_user_meta( $user_id, 'rp_activation_token', 1 ); 490 if($db_activation_token == $rp_activation_token){ 491 $pass_reset = get_user_meta( $user_id, 'rp_password_reset', 1 ); 492 if( $pass_reset == 0 ) { 493 $userdata = array( 494 'ID' => $user_id, 495 'user_pass' => $user_password 496 ); 497 $updated_user_id = wp_update_user($userdata); 498 if($user_id == $updated_user_id) { 499 update_user_meta( $user_id, 'rp_password_reset', 1 ); 500 delete_user_meta($user_id, 'rp_activation_token'); 501 update_user_meta( $user_id, 'is_activated', 1 ); 502 $response['errorStatus'] = false; 503 $response['redirecturl'] = $currentPageUrl.'?success=rp'; 504 $response['success'] = __('Your password has been reset.', 'ajax-login-registration'); 505 } 506 } else { 507 $response['errorStatus'] = true; 508 $response['usersError'] = true; 509 $response['usersErrorMsg'] = __('Error: Please fill-up the form and submit it again', 'ajax-login-registration'); 510 } 511 } else { 512 $response['errorStatus'] = true; 513 $response['usersError'] = true; 514 $response['redirecturl'] = $currentPageUrl.'?action=lostpassword&error=invalidkey'; 515 $response['usersErrorMsg'] = __('Activation token is invalid.', 'ajax-login-registration'); 516 } 520 $user = $this->validate_reset_token( absint( $user_id ), $rp_activation_token ); 521 if ( $user ) { 522 reset_password( $user, $user_password ); 523 delete_user_meta( $user->ID, 'alr_reset_issued' ); 524 delete_user_meta( $user->ID, 'rp_activation_token' ); 525 delete_user_meta( $user->ID, 'rp_activation_time' ); 526 delete_user_meta( $user->ID, 'rp_password_reset' ); 527 $response['redirecturl'] = add_query_arg( 'success', 'rp', $reset_password_page ); 528 $response['success'] = __( 'Your password has been reset.', 'ajax-login-registration' ); 529 } else { 530 $response['errorStatus'] = true; 531 $response['usersError'] = true; 532 $response['redirecturl'] = add_query_arg( array( 'action' => 'lostpassword', 'error' => 'invalidkey' ), $reset_password_page ); 533 $response['usersErrorMsg'] = __( 'Activation token is invalid.', 'ajax-login-registration' ); 534 } 517 535 } 518 536 echo json_encode($response); 519 537 exit; 520 538 } 521 522 public function test(){523 echo 'Test';524 }525 539 } -
ajax-login-registration/trunk/public/js/ajax-login-registration-public.js
r2064864 r3826948 189 189 } 190 190 } else { 191 console.log( 'response', response ); 192 191 193 jQuery("#frm_user_signin").trigger('reset'); 192 194 jQuery('#frm_user_signin #responce-messages .success-msg').text(response.success); 193 195 jQuery('#frm_user_signin #responce-messages').show(); 194 196 jQuery('#frm_user_signin #responce-messages .success-msg').css('display', 'inline-block'); 195 //location.reload(true);197 location.reload(true); 196 198 //window.location = response.redirecturl; 197 199 } -
ajax-login-registration/trunk/public/templates/ajax-login-form.php
r3277009 r3826948 3 3 * Ajax Login Public View 4 4 */ 5 if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){ 6 $pageUrl = "https"; 7 } else { 8 $pageUrl = "http"; 9 } 10 $pageUrl .= "://"; 11 $pageUrl .= $_SERVER['HTTP_HOST']; 12 $pageUrl .= isset( $_SERVER['REDIRECT_URL'] ) ? rtrim($_SERVER['REDIRECT_URL'], '/') : ''; 5 $page_id = get_queried_object_id(); 6 $pageUrl = get_permalink( $page_id ); 13 7 ?> 8 <div class="form-container"> 14 9 <?php 15 10 if( isset($_REQUEST['action']) && $_REQUEST['action'] == 'lostpassword' ){ ?> 16 <div class="form-container">17 11 <form id="frm_forgot_password" method="post"> 18 12 <?php … … 28 22 </div> 29 23 <div class="form-group submit-button"> 30 <input type="hidden" name="forgot_password_page" id="forgot_password_page" value="<?php echo $pageUrl; ?>" />24 <input type="hidden" name="forgot_password_page" id="forgot_password_page" value="<?php echo esc_attr( $page_id ); ?>" /> 31 25 <input type="hidden" name="forgot_password_nonce" id="forgot_password_nonce" value="<?php echo wp_create_nonce('forgot-password'); ?>" /> 32 26 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> … … 44 38 </div> 45 39 </form> 46 </div>47 40 <?php } else if( isset($_REQUEST['action']) && $_REQUEST['action'] == 'rp' ){ ?> 48 41 <?php if( isset ( $_REQUEST['user_id']) && isset( $_REQUEST['rp_activation_token']) && !empty( $_REQUEST['user_id']) && !empty( $_REQUEST['rp_activation_token']) ){ ?> 49 42 <?php 50 $user_id = $_REQUEST['user_id']; 51 $activation_token = get_user_meta( $user_id, 'rp_activation_token', 1 ); 52 $activation_time = get_user_meta( $user_id, 'rp_activation_time', 1 ); 53 $timeDifference = time() - $activation_time; 54 if( ( $activation_token != $_REQUEST['rp_activation_token'] ) || ( $timeDifference > 3600 ) ){ ?> 55 <script type="text/javascript">window.location = "<?php echo $pageUrl; ?>?action=lostpassword&error=invalidkey";</script> 43 $user_id = absint( $this->request_string( $_GET, 'user_id' ) ); 44 $token = $this->request_string( $_GET, 'rp_activation_token' ); 45 if ( ! $this->validate_reset_token( $user_id, $token ) ) { ?> 46 <script type="text/javascript">window.location = <?php echo wp_json_encode( add_query_arg( array( 'action' => 'lostpassword', 'error' => 'invalidkey' ), $pageUrl ), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); ?>;</script> 56 47 <?php 57 48 } else { ?> 58 <div class="form-container"> 59 <form id="frm_reset_password" method="post"> 60 <div class="form-group"> 61 <input type="password" name="new_password" id="new_password" class="form-control" placeholder="<?php echo __('New password', 'ajax-login-registration'); ?>"> 62 </div> 63 <div class="form-group"> 64 <input type="password" name="renew_password" id="renew_password" class="form-control" placeholder="<?php echo __('Confirm new password', 'ajax-login-registration'); ?>"> 65 </div> 66 <div class="form-group submit-button"> 67 <input type="hidden" name="rp_activation_token" id="rp_activation_token" value="<?php echo $_REQUEST['rp_activation_token']; ?>" /> 68 <input type="hidden" name="user_id" id="user_id" value="<?php echo $_REQUEST['user_id']; ?>" /> 69 <input type="hidden" name="reset_password_page" id="reset_password_page" value="<?php echo $pageUrl; ?>" /> 70 <input type="hidden" name="reset_password_nonce" id="reset_password_nonce" value="<?php echo wp_create_nonce('reset-password'); ?>" /> 71 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> 72 <span class="ajax-loader"></span> 73 </div> 74 <div id="responce-messages"> 75 <div class="error-msg"></div> 76 <div class="success-msg"></div> 77 </div> 78 </form> 79 </div> 49 <form id="frm_reset_password" method="post"> 50 <div class="form-group"> 51 <input type="password" name="new_password" id="new_password" class="form-control" placeholder="<?php echo __('New password', 'ajax-login-registration'); ?>"> 52 </div> 53 <div class="form-group"> 54 <input type="password" name="renew_password" id="renew_password" class="form-control" placeholder="<?php echo __('Confirm new password', 'ajax-login-registration'); ?>"> 55 </div> 56 <div class="form-group submit-button"> 57 <input type="hidden" name="rp_activation_token" id="rp_activation_token" value="<?php echo esc_attr( $token ); ?>" /> 58 <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $user_id ); ?>" /> 59 <input type="hidden" name="reset_password_page" id="reset_password_page" value="<?php echo esc_attr( $page_id ); ?>" /> 60 <input type="hidden" name="reset_password_nonce" id="reset_password_nonce" value="<?php echo wp_create_nonce('reset-password'); ?>" /> 61 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> 62 <span class="ajax-loader"></span> 63 </div> 64 <div id="responce-messages"> 65 <div class="error-msg"></div> 66 <div class="success-msg"></div> 67 </div> 68 </form> 80 69 <?php } 81 70 ?> 82 71 <?php } ?> 83 72 <?php } else { ?> 84 <div class="form-container"> 73 <?php if ( is_user_logged_in() ) { ?> 74 <p><?php echo __( 'You are already logged in.', 'ajax-login-registration'); ?> <a href="<?php echo esc_url( wp_logout_url( get_permalink() ) ); ?>"><?php echo __( 'Log out', 'ajax-login-registration'); ?></a></p> 75 <?php } else { ?> 85 76 <form id="frm_user_signin" method="post"> 86 77 <div class="form-group"> … … 95 86 ?> 96 87 <div class="form-group forgotten-pass"> 97 <a href=" ?action=lostpassword"><?php echo $password_text; ?></a>88 <a href="<?php echo esc_url( add_query_arg( 'action', 'lostpassword', $pageUrl ) ); ?>"><?php echo $password_text; ?></a> 98 89 </div> 99 90 <?php } ?> 100 91 <div class="form-group submit-button"> 101 <input type="hidden" name="signin_page" id="signin_page" value="<?php echo $pageUrl; ?>" />92 <input type="hidden" name="signin_page" id="signin_page" value="<?php echo esc_attr( $page_id ); ?>" /> 102 93 <input type="hidden" name="signin_nonce" id="signin_nonce" value="<?php echo wp_create_nonce('signin-nonce'); ?>" /> 103 94 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> … … 117 108 </div> 118 109 </form> 110 <?php } ?> 111 <?php } ?> 119 112 </div> 120 <?php } ?> -
ajax-login-registration/trunk/public/templates/ajax-registration-form.php
r3277009 r3826948 3 3 * Ajax Registration Public View 4 4 */ 5 if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){ 6 $pageUrl = "https"; 7 } else { 8 $pageUrl = "http"; 9 } 10 $pageUrl .= "://"; 11 $pageUrl .= $_SERVER['HTTP_HOST']; 12 $pageUrl .= isset( $_SERVER['REDIRECT_URL'] ) ? rtrim($_SERVER['REDIRECT_URL'], '/') : ''; 5 $page_id = get_queried_object_id(); 6 $pageUrl = get_permalink( $page_id ); 13 7 14 8 if(isset($_GET['account-activation']) && $_GET['account-activation'] == 'yes' ){ 15 9 if( isset ( $_GET['user_id']) && isset( $_GET['activation_token']) && !empty( $_GET['user_id']) && !empty( $_GET['activation_token']) ){ 16 $user_id = $_GET['user_id'];17 $activation_token = get_user_meta( $user_id, 'activation_token', 1);18 $activation_time = get_user_meta( $user_id, 'activation_token_time', 1);19 $timeDifference = time() - $activation_time;20 if( ($activation_token != $_GET['activation_token']) || ( $timeDifference > 3600 ) ){10 $user_id = absint( $this->request_string( $_GET, 'user_id' ) ); 11 $token = $this->request_string( $_GET, 'activation_token' ); 12 $activation_token = get_user_meta( $user_id, 'activation_token', true ); 13 $activation_time = (int) get_user_meta( $user_id, 'activation_token_time', true ); 14 if ( ! $user_id || '' === $token || ! is_string( $activation_token ) || ! hash_equals( $activation_token, hash( 'sha256', $token ) ) || ! $activation_time || $activation_time > time() || time() - $activation_time >= HOUR_IN_SECONDS || 'pending' !== get_user_meta( $user_id, 'user_active_status', true ) ) { 21 15 ?> 22 16 <div> … … 33 27 <?php 34 28 } else { 35 update_user_meta( $user_id, 'is_activated', 1 ); 29 if ( ! delete_user_meta( $user_id, 'activation_token', $activation_token ) ) { return; } 30 delete_user_meta( $user_id, 'activation_token_time' ); 31 update_user_meta( $user_id, 'is_activated', 1 ); 36 32 update_user_meta( $user_id, 'user_active_status', 'registered' ); 37 33 //delete_user_meta( $user_id, 'user_active_status'); … … 62 58 if(get_option('activation_email')){ 63 59 $tokens = array( 64 'FIRSTNAME' => ucfirst( $firstname),65 'LASTNAME' => ucfirst( $lastname),60 'FIRSTNAME' => esc_html( ucfirst( $firstname ) ), 61 'LASTNAME' => esc_html( ucfirst( $lastname ) ), 66 62 'NEW_PASSWORD' => $user_password, 67 63 ); 68 64 $mail_content .= $this->make_email_template( get_option('activation_email'), $tokens ); 69 65 } else { 70 $mail_content .= '<p>Hello '. ucfirst($firstname).' '.ucfirst($lastname).',</p><p>Your account is activated successfully.</p><p>Your password is : '. $user_password.'</p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>';66 $mail_content .= '<p>Hello '.esc_html( ucfirst($firstname) ).' '.esc_html( ucfirst($lastname) ).',</p><p>Your account is activated successfully.</p><p>Your password is : '. esc_html( $user_password ) .'</p> <p>Thanks & Regards,<br/>'. get_bloginfo('name') .'</p>'; 71 67 } 72 68 $mail_content .= $mail_footer; … … 91 87 } else { 92 88 ?> 93 <div class="form-container"> 94 <form id="frm_user_signup" method="post"> 95 <div class="form-group"> 96 <input type="text" name="signup_username" id="signup_username" class="form-control" placeholder="<?php echo __('Username', 'ajax-login-registration'); ?>"> 97 </div> 98 <div class="form-group"> 99 <input type="text" name="signup_firstname" id="signup_firstname" class="form-control" placeholder="<?php echo __('First Name', 'ajax-login-registration'); ?>"> 100 </div> 101 <div class="form-group"> 102 <input type="text" name="signup_lastname" id="signup_lastname" class="form-control" placeholder="<?php echo __('Last Name', 'ajax-login-registration'); ?>"> 103 </div> 104 <div class="form-group"> 105 <input type="text" name="signup_email" id="signup_email" class="form-control" placeholder="<?php echo __('Email Address', 'ajax-login-registration'); ?>"> 106 </div> 107 <div class="form-group submit-button"> 108 <input type="hidden" name="signup_page" id="signup_page" value="<?php echo $pageUrl; ?>" /> 109 <input type="hidden" name="signup_nonce" id="signup_nonce" value="<?php echo wp_create_nonce('signup-nonce'); ?>" /> 110 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> 111 <span class="ajax-loader"></span> 112 </div> 113 <div id="responce-messages"> 114 <div class="error-msg"></div> 115 <div class="success-msg"></div> 116 <div class="warning-msg"></div> 117 </div> 118 </form> 119 </div> 89 <?php if ( is_user_logged_in() ) { ?> 90 <p><?php echo __( 'You are already logged in.', 'ajax-login-registration'); ?> <a href="<?php echo esc_url( wp_logout_url( get_permalink() ) ); ?>"><?php echo __( 'Log out', 'ajax-login-registration'); ?></a></p> 91 <?php } else { ?> 92 <div class="form-container"> 93 <form id="frm_user_signup" method="post"> 94 <div class="form-group"> 95 <input type="text" name="signup_username" id="signup_username" class="form-control" placeholder="<?php echo __('Username', 'ajax-login-registration'); ?>"> 96 </div> 97 <div class="form-group"> 98 <input type="text" name="signup_firstname" id="signup_firstname" class="form-control" placeholder="<?php echo __('First Name', 'ajax-login-registration'); ?>"> 99 </div> 100 <div class="form-group"> 101 <input type="text" name="signup_lastname" id="signup_lastname" class="form-control" placeholder="<?php echo __('Last Name', 'ajax-login-registration'); ?>"> 102 </div> 103 <div class="form-group"> 104 <input type="text" name="signup_email" id="signup_email" class="form-control" placeholder="<?php echo __('Email Address', 'ajax-login-registration'); ?>"> 105 </div> 106 <div class="form-group submit-button"> 107 <input type="hidden" name="signup_page" id="signup_page" value="<?php echo esc_attr( $page_id ); ?>" /> 108 <input type="hidden" name="signup_nonce" id="signup_nonce" value="<?php echo wp_create_nonce('signup-nonce'); ?>" /> 109 <button type="submit" class="btn"><?php echo __('Submit', 'ajax-login-registration'); ?></button> 110 <span class="ajax-loader"></span> 111 </div> 112 <div id="responce-messages"> 113 <div class="error-msg"></div> 114 <div class="success-msg"></div> 115 <div class="warning-msg"></div> 116 </div> 117 </form> 118 </div> 119 <?php } ?> 120 120 <?php } ?>
Note:
See TracChangeset
for help on using the changeset viewer.