Files
wordpress-theme-aksrt/inc/helpers/user-center-renderers/settings-account.php
T

145 lines
12 KiB
PHP

<?php
/**
* User center account settings rows and runtime modal templates.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$account_user = isset($target_user) && $target_user instanceof WP_User
? $target_user
: wp_get_current_user();
$account_user_id = $account_user instanceof WP_User ? (int) $account_user->ID : (int) ($user_id ?? 0);
$account_email = $account_user instanceof WP_User ? (string) $account_user->user_email : '';
$account_phone = $account_user_id > 0 ? (string) get_user_meta($account_user_id, 'aksrt_phone', true) : '';
$user_settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_all() : [];
$sms_settings = class_exists('\\AKSRT\\Sms\\SMS') ? \AKSRT\Sms\SMS::get_instance()->get_provider_config() : [];
$phone_available = !empty($user_settings['bind_phone']) && (($sms_settings['sms_sdk'] ?? 'null') !== 'null');
$phone_visible = $account_phone !== '' || $phone_available;
$phone_label = $account_phone !== '' ? $account_phone : __('暂未绑定', 'aksrt');
$email_action = $account_email !== '' ? __('修改', 'aksrt') : __('绑定', 'aksrt');
$phone_action = $account_phone !== '' ? __('修改', 'aksrt') : __('绑定', 'aksrt');
$render_row = static function (string $icon, string $title, string $value, string $action, string $modal, string $icon_tone, string $action_tone, bool $interactive = true): void {
?>
<div class="aksrt-account-row<?php echo $value === '' ? ' aksrt-account-row--simple' : ''; ?>">
<div class="aksrt-account-row__identity">
<span class="aksrt-account-row__icon aksrt-account-row__icon--<?php echo esc_attr($icon_tone); ?>"><i class="fa fas <?php echo esc_attr($icon); ?>" aria-hidden="true"></i></span>
<strong class="aksrt-account-row__copy"><?php echo esc_html($title); ?></strong>
</div>
<?php if ($value !== '') : ?>
<div class="aksrt-account-row__value" title="<?php echo esc_attr($value); ?>"><?php echo esc_html($value); ?></div>
<?php endif; ?>
<?php if ($interactive) : ?>
<button type="button" class="but hollow <?php echo esc_attr($action_tone); ?> aksrt-account-row__action" data-aksrt-settings-modal="<?php echo esc_attr($modal); ?>">
<?php echo esc_html($action); ?>
</button>
<?php else : ?>
<span class="aksrt-account-row__action aksrt-account-row__action--unavailable"><?php esc_html_e('暂不可修改', 'aksrt'); ?></span>
<?php endif; ?>
</div>
<?php
};
?>
<section class="aksrt-account-settings" data-aksrt-settings-root data-aksrt-captcha-scope>
<div class="aksrt-account-settings__section">
<div class="aksrt-account-settings__heading">
<div>
<h3 class="title-h-left"><b><?php esc_html_e('绑定邮箱', 'aksrt'); ?></b></h3>
<p><?php esc_html_e('绑定邮箱账号,及时接收订单、审核等重要信息', 'aksrt'); ?></p>
</div>
</div>
<div class="aksrt-account-list">
<?php $render_row('fa-envelope', __('邮箱', 'aksrt'), $account_email !== '' ? $account_email : __('暂未绑定', 'aksrt'), $email_action, 'email', 'blue', $account_email !== '' ? 'c-yellow-2' : 'c-blue'); ?>
</div>
</div>
<?php if ($phone_visible) : ?>
<div class="aksrt-account-settings__section">
<div class="aksrt-account-settings__heading">
<div>
<h3 class="title-h-left"><b><?php esc_html_e('绑定手机', 'aksrt'); ?></b></h3>
<p><?php esc_html_e('绑定手机号,提高账户安全性', 'aksrt'); ?></p>
</div>
</div>
<div class="aksrt-account-list">
<?php $render_row('fa-phone', __('手机号', 'aksrt'), $phone_label, $phone_action, 'phone', 'blue-2', $account_phone !== '' ? 'c-yellow' : 'c-blue', $phone_available); ?>
</div>
</div>
<?php endif; ?>
<?php require __DIR__ . '/settings-bindings.php'; ?>
<div class="aksrt-account-settings__section">
<div class="aksrt-account-settings__heading">
<div>
<h3 class="title-h-left"><b><?php esc_html_e('账户密码', 'aksrt'); ?></b></h3>
<p><?php esc_html_e('定期修改密码有助于账户安全', 'aksrt'); ?></p>
</div>
</div>
<div class="aksrt-account-list">
<?php $render_row('fa-unlock-alt', __('账户密码', 'aksrt'), '', __('修改密码', 'aksrt'), 'password', 'purple', 'c-blue-2'); ?>
</div>
</div>
<template data-aksrt-settings-modal-template="password">
<div class="aksrt-settings-modal">
<div class="modal-colorful-header colorful-bg jb-yellow">
<button type="button" class="close" data-aksrt-modal-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
<div class="colorful-make"></div>
<div class="text-center"><div class="em2x"><i class="fa fas fa-unlock-alt" aria-hidden="true"></i></div><div class="mt10 em12 padding-w10"><?php esc_html_e('修改密码', 'aksrt'); ?></div></div>
</div>
<form id="pwd-form" autocomplete="off" novalidate>
<div class="aksrt-settings-modal__fields">
<div class="modal-field"><label for="pwd-old"><?php esc_html_e('原密码', 'aksrt'); ?></label><input type="password" id="pwd-old" name="old_password" required minlength="1"><button type="button" class="toggle-pwd" data-target="pwd-old" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>"><i class="fa fa-eye" aria-hidden="true"></i></button></div>
<div class="modal-field"><label for="pwd-new"><?php esc_html_e('新密码', 'aksrt'); ?></label><input type="password" id="pwd-new" name="new_password" required minlength="6" placeholder="<?php esc_attr_e('至少6位字符', 'aksrt'); ?>"><button type="button" class="toggle-pwd" data-target="pwd-new" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>"><i class="fa fa-eye" aria-hidden="true"></i></button><div class="pwd-strength" id="pwd-strength-bar"><div class="pwd-strength__fill"></div></div><span class="pwd-strength__text" id="pwd-strength-text"></span></div>
<div class="modal-field"><label for="pwd-new-confirm"><?php esc_html_e('确认新密码', 'aksrt'); ?></label><input type="password" id="pwd-new-confirm" name="new_password_confirm" required minlength="6" placeholder="<?php esc_attr_e('再次输入新密码', 'aksrt'); ?>"><button type="button" class="toggle-pwd" data-target="pwd-new-confirm" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>"><i class="fa fa-eye" aria-hidden="true"></i></button></div>
<div class="modal-field modal-field--code"><label for="pwd-code"><?php esc_html_e('当前邮箱验证码', 'aksrt'); ?></label><div class="code-input-group"><input type="text" id="pwd-code" name="email_code" maxlength="6" inputmode="numeric" pattern="[0-9]*" placeholder="<?php esc_attr_e('6位数字验证码', 'aksrt'); ?>" required><button type="button" class="but hollow code-send-btn" id="pwd-send-code"><?php esc_html_e('发送到当前邮箱', 'aksrt'); ?></button></div></div>
<?php aksrt_render_captcha('change_password'); ?>
</div>
<div class="aksrt-settings-modal__footer"><button type="submit" class="but jb-blue padding-lg btn-block" id="pwd-submit"><?php esc_html_e('确认修改', 'aksrt'); ?></button></div>
</form>
</div>
</template>
<template data-aksrt-settings-modal-template="email">
<div class="aksrt-settings-modal">
<div class="modal-colorful-header colorful-bg jb-blue">
<button type="button" class="close" data-aksrt-modal-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
<div class="colorful-make"></div>
<div class="text-center"><div class="em2x"><i class="fa fas fa-envelope" aria-hidden="true"></i></div><div class="mt10 em12 padding-w10"><?php echo esc_html($account_email !== '' ? __('更改邮箱', 'aksrt') : __('绑定邮箱', 'aksrt')); ?></div></div>
</div>
<form id="email-form" autocomplete="off" novalidate>
<div class="aksrt-settings-modal__fields">
<?php if ($account_email !== '') : ?><div class="modal-field"><label><?php esc_html_e('当前邮箱', 'aksrt'); ?></label><div class="readonly-display"><?php echo esc_html($account_email); ?></div></div><?php endif; ?>
<div class="modal-field"><label for="email-current-password"><?php esc_html_e('当前密码', 'aksrt'); ?></label><input type="password" id="email-current-password" name="current_password" required minlength="1" placeholder="<?php esc_attr_e('请输入当前登录密码', 'aksrt'); ?>"><button type="button" class="toggle-pwd" data-target="email-current-password" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>"><i class="fa fa-eye" aria-hidden="true"></i></button></div>
<div class="modal-field"><label for="email-new"><?php esc_html_e('新邮箱', 'aksrt'); ?></label><input type="email" id="email-new" name="new_email" required placeholder="<?php esc_attr_e('请输入新的邮箱地址', 'aksrt'); ?>"></div>
<div class="modal-field modal-field--code"><label for="email-code"><?php esc_html_e('新邮箱验证码', 'aksrt'); ?></label><div class="code-input-group"><input type="text" id="email-code" name="email_code" maxlength="6" inputmode="numeric" pattern="[0-9]*" placeholder="<?php esc_attr_e('6位数字验证码', 'aksrt'); ?>" required><button type="button" class="but hollow code-send-btn" id="email-send-code"><?php esc_html_e('发送到新邮箱', 'aksrt'); ?></button></div><p class="settings-hint settings-hint--bottom"><?php esc_html_e('验证码将发送到你填写的新邮箱,验证通过后才会正式切换。', 'aksrt'); ?></p></div>
<?php aksrt_render_captcha('change_email'); ?>
</div>
<div class="aksrt-settings-modal__footer"><button type="submit" class="but jb-blue padding-lg btn-block" id="email-submit"><?php echo esc_html($account_email !== '' ? __('确认更改', 'aksrt') : __('确认绑定', 'aksrt')); ?></button></div>
</form>
</div>
</template>
<?php if ($phone_available) : ?>
<template data-aksrt-settings-modal-template="phone">
<div class="aksrt-settings-modal">
<div class="modal-colorful-header colorful-bg jb-blue">
<button type="button" class="close" data-aksrt-modal-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
<div class="colorful-make"></div>
<div class="text-center"><div class="em2x"><i class="fa fas fa-mobile-alt" aria-hidden="true"></i></div><div class="mt10 em12 padding-w10"><?php echo esc_html($account_phone !== '' ? __('修改手机', 'aksrt') : __('绑定手机', 'aksrt')); ?></div></div>
</div>
<form id="aksrt-bind-phone-form" autocomplete="off" novalidate data-aksrt-bind-phone-form>
<div class="aksrt-settings-modal__fields">
<div class="modal-field"><label for="bind-phone-input"><?php esc_html_e('手机号', 'aksrt'); ?></label><input type="tel" id="bind-phone-input" name="phone" data-aksrt-phone-input inputmode="tel" autocomplete="tel" required placeholder="<?php esc_attr_e('请输入手机号', 'aksrt'); ?>"></div>
<div class="modal-field modal-field--code"><label for="bind-phone-code"><?php esc_html_e('短信验证码', 'aksrt'); ?></label><div class="code-input-group"><input type="text" id="bind-phone-code" name="code" maxlength="6" inputmode="numeric" autocomplete="one-time-code" required placeholder="<?php esc_attr_e('请输入验证码', 'aksrt'); ?>"><button type="button" class="but hollow code-send-btn" data-aksrt-sms-trigger data-aksrt-sms-scene="bind_phone" data-aksrt-sms-phone="#bind-phone-input"><?php esc_html_e('获取验证码', 'aksrt'); ?></button></div></div>
<?php if (function_exists('aksrt_render_captcha')) : ?><?php aksrt_render_captcha('bind_phone'); ?><?php endif; ?>
</div>
<div class="aksrt-settings-modal__footer"><button type="submit" class="but jb-blue padding-lg btn-block"><?php echo esc_html($account_phone !== '' ? __('确认修改', 'aksrt') : __('确认绑定', 'aksrt')); ?></button></div>
</form>
</div>
</template>
<?php endif; ?>
</section>