| 1 |
<?php |
| 2 |
/** |
| 3 |
* When a new member joins, confirm the authenticity of |
| 4 |
* the email address and the identity of the member. |
| 5 |
* |
| 6 |
* The following built-in templates have been added. |
| 7 |
* templates/cart/verifying.php |
| 8 |
* templates/cart/verified.php |
| 9 |
* templates/member/verifying.php |
| 10 |
* |
| 11 |
* @package Welcart |
| 12 |
*/ |
| 13 |
|
| 14 |
/** |
| 15 |
* Verify Members Email class |
| 16 |
*/ |
| 17 |
class USCES_VERIFY_MEMBERS_EMAIL { |
| 18 |
|
| 19 |
/** |
| 20 |
* Instance of this class. |
| 21 |
* |
| 22 |
* @var object |
| 23 |
*/ |
| 24 |
protected static $instance = null; |
| 25 |
|
| 26 |
/** |
| 27 |
* Verifyemail options |
| 28 |
* |
| 29 |
* @var array |
| 30 |
*/ |
| 31 |
public static $opts; |
| 32 |
|
| 33 |
/** |
| 34 |
* Initialization vector key |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
public static $verify_key; |
| 39 |
|
| 40 |
/** |
| 41 |
* Initialization vector key |
| 42 |
* |
| 43 |
* @var string |
| 44 |
*/ |
| 45 |
public static $algo; |
| 46 |
|
| 47 |
/** |
| 48 |
* Construct |
| 49 |
*/ |
| 50 |
public function __construct() { |
| 51 |
|
| 52 |
self::initialize_data(); |
| 53 |
self::$verify_key = 'zMsHTOIF6xRrmaMB'; |
| 54 |
self::$algo = 'AES-128-CBC'; |
| 55 |
|
| 56 |
if ( is_admin() ) { |
| 57 |
add_action( 'usces_action_admin_system_extentions', array( $this, 'setting_form' ) ); |
| 58 |
add_action( 'init', array( $this, 'save_data' ) ); |
| 59 |
} |
| 60 |
|
| 61 |
if ( self::$opts['switch_flag'] ) { |
| 62 |
|
| 63 |
add_action( 'wc_cron', array( $this, 'delete_flag' ) ); |
| 64 |
|
| 65 |
if ( ! is_admin() ) { |
| 66 |
add_filter( 'usces_filter_veirfyemail_newmemberform', array( $this, 'member_registered' ), 10, 2 ); |
| 67 |
add_filter( 'usces_filter_veirfyemail_newmemberfromcart', array( $this, 'member_registered' ), 10, 2 ); |
| 68 |
add_action( 'usces_main', array( $this, 'verified_email' ) ); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
if ( self::$opts['edit_flag'] && usces_is_membersystem_state() ) { |
| 73 |
|
| 74 |
add_action( 'wc_cron', array( $this, 'delete_edit_flag' ) ); |
| 75 |
|
| 76 |
if ( ! is_admin() ) { |
| 77 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 78 |
add_action( 'wp_print_styles', array( $this, 'print_styles' ) ); |
| 79 |
add_action( 'usces_main', array( $this, 'member_auth_first' ), 1 ); |
| 80 |
add_filter( 'usces_filter_template_redirect', array( $this, 'member_auth' ), 1 ); |
| 81 |
add_action( 'usces_main', array( $this, 'verified_member' ) ); |
| 82 |
add_filter( 'usces_filter_login_inform', array( $this, 'login_inform' ) ); |
| 83 |
add_action( 'usces_action_login_page_inform', array( $this, 'login_page_inform' ) ); |
| 84 |
add_filter( 'usces_filter_member_submenu_list', array( $this, 'member_submenu_list' ), 99, 2 ); |
| 85 |
add_action( 'usces_action_member_logined', array( $this, 'after_login' ) ); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
if ( self::$opts['login_notify'] && usces_is_membersystem_state() ) { |
| 90 |
add_action( 'usces_action_after_login', array( $this, 'login_notify' ) ); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Return an instance of this class. |
| 96 |
*/ |
| 97 |
public static function get_instance() { |
| 98 |
if ( is_null( self::$instance ) ) { |
| 99 |
self::$instance = new self(); |
| 100 |
} |
| 101 |
return self::$instance; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Initialize |
| 106 |
* Modified:30 Sep.2019 |
| 107 |
*/ |
| 108 |
public function initialize_data() { |
| 109 |
global $usces; |
| 110 |
|
| 111 |
$options = get_option( 'usces_ex', array() ); |
| 112 |
$options['system']['verifyemail']['switch_flag'] = ! isset( $options['system']['verifyemail']['switch_flag'] ) ? 0 : (int) $options['system']['verifyemail']['switch_flag']; |
| 113 |
$options['system']['verifyemail']['edit_flag'] = ! isset( $options['system']['verifyemail']['edit_flag'] ) ? 1 : (int) $options['system']['verifyemail']['edit_flag']; |
| 114 |
$options['system']['verifyemail']['login_notify'] = ! isset( $options['system']['verifyemail']['login_notify'] ) ? 0 : (int) $options['system']['verifyemail']['login_notify']; |
| 115 |
update_option( 'usces_ex', $options ); |
| 116 |
self::$opts = $options['system']['verifyemail']; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Save option data |
| 121 |
* Modified:30 Sep.2019 |
| 122 |
*/ |
| 123 |
public function save_data() { |
| 124 |
global $usces; |
| 125 |
|
| 126 |
if ( isset( $_POST['usces_verifyemail_option_update'] ) ) { |
| 127 |
|
| 128 |
check_admin_referer( 'admin_system', 'wc_nonce' ); |
| 129 |
if ( ! current_user_can( 'wel_manage_setting' ) ) { |
| 130 |
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
| 131 |
} |
| 132 |
|
| 133 |
if ( isset( $_POST['verifyemail_switch_flag'] ) ) { |
| 134 |
self::$opts['switch_flag'] = (int) $_POST['verifyemail_switch_flag']; |
| 135 |
} else { |
| 136 |
self::$opts['switch_flag'] = 0; |
| 137 |
} |
| 138 |
|
| 139 |
if ( isset( $_POST['verifyemail_edit_flag'] ) ) { |
| 140 |
self::$opts['edit_flag'] = (int) $_POST['verifyemail_edit_flag']; |
| 141 |
} else { |
| 142 |
self::$opts['edit_flag'] = 0; |
| 143 |
} |
| 144 |
|
| 145 |
if ( isset( $_POST['verifyemail_login_notify'] ) ) { |
| 146 |
self::$opts['login_notify'] = (int) $_POST['verifyemail_login_notify']; |
| 147 |
} else { |
| 148 |
self::$opts['login_notify'] = 0; |
| 149 |
} |
| 150 |
|
| 151 |
$options = get_option( 'usces_ex', array() ); |
| 152 |
$options['system']['verifyemail'] = self::$opts; |
| 153 |
update_option( 'usces_ex', $options ); |
| 154 |
|
| 155 |
if ( 0 === self::$opts['edit_flag'] ) { |
| 156 |
$this->delete_edit_flag(); |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Setting form |
| 163 |
* Modified:30 Sep.2019 |
| 164 |
*/ |
| 165 |
public function setting_form() { |
| 166 |
$status = ( self::$opts['switch_flag'] || self::$opts['edit_flag'] || self::$opts['login_notify'] ) ? '<span class="running">' . __( 'Running', 'usces' ) . '</span>' : '<span class="stopped">' . __( 'Stopped', 'usces' ) . '</span>'; |
| 167 |
?> |
| 168 |
<form action="" method="post" name="option_form" id="verifyemail_form"> |
| 169 |
<div class="postbox"> |
| 170 |
<div class="postbox-header"> |
| 171 |
<h2><span><?php esc_html_e( 'Security on membership', 'usces' ); ?></span><?php echo wp_kses_post( $status ); ?></h2> |
| 172 |
<div class="handle-actions"><button type="button" class="handlediv" id="verifyemail"><span class="screen-reader-text"><?php echo esc_html( sprintf( __( 'Toggle panel: %s' ), __( 'Security on membership', 'usces' ) ) ); ?></span><span class="toggle-indicator"></span></button></div> |
| 173 |
</div> |
| 174 |
<div class="inside"> |
| 175 |
<table class="form_table"> |
| 176 |
<tr height="35"> |
| 177 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_verifyemail_switch_flag');"><?php esc_html_e( 'Email verification for new registration', 'usces' ); ?></a></th> |
| 178 |
<td width="10"><input name="verifyemail_switch_flag" id="verifyemail_switch_flag0" type="radio" value="0"<?php checked( self::$opts['switch_flag'], 0 ); ?> /></td><td width="100"><label for="verifyemail_switch_flag0"><?php esc_html_e( 'disable', 'usces' ); ?></label></td> |
| 179 |
<td width="10"><input name="verifyemail_switch_flag" id="verifyemail_switch_flag1" type="radio" value="1"<?php checked( self::$opts['switch_flag'], 1 ); ?> /></td><td width="100"><label for="verifyemail_switch_flag1"><?php esc_html_e( 'enable', 'usces' ); ?></label></td> |
| 180 |
<td><div id="ex_verifyemail_switch_flag" class="explanation"><?php esc_html_e( 'Send an e-mail to the e-mail address registered when new member registration, and make them approve that the e-mail address is definitely their own.', 'usces' ); ?></div></td> |
| 181 |
</tr> |
| 182 |
<tr height="35"> |
| 183 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_verifyemail_edit_flag');"><?php esc_html_e( 'Email verification for editing information', 'usces' ); ?></a></th> |
| 184 |
<td width="10"><input name="verifyemail_edit_flag" id="verifyemail_edit_flag0" type="radio" value="0"<?php checked( self::$opts['edit_flag'], 0 ); ?> /></td><td width="100"><label for="verifyemail_edit_flag0"><?php esc_html_e( 'disable', 'usces' ); ?></label></td> |
| 185 |
<td width="10"><input name="verifyemail_edit_flag" id="verifyemail_edit_flag1" type="radio" value="1"<?php checked( self::$opts['edit_flag'], 1 ); ?> /></td><td width="100"><label for="verifyemail_edit_flag1"><?php esc_html_e( 'enable', 'usces' ); ?></label></td> |
| 186 |
<td><div id="ex_verifyemail_edit_flag" class="explanation"><?php esc_html_e( "When editing membership information, an email will be sent to the member's email address to confirm that the change is indeed made by the member. Membership information cannot be edited unless the authentication link is clicked.", 'usces' ); ?></div></td> |
| 187 |
</tr> |
| 188 |
<tr height="35"> |
| 189 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_verifyemail_login_notify');"><?php esc_html_e( 'Login Notification', 'usces' ); ?></a></th> |
| 190 |
<td width="10"><input name="verifyemail_login_notify" id="verifyemail_login_notify0" type="radio" value="0"<?php checked( self::$opts['login_notify'], 0 ); ?> /></td><td width="100"><label for="verifyemail_login_notify0"><?php esc_html_e( 'disable', 'usces' ); ?></label></td> |
| 191 |
<td width="10"><input name="verifyemail_login_notify" id="verifyemail_login_notify1" type="radio" value="1"<?php checked( self::$opts['login_notify'], 1 ); ?> /></td><td width="100"><label for="verifyemail_login_notify1"><?php esc_html_e( 'enable', 'usces' ); ?></label></td> |
| 192 |
<td><div id="ex_verifyemail_login_notify" class="explanation"><?php esc_html_e( 'An email will be sent to the member notifying them that they have logged in.', 'usces' ); ?></div></td> |
| 193 |
</tr> |
| 194 |
</table> |
| 195 |
<hr /> |
| 196 |
<input name="usces_verifyemail_option_update" type="submit" class="button button-primary" value="<?php esc_attr_e( 'change decision', 'usces' ); ?>" /> |
| 197 |
</div> |
| 198 |
</div><!--postbox--> |
| 199 |
<?php wp_nonce_field( 'admin_system', 'wc_nonce' ); ?> |
| 200 |
</form> |
| 201 |
<?php |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Member Registration |
| 206 |
* usces_filter_veirfyemail_newmemberform |
| 207 |
* usces_filter_veirfyemail_newmemberfromcart |
| 208 |
* Modified:30 Sep.2019 |
| 209 |
* |
| 210 |
* @param bool $ob Switch. |
| 211 |
* @param array $member Member data. |
| 212 |
* @return bool |
| 213 |
*/ |
| 214 |
public function member_registered( $ob, $member ) { |
| 215 |
global $usces; |
| 216 |
|
| 217 |
$time = current_time( 'timestamp' ); |
| 218 |
$usces->set_member_meta_value( '_verifying', $time, $member['ID'] ); |
| 219 |
$member_regmode = wp_unslash( $_POST['member_regmode'] ); |
| 220 |
|
| 221 |
if ( 'newmemberform' === $member_regmode ) { |
| 222 |
add_filter( 'usces_filter_template_redirect', array( $this, 'start_verifying' ) ); |
| 223 |
} elseif ( 'newmemberfromcart' === $member_regmode ) { |
| 224 |
add_filter( 'usces_filter_template_redirect', array( $this, 'start_verifying_cart' ) ); |
| 225 |
$member['flat_pass'] = wp_unslash( $_POST['customer']['password1'] ); |
| 226 |
} |
| 227 |
|
| 228 |
remove_filter( 'usces_filter_template_redirect', 'dlseller_filter_template_redirect', 2 ); |
| 229 |
|
| 230 |
$member['regmode'] = $member_regmode; |
| 231 |
$this->send_verifymail( $member ); |
| 232 |
unset( $_SESSION['usces_member'] ); |
| 233 |
|
| 234 |
return true; |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Start verifying |
| 239 |
* Modified:30 Sep.2019 |
| 240 |
*/ |
| 241 |
public function start_verifying() { |
| 242 |
global $usces; |
| 243 |
|
| 244 |
if ( file_exists( get_theme_file_path( '/wc_templates/member/wc_member_verifying.php' ) ) ) { |
| 245 |
include get_theme_file_path( '/wc_templates/member/wc_member_verifying.php' ); |
| 246 |
exit; |
| 247 |
} |
| 248 |
|
| 249 |
return true; |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* Start verifying |
| 254 |
* Modified:30 Sep.2019 |
| 255 |
*/ |
| 256 |
public function start_verifying_cart() { |
| 257 |
global $usces; |
| 258 |
|
| 259 |
if ( file_exists( get_theme_file_path( '/wc_templates/cart/wc_cart_verifying.php' ) ) ) { |
| 260 |
include get_theme_file_path( '/wc_templates/cart/wc_cart_verifying.php' ); |
| 261 |
exit; |
| 262 |
} |
| 263 |
|
| 264 |
return true; |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Send verifymail |
| 269 |
* Modified:30 Sep.2019 |
| 270 |
* |
| 271 |
* @param array $user User data. |
| 272 |
* @return bool |
| 273 |
*/ |
| 274 |
public function send_verifymail( $user ) { |
| 275 |
global $usces; |
| 276 |
|
| 277 |
$remaining_hour = $this->get_remaining_hour(); |
| 278 |
$res = false; |
| 279 |
$newmem_admin_mail = $usces->options['newmem_admin_mail']; |
| 280 |
$name = sprintf( _x( '%s', 'honorific', 'usces' ), usces_localized_name( trim( $user['name1'] ), trim( $user['name2'] ), 'return' ) ); |
| 281 |
$mailaddress1 = trim( $user['mailaddress1'] ); |
| 282 |
|
| 283 |
$subject = apply_filters( 'usces_filter_send_verifymembermail_subject', __( 'Request email confirmation', 'usces' ), $user ); |
| 284 |
$message = sprintf( __( 'Thank you for registering to %s.', 'usces' ), html_entity_decode( get_option( 'blogname' ) ) ) . "\r\n\r\n"; |
| 285 |
$message .= __( 'By accessing the following URL, you can complete membership registration.', 'usces' ) . "\r\n"; |
| 286 |
$message .= __( 'Please note that the procedure has not been completed until you receive registration complete e-mail.', 'usces' ) . "\r\n\r\n"; |
| 287 |
$message .= sprintf( __( 'The following URL is valid for %d hours. If it expires, please try again from the beginning.', 'usces' ), $remaining_hour ) . "\r\n\r\n"; |
| 288 |
$message .= $this->get_verify_url( $user ) . "\r\n\r\n"; |
| 289 |
|
| 290 |
$message .= '--------------------------------' . "\r\n"; |
| 291 |
$message .= __( 'Please delete this email if you were not aware that you were going to receive it.', 'usces' ) . "\r\n"; |
| 292 |
$message .= '--------------------------------' . "\r\n\r\n"; |
| 293 |
$message .= html_entity_decode( get_option( 'blogname' ) ) . "\r\n"; |
| 294 |
if ( 1 === (int) $usces->options['put_customer_name'] ) { |
| 295 |
$dear_name = sprintf( __( 'Dear %s', 'usces' ), usces_localized_name( trim( $user['name1'] ), trim( $user['name2'] ), 'return' ) ); |
| 296 |
$message = $dear_name . "\r\n\r\n" . $message; |
| 297 |
} |
| 298 |
$message = apply_filters( 'usces_filter_send_verifymembermail_message', $message, $user ); |
| 299 |
|
| 300 |
$para1 = array( |
| 301 |
'to_name' => $name, |
| 302 |
'to_address' => $mailaddress1, |
| 303 |
'from_name' => get_option( 'blogname' ), |
| 304 |
'from_address' => $usces->options['sender_mail'], |
| 305 |
'reply_name' => get_option( 'blogname' ), |
| 306 |
'reply_to' => usces_get_first_order_mail(), |
| 307 |
'return_path' => $usces->options['sender_mail'], |
| 308 |
'subject' => $subject, |
| 309 |
'message' => do_shortcode( $message ), |
| 310 |
); |
| 311 |
$para1 = apply_filters( 'usces_filter_send_verifymembermail_para1', $para1 ); |
| 312 |
$res = usces_send_mail( $para1 ); |
| 313 |
return $res; |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
* Get verify url |
| 318 |
* Modified:30 Sep.2019 |
| 319 |
* |
| 320 |
* @param array $user User data. |
| 321 |
* @return string |
| 322 |
*/ |
| 323 |
public function get_verify_url( $user ) { |
| 324 |
global $usces; |
| 325 |
|
| 326 |
$encrypt_value = $this->encrypt_value( $user ); |
| 327 |
$query = array( |
| 328 |
'verify' => $encrypt_value, |
| 329 |
'usces_page' => 'memberverified', |
| 330 |
'uscesid' => $usces->get_uscesid( false ), |
| 331 |
); |
| 332 |
$query = apply_filters( 'usces_filter_verifymail_query', $query, $user ); |
| 333 |
$url = add_query_arg( $query, USCES_MEMBER_URL ); |
| 334 |
|
| 335 |
return $url; |
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* Encrypt value |
| 340 |
* Modified:30 Sep.2019 |
| 341 |
* |
| 342 |
* @param array $user User data. |
| 343 |
* @return array |
| 344 |
*/ |
| 345 |
public function encrypt_value( $user ) { |
| 346 |
if ( isset( $user['auth_code'] ) ) { |
| 347 |
$datatext = $user['auth_code']; |
| 348 |
} else { |
| 349 |
$datatext = $user['regmode'] . ',' . $user['ID']; |
| 350 |
} |
| 351 |
$key = get_option( 'usces_wcid' ); |
| 352 |
$encrypt_value = openssl_encrypt( $datatext, self::$algo, $key, OPENSSL_RAW_DATA, self::$verify_key ); |
| 353 |
$encrypt_value = urlencode( base64_encode( $encrypt_value ) ); |
| 354 |
|
| 355 |
return $encrypt_value; |
| 356 |
} |
| 357 |
|
| 358 |
/** |
| 359 |
* Decrypt value |
| 360 |
* Modified:30 Sep.2019 |
| 361 |
* |
| 362 |
* @param string $value Value. |
| 363 |
* @return string |
| 364 |
*/ |
| 365 |
public function decrypt_value( $value ) { |
| 366 |
$key = get_option( 'usces_wcid' ); |
| 367 |
$data = base64_decode( $value ); |
| 368 |
$data = openssl_decrypt( $data, self::$algo, $key, OPENSSL_RAW_DATA, self::$verify_key ); |
| 369 |
|
| 370 |
return $data; |
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* Verified email |
| 375 |
* usces_main |
| 376 |
* Modified:30 Sep.2019 |
| 377 |
*/ |
| 378 |
public function verified_email() { |
| 379 |
global $usces; |
| 380 |
|
| 381 |
if ( ! $usces->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || ! isset( $_GET['verify'] ) ) { |
| 382 |
return; |
| 383 |
} |
| 384 |
|
| 385 |
usces_register_action( 'page_allow_email', 'get', 'usces_page', 'memberverified', array( $this, 'allow_email' ) ); |
| 386 |
add_filter( 'usces_filter_template_redirect', array( $this, 'complete_verifying' ) ); |
| 387 |
remove_filter( 'usces_filter_template_redirect', 'dlseller_filter_template_redirect', 2 ); |
| 388 |
} |
| 389 |
|
| 390 |
/** |
| 391 |
* Allow email |
| 392 |
* Modified:30 Sep.2019 |
| 393 |
*/ |
| 394 |
public function allow_email() { |
| 395 |
global $usces; |
| 396 |
|
| 397 |
if ( ! $usces->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || ! isset( $_GET['verify'] ) ) { |
| 398 |
return; |
| 399 |
} |
| 400 |
|
| 401 |
$value = wp_unslash( $_GET['verify'] ); |
| 402 |
$datatext = $this->decrypt_value( $value ); |
| 403 |
$data = explode( ',', $datatext ); |
| 404 |
$regmode = $data[0]; |
| 405 |
$mem_id = (int) $data[1]; |
| 406 |
$member = $usces->get_member_info( $mem_id ); |
| 407 |
$flag = $usces->get_member_meta_value( '_verifying', $mem_id ); |
| 408 |
if ( empty( $member ) || empty( $flag ) ) { |
| 409 |
wp_redirect( USCES_MEMBER_URL ); |
| 410 |
exit; |
| 411 |
} |
| 412 |
|
| 413 |
$user = array(); |
| 414 |
foreach ( $member as $key => $value ) { |
| 415 |
if ( 'mem_email' === $key ) { |
| 416 |
$user['mailaddress1'] = $value; |
| 417 |
} elseif ( 'mem_name1' === $key ) { |
| 418 |
$user['name1'] = $value; |
| 419 |
} elseif ( 'mem_name2' === $key ) { |
| 420 |
$user['name2'] = $value; |
| 421 |
} elseif ( 'mem_name3' === $key ) { |
| 422 |
$user['name3'] = $value; |
| 423 |
} elseif ( 'mem_name4' === $key ) { |
| 424 |
$user['name4'] = $value; |
| 425 |
} elseif ( 'mem_zip' === $key ) { |
| 426 |
$user['zipcode'] = $value; |
| 427 |
} elseif ( 'customer_country' === $key ) { |
| 428 |
$user['country'] = $value; |
| 429 |
} elseif ( 'mem_pref' === $key ) { |
| 430 |
$user['pref'] = $value; |
| 431 |
} elseif ( 'mem_address1' === $key ) { |
| 432 |
$user['address1'] = $value; |
| 433 |
} elseif ( 'mem_address2' === $key ) { |
| 434 |
$user['address2'] = $value; |
| 435 |
} elseif ( 'mem_address3' === $key ) { |
| 436 |
$user['address3'] = $value; |
| 437 |
} elseif ( 'mem_tel' === $key ) { |
| 438 |
$user['tel'] = $value; |
| 439 |
} elseif ( 'mem_fax' === $key ) { |
| 440 |
$user['fax'] = $value; |
| 441 |
} else { |
| 442 |
$user[ $key ] = $value; |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
$usces->del_member_meta( '_verifying', $mem_id ); |
| 447 |
|
| 448 |
do_action( 'usces_action_member_registered', $user, $mem_id ); |
| 449 |
usces_send_regmembermail( $user ); |
| 450 |
|
| 451 |
if ( 'newmemberform' === $regmode ) { |
| 452 |
unset( $_SESSION['usces_member'] ); |
| 453 |
$usces->page = 'newcompletion'; |
| 454 |
add_action( 'the_post', array( $usces, 'action_memberFilter' ) ); |
| 455 |
add_action( 'template_redirect', array( $usces, 'template_redirect' ) ); |
| 456 |
|
| 457 |
do_action( 'usces_action_after_newmemberform_verified', $user, $data ); |
| 458 |
|
| 459 |
} elseif ( 'newmemberfromcart' === $regmode ) { |
| 460 |
unset( $_SESSION['usces_entry']['customer'] ); |
| 461 |
$usces->page = 'cartverified'; |
| 462 |
add_action( 'the_post', array( $usces, 'action_cartFilter' ) ); |
| 463 |
add_action( 'template_redirect', array( $usces, 'template_redirect' ) ); |
| 464 |
|
| 465 |
do_action( 'usces_action_after_newmemberfromcart_verified', $user, $data ); |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
/** |
| 470 |
* Complete verifying |
| 471 |
* Modified:30 Sep.2019 |
| 472 |
*/ |
| 473 |
public function complete_verifying() { |
| 474 |
global $usces; |
| 475 |
|
| 476 |
if ( file_exists( get_theme_file_path( '/wc_templates/cart/wc_cart_verified.php' ) ) ) { |
| 477 |
include get_theme_file_path( '/wc_templates/cart/wc_cart_verified.php' ); |
| 478 |
exit; |
| 479 |
} |
| 480 |
|
| 481 |
return true; |
| 482 |
} |
| 483 |
|
| 484 |
/** |
| 485 |
* Get remaining hour |
| 486 |
* Modified:30 Sep.2019 |
| 487 |
*/ |
| 488 |
public static function get_remaining_hour() { |
| 489 |
$crons = _get_cron_array(); |
| 490 |
$remaining_time = 0; |
| 491 |
foreach ( $crons as $time => $cron ) { |
| 492 |
foreach ( $cron as $key => $value ) { |
| 493 |
if ( 'wc_cron' === $key ) { |
| 494 |
$remaining_time = $time - current_time( 'timestamp', 1 ); |
| 495 |
} |
| 496 |
} |
| 497 |
} |
| 498 |
$remaining_hour = floor( $remaining_time / 3600 ); |
| 499 |
if ( 1 > $remaining_hour ) { |
| 500 |
$remaining_hour = 1; |
| 501 |
} |
| 502 |
|
| 503 |
return $remaining_hour; |
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* 'wc_cron' event |
| 508 |
* Modified:30 Sep.2019 |
| 509 |
*/ |
| 510 |
public function delete_flag() { |
| 511 |
global $wpdb; |
| 512 |
|
| 513 |
$table = usces_get_tablename( 'usces_member_meta' ); |
| 514 |
$mem_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `member_id` FROM {$table} WHERE `meta_key` = %s", '_verifying' ) ); |
| 515 |
|
| 516 |
foreach ( (array) $mem_ids as $mem_id ) { |
| 517 |
usces_delete_memberdata( $mem_id ); |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
/** |
| 522 |
* Delete expired authentication flags. |
| 523 |
*/ |
| 524 |
public function delete_edit_flag() { |
| 525 |
global $usces, $wpdb; |
| 526 |
|
| 527 |
$member_meta_table = usces_get_tablename( 'usces_member_meta' ); |
| 528 |
$member_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `member_id` FROM {$member_meta_table} WHERE `meta_key` = %s", 'auth_url_creation_time' ) ); |
| 529 |
if ( ! empty( $member_ids ) ) { |
| 530 |
$now = current_time( 'timestamp' ); |
| 531 |
foreach ( (array) $member_ids as $member_id ) { |
| 532 |
$time = $usces->get_member_meta_value( 'auth_url_creation_time', $member_id ); |
| 533 |
if ( $time < $now ) { |
| 534 |
$usces->del_member_meta( 'auth_url_creation_time', $member_id ); |
| 535 |
$usces->del_member_meta( 'member_edit_auth_code', $member_id ); |
| 536 |
} |
| 537 |
} |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
/** |
| 542 |
* Member information editing page. |
| 543 |
* |
| 544 |
* @return bool |
| 545 |
*/ |
| 546 |
private function is_member_edit_page() { |
| 547 |
global $usces; |
| 548 |
|
| 549 |
$member_edit = false; |
| 550 |
if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) { |
| 551 |
$usces_page = ( ! empty( $usces->page ) ) ? $usces->page : filter_input( INPUT_GET, 'usces_page', FILTER_DEFAULT ); |
| 552 |
switch ( $usces_page ) { |
| 553 |
case 'newmember': |
| 554 |
case 'member_auth_error': |
| 555 |
case 'member_register_settlement': |
| 556 |
case 'member_update_settlement': |
| 557 |
case 'member_auto_billing_info': |
| 558 |
case 'member_favorite_page': |
| 559 |
case 'autodelivery_history': |
| 560 |
case 'msa_setting': |
| 561 |
case 'mda_setting': |
| 562 |
$member_edit = false; |
| 563 |
break; |
| 564 |
default: |
| 565 |
$member_edit = true; |
| 566 |
} |
| 567 |
} |
| 568 |
return $member_edit; |
| 569 |
} |
| 570 |
|
| 571 |
/** |
| 572 |
* Front scripts. |
| 573 |
* wp_enqueue_scripts |
| 574 |
*/ |
| 575 |
public function enqueue_scripts() { |
| 576 |
global $usces; |
| 577 |
|
| 578 |
if ( $this->is_member_edit_page() ) { |
| 579 |
$member = $usces->get_member(); |
| 580 |
$edit_url = add_query_arg( |
| 581 |
array( |
| 582 |
'usces_page' => 'member_edit', |
| 583 |
), |
| 584 |
USCES_MEMBER_URL |
| 585 |
); |
| 586 |
$card_reg_url = add_query_arg( |
| 587 |
array( |
| 588 |
'usces_page' => 'member_register_settlement', |
| 589 |
're-enter' => 1, |
| 590 |
), |
| 591 |
USCES_MEMBER_URL |
| 592 |
); |
| 593 |
$card_upd_url = add_query_arg( |
| 594 |
array( |
| 595 |
'usces_page' => 'member_update_settlement', |
| 596 |
're-enter' => 1, |
| 597 |
), |
| 598 |
USCES_MEMBER_URL |
| 599 |
); |
| 600 |
wp_register_script( 'wel-member-auth', USCES_FRONT_PLUGIN_URL . '/js/member_auth.js', array( 'jquery' ), USCES_VERSION, true ); |
| 601 |
$member_params = array(); |
| 602 |
$member_params['url']['go2top'] = esc_url( home_url() ); |
| 603 |
$member_params['url']['edit'] = $edit_url; |
| 604 |
$member_params['url']['card_reg'] = $card_reg_url; |
| 605 |
$member_params['url']['card_upd'] = $card_upd_url; |
| 606 |
$member_params['label']['go2top'] = esc_html__( 'Back to the top page.', 'usces' ); |
| 607 |
$member_params['label']['edit'] = esc_html__( 'To member information editing', 'usces' ); |
| 608 |
$member_params['message']['edit'] = esc_html__( 'Identity verification is required to edit your membership information. Are you sure you want to send an authentication email to your registered email address?', 'usces' ); |
| 609 |
$member_params['message']['card_reg'] = esc_html__( 'Identity verification is required to register credit card information. Are you sure you want to send an authentication email to your registered email address?', 'usces' ); |
| 610 |
$member_params['message']['card_upd'] = esc_html__( 'Identity verification is required to change credit card information. Are you sure you want to send an authentication email to your registered email address?', 'usces' ); |
| 611 |
$member_params['message']['done'] = esc_html__( 'Successfully updated.', 'usces' ); |
| 612 |
$member_params['edit_auth'] = ( isset( $member['edit_auth'] ) ) ? $member['edit_auth'] : ''; |
| 613 |
wp_localize_script( 'wel-member-auth', 'member_params', $member_params ); |
| 614 |
wp_enqueue_script( 'wel-member-auth' ); |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
/** |
| 619 |
* Front styles. |
| 620 |
* wp_print_styles |
| 621 |
*/ |
| 622 |
public function print_styles() { |
| 623 |
if ( $this->is_member_edit_page() ) : |
| 624 |
?> |
| 625 |
<style type="text/css"> |
| 626 |
.send { |
| 627 |
padding-top: .714286em; |
| 628 |
text-align: center; |
| 629 |
} |
| 630 |
</style> |
| 631 |
<?php |
| 632 |
endif; |
| 633 |
} |
| 634 |
|
| 635 |
/** |
| 636 |
* Authenticate first. |
| 637 |
* usces_main |
| 638 |
*/ |
| 639 |
public function member_auth_first() { |
| 640 |
global $usces; |
| 641 |
|
| 642 |
if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) { |
| 643 |
if ( ! usces_is_login() ) { |
| 644 |
return; |
| 645 |
} |
| 646 |
$usces_page = ( ! empty( $usces->page ) ) ? $usces->page : filter_input( INPUT_GET, 'usces_page', FILTER_DEFAULT ); |
| 647 |
switch ( $usces_page ) { |
| 648 |
case 'member_register_settlement': |
| 649 |
case 'member_update_settlement': |
| 650 |
$member = $usces->get_member(); |
| 651 |
if ( ! $this->member_auth_check( $member ) ) { |
| 652 |
$usces->page = 'member_edit'; |
| 653 |
$url = add_query_arg( |
| 654 |
array( |
| 655 |
'usces_page' => 'member_edit', |
| 656 |
'usces_subpage' => $usces_page, |
| 657 |
), |
| 658 |
USCES_MEMBER_URL |
| 659 |
); |
| 660 |
wp_safe_redirect( $url ); |
| 661 |
exit(); |
| 662 |
} |
| 663 |
break; |
| 664 |
|
| 665 |
case 'member_auto_billing_info': |
| 666 |
case 'member_favorite_page': |
| 667 |
case 'autodelivery_history': |
| 668 |
case 'msa_setting': |
| 669 |
case 'mda_setting': |
| 670 |
break; |
| 671 |
default: |
| 672 |
} |
| 673 |
} |
| 674 |
} |
| 675 |
|
| 676 |
/** |
| 677 |
* Authenticate Membership. |
| 678 |
* usces_filter_template_redirect |
| 679 |
*/ |
| 680 |
public function member_auth() { |
| 681 |
global $usces; |
| 682 |
|
| 683 |
if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) { |
| 684 |
$usces_page = filter_input( INPUT_GET, 'usces_page', FILTER_DEFAULT ); |
| 685 |
if ( 'member_auth_error' === $usces_page ) { |
| 686 |
$this->member_verifying_error_form(); |
| 687 |
exit(); |
| 688 |
} |
| 689 |
if ( ! usces_is_login() ) { |
| 690 |
return false; |
| 691 |
} |
| 692 |
if ( 'member_edit' !== $usces_page && 'member_edit' !== $usces->page ) { |
| 693 |
return false; |
| 694 |
} |
| 695 |
|
| 696 |
add_filter( 'usces_filter_states_form_js', array( $this, 'states_form_js' ) ); |
| 697 |
|
| 698 |
$member = $usces->get_member(); |
| 699 |
if ( ! $this->member_auth_check( $member ) ) { |
| 700 |
$subpage = filter_input( INPUT_GET, 'usces_subpage', FILTER_DEFAULT ); |
| 701 |
$now = current_time( 'timestamp' ); |
| 702 |
$time = strtotime( '+15 minutes', $now ); |
| 703 |
$usces->set_member_meta_value( 'auth_url_creation_time', $time, $member['ID'] ); |
| 704 |
$auth_code = $this->generate_auth_code(); |
| 705 |
$usces->set_member_meta_value( 'member_edit_auth_code', $auth_code, $member['ID'] ); |
| 706 |
$member['regmode'] = 'updatememberform'; |
| 707 |
$member['auth_code'] = $auth_code; |
| 708 |
$this->send_verify_edit_email( $member, $time ); |
| 709 |
$this->member_edit_verifying_form(); |
| 710 |
exit(); |
| 711 |
} else { |
| 712 |
$usces->page = 'member_edit'; |
| 713 |
$this->member_edit_form( $member ); |
| 714 |
exit(); |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
return false; |
| 719 |
} |
| 720 |
|
| 721 |
/** |
| 722 |
* Authentication Code Generation. |
| 723 |
* |
| 724 |
* @return string |
| 725 |
*/ |
| 726 |
public function generate_auth_code() { |
| 727 |
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 728 |
$characterslength = strlen( $characters ); |
| 729 |
$auth_code = ''; |
| 730 |
for ( $i = 0; $i < 24; $i++ ) { |
| 731 |
$auth_code .= $characters[ wp_rand( 0, $characterslength - 1 ) ]; |
| 732 |
} |
| 733 |
return $auth_code; |
| 734 |
} |
| 735 |
|
| 736 |
/** |
| 737 |
* Disable hook. |
| 738 |
* usces_filter_states_form_js |
| 739 |
* |
| 740 |
* @param string $js Scripts. |
| 741 |
* @return string |
| 742 |
*/ |
| 743 |
public function states_form_js( $js ) { |
| 744 |
return ''; |
| 745 |
} |
| 746 |
|
| 747 |
/** |
| 748 |
* Send member verification email. |
| 749 |
* |
| 750 |
* @param array $member Member data. |
| 751 |
* @param int $time Remaining time in minutes. |
| 752 |
*/ |
| 753 |
public function send_verify_edit_email( $member, $time ) { |
| 754 |
global $usces; |
| 755 |
|
| 756 |
$name = usces_localized_name( trim( $member['name1'] ), trim( $member['name2'] ), 'return' ); |
| 757 |
$mailaddress1 = trim( $member['mailaddress1'] ); |
| 758 |
|
| 759 |
$subject = apply_filters( 'usces_filter_send_verifyeditmail_subject', __( 'Identity Verification Email', 'usces' ), $member ); |
| 760 |
$totime = date( __( 'Y-n-j G:i', 'usces' ), $time ); |
| 761 |
|
| 762 |
$message = sprintf( __( 'This email is a verification email for updating your membership information at "%s".', 'usces' ), html_entity_decode( get_option( 'blogname' ) ) ) . "\r\n"; |
| 763 |
$message .= __( 'By clicking on the URL below, your identity will be authenticated.', 'usces' ) . "\r\n"; |
| 764 |
$message .= __( 'After authentication, My Page will be displayed, so please click the menu again to proceed.', 'usces' ) . "\r\n"; |
| 765 |
$message .= sprintf( __( 'Please note that this URL is valid until %s.', 'usces' ), $totime ) . "\r\n\r\n"; |
| 766 |
$message .= $this->get_verify_edit_url( $member ) . "\r\n\r\n"; |
| 767 |
|
| 768 |
$message .= __( 'Please delete this email if you were not aware that you were going to receive it.', 'usces' ) . "\r\n\r\n"; |
| 769 |
$message .= html_entity_decode( get_option( 'blogname' ) ) . "\r\n"; |
| 770 |
if ( 1 === (int) $usces->options['put_customer_name'] ) { |
| 771 |
// translators: %s: name of user. |
| 772 |
$dear_name = sprintf( __( 'Dear %s', 'usces' ), $name ); |
| 773 |
$message = $dear_name . "\r\n\r\n" . $message; |
| 774 |
} |
| 775 |
$message = apply_filters( 'usces_filter_send_verifyeditmail_message', $message, $member ); |
| 776 |
|
| 777 |
$para1 = array( |
| 778 |
'to_name' => sprintf( _x( '%s', 'honorific', 'usces' ), $name ), |
| 779 |
'to_address' => $mailaddress1, |
| 780 |
'from_name' => get_option( 'blogname' ), |
| 781 |
'from_address' => $usces->options['sender_mail'], |
| 782 |
'reply_name' => get_option( 'blogname' ), |
| 783 |
'reply_to' => usces_get_first_order_mail(), |
| 784 |
'return_path' => $usces->options['sender_mail'], |
| 785 |
'subject' => $subject, |
| 786 |
'message' => do_shortcode( $message ), |
| 787 |
); |
| 788 |
$para1 = apply_filters( 'usces_filter_send_verifyeditmail_para1', $para1 ); |
| 789 |
usces_send_mail( $para1 ); |
| 790 |
} |
| 791 |
|
| 792 |
/** |
| 793 |
* URL for member verification. |
| 794 |
* |
| 795 |
* @param array $member Member data. |
| 796 |
* @return string |
| 797 |
*/ |
| 798 |
private function get_verify_edit_url( $member ) { |
| 799 |
global $usces; |
| 800 |
|
| 801 |
$encrypt_value = $this->encrypt_value( $member ); |
| 802 |
$query = array( |
| 803 |
'member_edit_auth_code' => $encrypt_value, |
| 804 |
); |
| 805 |
$query = apply_filters( 'usces_filter_verifyeditmail_query', $query, $member ); |
| 806 |
$url = add_query_arg( $query, USCES_MEMBER_URL ); |
| 807 |
|
| 808 |
return $url; |
| 809 |
} |
| 810 |
|
| 811 |
/** |
| 812 |
* Member Authentication Check. |
| 813 |
* |
| 814 |
* @param array $member Member data. |
| 815 |
* @return bool |
| 816 |
*/ |
| 817 |
public function member_auth_check( $member ) { |
| 818 |
if ( empty( $member['edit_auth'] ) ) { |
| 819 |
return false; |
| 820 |
} |
| 821 |
return true; |
| 822 |
} |
| 823 |
|
| 824 |
/** |
| 825 |
* Authentication mail transmission completion page. |
| 826 |
*/ |
| 827 |
public function member_edit_verifying_form() { |
| 828 |
get_header(); |
| 829 |
ob_start(); |
| 830 |
?> |
| 831 |
<div class="storycontent"> |
| 832 |
<div id="primary" class="site-content"> |
| 833 |
<main id="content" class="inner_block member-page" role="main"> |
| 834 |
<?php |
| 835 |
if ( have_posts() ) : |
| 836 |
usces_remove_filter(); |
| 837 |
?> |
| 838 |
<article class="post wc_member" id="wc_member"> |
| 839 |
<h1 class="member_page_title"><?php esc_html_e( 'Verifying', 'usces' ); ?></h1> |
| 840 |
|
| 841 |
<div id="memberpages"> |
| 842 |
<div class="whitebox"> |
| 843 |
<div id="memberedit"> |
| 844 |
|
| 845 |
<div class="header_explanation"> |
| 846 |
<?php echo apply_filters( 'usces_filter_memberverifying_page_header', '' ); ?> |
| 847 |
</div> |
| 848 |
|
| 849 |
<h2><?php esc_html_e( 'Authentication email sent.', 'usces' ); ?></h2> |
| 850 |
<p><?php esc_html_e( 'When updating important information, you will need to authenticate your identity by email.', 'usces' ); ?></p> |
| 851 |
<p><?php esc_html_e( 'You will receive an authentication email to your registered email address. Please click the URL in the body of the email to approve it.', 'usces' ); ?></p> |
| 852 |
<p><?php esc_html_e( 'The URL for authentication expires in 15 minutes from now.', 'usces' ); ?></p> |
| 853 |
<p><?php esc_html_e( 'If the expiration date has passed, please click the menu again to send the authentication email.', 'usces' ); ?></p> |
| 854 |
|
| 855 |
<div class="footer_explanation"> |
| 856 |
<?php echo apply_filters( 'usces_filter_memberverifying_page_footer', '' ); ?> |
| 857 |
</div> |
| 858 |
|
| 859 |
<div class="send"> |
| 860 |
<input type="button" name="back" class="top back" value="<?php esc_attr_e( 'Back', 'usces' ); ?>" onclick="location.href='<?php echo esc_url( USCES_MEMBER_URL ); ?>'" /> |
| 861 |
</div> |
| 862 |
|
| 863 |
</div><!-- #memberedit --> |
| 864 |
</div><!-- .whitebox --> |
| 865 |
</div><!-- #memberpages --> |
| 866 |
</article><!-- .post .wc_member #wc_member --> |
| 867 |
</main><!-- #content .inner_block .member-page --> |
| 868 |
</div><!-- #primary .site-content --> |
| 869 |
</div><!-- .storycontent --> |
| 870 |
<?php |
| 871 |
endif; |
| 872 |
$contents = ob_get_contents(); |
| 873 |
ob_end_clean(); |
| 874 |
$contents = apply_filters( 'usces_filter_member_edit_verifying_form', $contents ); |
| 875 |
echo $contents; // no escape. |
| 876 |
get_footer(); |
| 877 |
} |
| 878 |
|
| 879 |
/** |
| 880 |
* Authentication mail transmission completion page. |
| 881 |
*/ |
| 882 |
public function member_verifying_error_form() { |
| 883 |
$auth_error = filter_input( INPUT_GET, 'auth_error', FILTER_DEFAULT ); |
| 884 |
get_header(); |
| 885 |
ob_start(); |
| 886 |
?> |
| 887 |
<div class="storycontent"> |
| 888 |
<div id="primary" class="site-content"> |
| 889 |
<main id="content" class="inner_block member-page" role="main"> |
| 890 |
<?php |
| 891 |
if ( have_posts() ) : |
| 892 |
usces_remove_filter(); |
| 893 |
?> |
| 894 |
<article class="post wc_member" id="wc_member"> |
| 895 |
<h1 class="member_page_title"><?php esc_html_e( 'Verifying', 'usces' ); ?></h1> |
| 896 |
|
| 897 |
<div id="memberpages"> |
| 898 |
<div class="whitebox"> |
| 899 |
<div id="memberedit"> |
| 900 |
|
| 901 |
<div class="header_explanation"> |
| 902 |
<?php echo apply_filters( 'usces_filter_memberverifying_error_page_header', '' ); ?> |
| 903 |
</div> |
| 904 |
|
| 905 |
<h2><?php esc_html_e( 'Email Authentication Error', 'usces' ); ?></h2> |
| 906 |
<?php if ( 0 < $auth_error ) : ?> |
| 907 |
<p><?php esc_html_e( 'Authentication by email has failed.', 'usces' ); ?></p> |
| 908 |
<?php endif; ?> |
| 909 |
<p><?php esc_html_e( 'Authentication URL has expired or invalid access.', 'usces' ); ?></p> |
| 910 |
|
| 911 |
<div class="footer_explanation"> |
| 912 |
<?php echo apply_filters( 'usces_filter_memberverifying_error_page_footer', '' ); ?> |
| 913 |
</div> |
| 914 |
|
| 915 |
<div class="send"> |
| 916 |
<input type="button" name="back" class="top back" value="<?php esc_attr_e( 'Back to the member page.', 'usces' ); ?>" onclick="location.href='<?php echo esc_url( USCES_MEMBER_URL ); ?>'" /> |
| 917 |
</div> |
| 918 |
|
| 919 |
</div><!-- #memberedit --> |
| 920 |
</div><!-- .whitebox --> |
| 921 |
</div><!-- #memberpages --> |
| 922 |
</article><!-- .post .wc_member #wc_member --> |
| 923 |
</main><!-- #content .inner_block .member-page --> |
| 924 |
</div><!-- #primary .site-content --> |
| 925 |
</div><!-- .storycontent --> |
| 926 |
<?php |
| 927 |
endif; |
| 928 |
$contents = ob_get_contents(); |
| 929 |
ob_end_clean(); |
| 930 |
$contents = apply_filters( 'usces_filter_member_verifying_error_form', $contents, $auth_error ); |
| 931 |
echo $contents; // no escape. |
| 932 |
get_footer(); |
| 933 |
} |
| 934 |
|
| 935 |
/** |
| 936 |
* Member information editing page. |
| 937 |
* |
| 938 |
* @param array $member Member data. |
| 939 |
*/ |
| 940 |
public function member_edit_form( $member ) { |
| 941 |
global $usces; |
| 942 |
|
| 943 |
$update = ''; |
| 944 |
if ( empty( $usces->error_message ) && isset( $_POST['editmember'] ) ) { |
| 945 |
$update = 'update'; |
| 946 |
} |
| 947 |
|
| 948 |
get_header(); |
| 949 |
ob_start(); |
| 950 |
?> |
| 951 |
<div class="storycontent"> |
| 952 |
<div id="primary" class="site-content"> |
| 953 |
<main id="content" class="inner_block member-page" role="main"> |
| 954 |
<?php |
| 955 |
if ( have_posts() ) : |
| 956 |
usces_remove_filter(); |
| 957 |
?> |
| 958 |
<article class="post wc_member" id="wc_member"> |
| 959 |
<h1 class="member_page_title"><?php esc_html_e( 'Member information editing', 'usces' ); ?></h1> |
| 960 |
|
| 961 |
<div id="memberpages"> |
| 962 |
<div class="whitebox"> |
| 963 |
<div id="memberedit"> |
| 964 |
|
| 965 |
<div class="error_message"><?php usces_error_message(); ?></div> |
| 966 |
|
| 967 |
<form action="<?php echo esc_url( USCES_MEMBER_URL ); ?>#edit" method="post" onKeyDown="if (event.keyCode == 13) {return false;}"> |
| 968 |
<table class="customer_form"> |
| 969 |
|
| 970 |
<?php uesces_addressform( 'member', $member, 'echo' ); ?> |
| 971 |
|
| 972 |
<tr> |
| 973 |
<th scope="row"><?php esc_html_e( 'e-mail adress', 'usces' ); ?></th> |
| 974 |
<td colspan="2"><input name="member[mailaddress1]" id="mailaddress1" type="text" value="<?php echo esc_attr( $member['mailaddress1'] ); ?>" /></td> |
| 975 |
</tr> |
| 976 |
<tr> |
| 977 |
<th scope="row"><?php esc_html_e( 'E-mail address (for verification)', 'usces' ); ?></th> |
| 978 |
<td colspan="2"><input name="member[mailaddress2]" id="mailaddress2" type="text" autocomplete="off" /> |
| 979 |
<?php esc_html_e( 'Leave it blank in case of no change.', 'usces' ); ?></td> |
| 980 |
</tr> |
| 981 |
<tr> |
| 982 |
<th scope="row"><?php esc_html_e( 'password', 'usces' ); ?></th> |
| 983 |
<td colspan="2"> |
| 984 |
<input name="member[password1]" id="password1" type="password" readonly /> |
| 985 |
<?php esc_html_e( 'Leave it blank in case of no change.', 'usces' ); ?></td> |
| 986 |
</tr> |
| 987 |
<tr> |
| 988 |
<th scope="row"><?php esc_html_e( 'Password (confirm)', 'usces' ); ?></th> |
| 989 |
<td colspan="2"> |
| 990 |
<input name="member[password2]" id="password2" type="password" readonly /> |
| 991 |
<?php esc_html_e( 'Leave it blank in case of no change.', 'usces' ); ?></td> |
| 992 |
</tr> |
| 993 |
</table> |
| 994 |
|
| 995 |
<input name="member_regmode" type="hidden" value="updatememberform" /> |
| 996 |
<input name="member_id" type="hidden" value="<?php echo esc_attr( $member['ID'] ); ?>" /> |
| 997 |
<input id="update" type="hidden" value="<?php echo esc_attr( $update ); ?>" /> |
| 998 |
<div class="send"> |
| 999 |
<input type="button" name="top" class="top" value="<?php esc_attr_e( 'Back to the top page.', 'usces' ); ?>" onclick="location.href='<?php echo esc_url( home_url() ); ?>'" /> |
| 1000 |
<input type="button" name="back" class="top back" value="<?php esc_attr_e( 'Back to the member page.', 'usces' ); ?>" onclick="location.href='<?php echo esc_url( USCES_MEMBER_URL ); ?>'" /> |
| 1001 |
<input type="submit" name="editmember" class="editmember" value="<?php esc_html_e( 'update it', 'usces' ); ?>" /> |
| 1002 |
<input type="submit" name="deletemember" class="deletemember" value="<?php esc_html_e( 'delete it', 'usces' ); ?>" onclick="return confirm('<?php esc_attr_e( 'All information about the member is deleted. Are you all right?', 'usces' ); ?>');" /> |
| 1003 |
<?php $noncekey = 'post_member' . $usces->get_uscesid( false ); ?> |
| 1004 |
<?php wp_nonce_field( $noncekey, 'wc_nonce' ); ?> |
| 1005 |
</div><!-- .send --> |
| 1006 |
</form> |
| 1007 |
|
| 1008 |
</div><!-- #memberedit --> |
| 1009 |
</div><!-- .whitebox --> |
| 1010 |
</div><!-- #memberpages --> |
| 1011 |
</article><!-- .post .wc_member #wc_member --> |
| 1012 |
</main><!-- #content .inner_block .member-page --> |
| 1013 |
</div><!-- #primary .site-content --> |
| 1014 |
</div><!-- .storycontent --> |
| 1015 |
<?php |
| 1016 |
endif; |
| 1017 |
$contents = ob_get_contents(); |
| 1018 |
ob_end_clean(); |
| 1019 |
$contents = apply_filters( 'usces_filter_member_edit_form', $contents, $member, $update ); |
| 1020 |
echo $contents; // no escape. |
| 1021 |
get_footer(); |
| 1022 |
} |
| 1023 |
|
| 1024 |
/** |
| 1025 |
* Verify membership with an authentication code. |
| 1026 |
* |
| 1027 |
* @param string $auth_code Authentication Code. |
| 1028 |
*/ |
| 1029 |
private function get_member_id_by_auth_code( $auth_code ) { |
| 1030 |
global $wpdb; |
| 1031 |
|
| 1032 |
$member_meta_table = usces_get_tablename( 'usces_member_meta' ); |
| 1033 |
$member_id = $wpdb->get_var( $wpdb->prepare( "SELECT `member_id` FROM {$member_meta_table} WHERE `meta_key` = %s AND `meta_value` = %s", 'member_edit_auth_code', $auth_code ) ); |
| 1034 |
return $member_id; |
| 1035 |
} |
| 1036 |
|
| 1037 |
/** |
| 1038 |
* Verify Membership. |
| 1039 |
* usces_main |
| 1040 |
*/ |
| 1041 |
public function verified_member() { |
| 1042 |
global $usces; |
| 1043 |
|
| 1044 |
if ( ! $usces->is_member_page( $_SERVER['REQUEST_URI'] ) || ! isset( $_GET['member_edit_auth_code'] ) ) { |
| 1045 |
return; |
| 1046 |
} |
| 1047 |
|
| 1048 |
$value = wp_unslash( $_GET['member_edit_auth_code'] ); |
| 1049 |
$auth_code = $this->decrypt_value( $value ); |
| 1050 |
$member_id = $this->get_member_id_by_auth_code( $auth_code ); |
| 1051 |
|
| 1052 |
if ( empty( $member_id ) && usces_is_login() ) { |
| 1053 |
$member = $usces->get_member(); |
| 1054 |
if ( isset( $member['edit_auth'] ) ) { |
| 1055 |
$loggedin_member_id = $this->get_member_id_by_auth_code( $member['edit_auth'] ); |
| 1056 |
if ( (int) $member['ID'] === (int) $loggedin_member_id ) { |
| 1057 |
wp_safe_redirect( |
| 1058 |
add_query_arg( |
| 1059 |
array( |
| 1060 |
'usces_page' => 'member_auth_error', |
| 1061 |
'auth_error' => '0', |
| 1062 |
), |
| 1063 |
USCES_MEMBER_URL |
| 1064 |
) |
| 1065 |
); |
| 1066 |
exit(); |
| 1067 |
} |
| 1068 |
} |
| 1069 |
} |
| 1070 |
|
| 1071 |
$member_info = $usces->get_member_info( $member_id ); |
| 1072 |
$time = $usces->get_member_meta_value( 'auth_url_creation_time', $member_id ); |
| 1073 |
$now = current_time( 'timestamp' ); |
| 1074 |
if ( empty( $member_info ) || empty( $time ) || $time < $now ) { |
| 1075 |
wp_safe_redirect( |
| 1076 |
add_query_arg( |
| 1077 |
array( |
| 1078 |
'usces_page' => 'member_auth_error', |
| 1079 |
'auth_error' => '1', |
| 1080 |
), |
| 1081 |
USCES_MEMBER_URL |
| 1082 |
) |
| 1083 |
); |
| 1084 |
exit(); |
| 1085 |
} |
| 1086 |
|
| 1087 |
if ( usces_is_login() ) { |
| 1088 |
$member = $usces->get_member(); |
| 1089 |
if ( (int) $member['ID'] !== (int) $member_id ) { |
| 1090 |
wp_safe_redirect( |
| 1091 |
add_query_arg( |
| 1092 |
array( |
| 1093 |
'usces_page' => 'member_auth_error', |
| 1094 |
'auth_error' => '2', |
| 1095 |
), |
| 1096 |
USCES_MEMBER_URL |
| 1097 |
) |
| 1098 |
); |
| 1099 |
exit(); |
| 1100 |
} |
| 1101 |
|
| 1102 |
if ( isset( $_SESSION['usces_member']['edit_auth'] ) ) { |
| 1103 |
if ( $_SESSION['usces_member']['edit_auth'] !== $auth_code ) { |
| 1104 |
wp_safe_redirect( |
| 1105 |
add_query_arg( |
| 1106 |
array( |
| 1107 |
'usces_page' => 'member_auth_error', |
| 1108 |
'auth_error' => '3', |
| 1109 |
), |
| 1110 |
USCES_MEMBER_URL |
| 1111 |
) |
| 1112 |
); |
| 1113 |
exit(); |
| 1114 |
} |
| 1115 |
} |
| 1116 |
|
| 1117 |
$_SESSION['usces_member']['edit_auth'] = $auth_code; |
| 1118 |
|
| 1119 |
$usces->page = 'member'; |
| 1120 |
add_action( 'the_post', array( $usces, 'action_memberFilter' ) ); |
| 1121 |
add_action( 'template_redirect', array( $usces, 'template_redirect' ) ); |
| 1122 |
|
| 1123 |
} else { |
| 1124 |
$usces->page = 'login'; |
| 1125 |
add_action( 'the_post', array( $usces, 'action_memberFilter' ) ); |
| 1126 |
add_action( 'template_redirect', array( $usces, 'template_redirect' ) ); |
| 1127 |
} |
| 1128 |
} |
| 1129 |
|
| 1130 |
/** |
| 1131 |
* Member Login. |
| 1132 |
* usces_filter_login_inform |
| 1133 |
* |
| 1134 |
* @param string $form HTML Form. |
| 1135 |
* @return string |
| 1136 |
*/ |
| 1137 |
public function login_inform( $form ) { |
| 1138 |
global $usces; |
| 1139 |
|
| 1140 |
if ( isset( $_SERVER['QUERY_STRING'] ) ) { |
| 1141 |
parse_str( $_SERVER['QUERY_STRING'], $query ); |
| 1142 |
if ( isset( $query['member_edit_auth_code'] ) ) { |
| 1143 |
$auth_code = $this->decrypt_value( $query['member_edit_auth_code'] ); |
| 1144 |
$form .= '<input type="hidden" name="memeditauth" value="' . esc_attr( $auth_code ) . '">'; |
| 1145 |
} elseif ( isset( $_POST['memeditauth'] ) ) { |
| 1146 |
$form .= '<input type="hidden" name="memeditauth" value="' . esc_attr( $_POST['memeditauth'] ) . '">'; |
| 1147 |
} |
| 1148 |
} elseif ( isset( $_POST['memeditauth'] ) ) { |
| 1149 |
$form .= '<input type="hidden" name="memeditauth" value="' . esc_attr( $_POST['memeditauth'] ) . '">'; |
| 1150 |
} |
| 1151 |
return $form; |
| 1152 |
} |
| 1153 |
|
| 1154 |
/** |
| 1155 |
* Member Login. |
| 1156 |
* usces_action_login_page_inform |
| 1157 |
*/ |
| 1158 |
public function login_page_inform() { |
| 1159 |
global $usces; |
| 1160 |
|
| 1161 |
if ( isset( $_SERVER['QUERY_STRING'] ) ) { |
| 1162 |
parse_str( $_SERVER['QUERY_STRING'], $query ); |
| 1163 |
if ( isset( $query['member_edit_auth_code'] ) ) { |
| 1164 |
$auth_code = $this->decrypt_value( $query['member_edit_auth_code'] ); |
| 1165 |
echo '<input type="hidden" name="memeditauth" value="' . esc_attr( $auth_code ) . '">'; |
| 1166 |
} elseif ( isset( $_POST['memeditauth'] ) ) { |
| 1167 |
echo '<input type="hidden" name="memeditauth" value="' . esc_attr( $_POST['memeditauth'] ) . '">'; |
| 1168 |
} |
| 1169 |
} elseif ( isset( $_POST['memeditauth'] ) ) { |
| 1170 |
echo '<input type="hidden" name="memeditauth" value="' . esc_attr( $_POST['memeditauth'] ) . '">'; |
| 1171 |
} |
| 1172 |
} |
| 1173 |
|
| 1174 |
/** |
| 1175 |
* Submenu area of the member page. |
| 1176 |
* usces_filter_member_submenu_list |
| 1177 |
* |
| 1178 |
* @param string $submenu_list Submenu area. |
| 1179 |
* @param array $member Member information. |
| 1180 |
* @return string |
| 1181 |
*/ |
| 1182 |
public function member_submenu_list( $submenu_list, $member ) { |
| 1183 |
if ( empty( $submenu_list ) ) { |
| 1184 |
$submenu_list = '<li class="member-edit"><a href="#edit">' . esc_html__( 'To member information editing', 'usces' ) . '</a></li>'; |
| 1185 |
} |
| 1186 |
return $submenu_list; |
| 1187 |
} |
| 1188 |
|
| 1189 |
/** |
| 1190 |
* Processing after login. |
| 1191 |
* usces_action_member_logined |
| 1192 |
*/ |
| 1193 |
public function after_login() { |
| 1194 |
global $usces; |
| 1195 |
|
| 1196 |
if ( isset( $_POST['memeditauth'] ) ) { |
| 1197 |
$auth_code = filter_input( INPUT_POST, 'memeditauth', FILTER_DEFAULT ); |
| 1198 |
$member_id = $this->get_member_id_by_auth_code( $auth_code ); |
| 1199 |
if ( (int) $member_id === (int) $_SESSION['usces_member']['ID'] ) { |
| 1200 |
$_SESSION['usces_member']['edit_auth'] = $auth_code; |
| 1201 |
} |
| 1202 |
} |
| 1203 |
} |
| 1204 |
|
| 1205 |
/** |
| 1206 |
* Send login notification email. |
| 1207 |
* usces_action_after_login |
| 1208 |
*/ |
| 1209 |
public function login_notify() { |
| 1210 |
global $usces; |
| 1211 |
|
| 1212 |
$member = $usces->get_member(); |
| 1213 |
$name = usces_localized_name( trim( $member['name1'] ), trim( $member['name2'] ), 'return' ); |
| 1214 |
$mailaddress1 = trim( $member['mailaddress1'] ); |
| 1215 |
|
| 1216 |
// translators: %s: name of shop. |
| 1217 |
$subject = apply_filters( 'usces_filter_send_loginnotifymail_subject', sprintf( __( '%s : Login Notification', 'usces' ), get_option( 'blogname' ) ), $member ); |
| 1218 |
|
| 1219 |
$message = __( 'There has been a login on your account. Please review the following information and if you are not familiar with it, please change your password for your own safety.', 'usces' ) . "\r\n\r\n"; |
| 1220 |
$message .= '--------------------------------' . "\r\n"; |
| 1221 |
$message .= __( 'Login date and time', 'usces' ) . ' : ' . wp_date( 'Y-m-d H:i:s' ) . "\r\n"; |
| 1222 |
$message .= __( 'Member ID', 'usces' ) . ' : ' . $member['ID'] . "\r\n"; |
| 1223 |
$message .= __( 'Full name', 'usces' ) . ' : ' . sprintf( __( 'Dear %s', 'usces' ), $name ) . "\r\n"; |
| 1224 |
$message .= '--------------------------------' . "\r\n\r\n"; |
| 1225 |
|
| 1226 |
$message .= html_entity_decode( get_option( 'blogname' ) ) . "\r\n"; |
| 1227 |
if ( 1 === (int) $usces->options['put_customer_name'] ) { |
| 1228 |
// translators: %s: name of user. |
| 1229 |
$dear_name = sprintf( __( 'Dear %s', 'usces' ), $name ); |
| 1230 |
$message = $dear_name . "\r\n\r\n" . $message; |
| 1231 |
} |
| 1232 |
$message = apply_filters( 'usces_filter_send_loginnotifymail_message', $message, $member ); |
| 1233 |
|
| 1234 |
$para1 = array( |
| 1235 |
'to_name' => sprintf( _x( '%s', 'honorific', 'usces' ), $name ), |
| 1236 |
'to_address' => $mailaddress1, |
| 1237 |
'from_name' => get_option( 'blogname' ), |
| 1238 |
'from_address' => $usces->options['sender_mail'], |
| 1239 |
'reply_name' => get_option( 'blogname' ), |
| 1240 |
'reply_to' => usces_get_first_order_mail(), |
| 1241 |
'return_path' => $usces->options['error_mail'], |
| 1242 |
'subject' => $subject, |
| 1243 |
'message' => do_shortcode( $message ), |
| 1244 |
); |
| 1245 |
$para1 = apply_filters( 'usces_filter_send_loginnotifymail_para1', $para1 ); |
| 1246 |
usces_send_mail( $para1 ); |
| 1247 |
} |
| 1248 |
} |
| 1249 |
|