mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
* added security condition to check that one logged-in user cannot activate another one user via email activation link;
* fixed double handler of email activation link (wp_die doesn't stop the script for some reason); * added redirects to login page with error notices instead of wp_die text;
This commit is contained in:
@@ -279,6 +279,8 @@ class Users {
|
||||
* @param {int} $expiration Expiration timestamp. Since 2.8.7.
|
||||
*/
|
||||
do_action( 'um_after_user_hash_is_changed', $user_id, $hash, $expiration );
|
||||
|
||||
$this->remove_cache( $user_id ); // Don't remove this line. It's required removing cache duplicate for the force case when re-send activation email.
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -113,16 +113,24 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
isset( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) ) { // valid token
|
||||
|
||||
$user_id = absint( $_REQUEST['user_id'] );
|
||||
if ( is_user_logged_in() && get_current_user_id() !== $user_id ) {
|
||||
// Cannot activate another user account. Please log out and try again.
|
||||
wp_safe_redirect( um_user_profile_url( get_current_user_id() ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
delete_option( "um_cache_userdata_{$user_id}" );
|
||||
|
||||
$account_secret_hash = get_user_meta( $user_id, 'account_secret_hash', true );
|
||||
if ( empty( $account_secret_hash ) || strtolower( sanitize_text_field( $_REQUEST['hash'] ) ) !== strtolower( $account_secret_hash ) ) {
|
||||
wp_die( esc_html__( 'This activation link is expired or have already been used.', 'ultimate-member' ) );
|
||||
wp_safe_redirect( add_query_arg( 'err', 'activation_link_used', um_get_core_page( 'login' ) ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
$account_secret_hash_expiry = get_user_meta( $user_id, 'account_secret_hash_expiry', true );
|
||||
if ( ! empty( $account_secret_hash_expiry ) && time() > $account_secret_hash_expiry ) {
|
||||
wp_die( esc_html__( 'This activation link is expired.', 'ultimate-member' ) );
|
||||
wp_safe_redirect( add_query_arg( 'err', 'activation_link_expired', um_get_core_page( 'login' ) ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
$redirect = um_get_core_page( 'login', 'account_active' );
|
||||
@@ -141,15 +149,7 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
// log in automatically
|
||||
$login = ! empty( $user_role_data['login_email_activate'] ); // Role setting "Login user after validating the activation link?"
|
||||
if ( ! is_user_logged_in() && $login ) {
|
||||
$user = get_userdata( $user_id );
|
||||
|
||||
// update wp user
|
||||
wp_set_current_user( $user_id, $user->user_login );
|
||||
wp_set_auth_cookie( $user_id );
|
||||
|
||||
ob_start();
|
||||
do_action( 'wp_login', $user->user_login, $user );
|
||||
ob_end_clean();
|
||||
UM()->user()->auto_login( $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1362,7 +1362,7 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
<?php UM()->user()->auto_login( 10, true ); ?>
|
||||
*
|
||||
*/
|
||||
function auto_login( $user_id, $rememberme = 0 ) {
|
||||
public function auto_login( $user_id, $rememberme = 0 ) {
|
||||
|
||||
wp_set_current_user( $user_id );
|
||||
|
||||
|
||||
@@ -176,6 +176,12 @@ function um_add_update_notice( $args ) {
|
||||
case 'invalid_nonce':
|
||||
$err = __( 'An error has been encountered. Probably page was cached. Please try again.', 'ultimate-member' );
|
||||
break;
|
||||
case 'activation_link_used':
|
||||
$err = __( 'This activation link is expired or have already been used.', 'ultimate-member' );
|
||||
break;
|
||||
case 'activation_link_expired':
|
||||
$err = __( 'This activation link is expired.', 'ultimate-member' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification -- used for echo and already verified here.
|
||||
|
||||
Reference in New Issue
Block a user