feat: unify invite flow with referral ref

This commit is contained in:
kate522 committed 2026-08-17 13:49:59 +08:00
1 parent f1d6809109
commit b501cf4611
47 files changed
+1083 -2548

No files matched your search

+19 -17
View File
@@ -102,6 +102,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['user_login'], $_POST[
if (class_exists('\AKSRT\Auth\Service')) {
$result = \AKSRT\Auth\Service::register_user($_POST, ['oauth_bind_data' => null, 'obk' => '']);
if (!empty($result['success'])) {
$ref_notice = trim((string) ($result['notice'] ?? ''));
if (!empty($result['verification_required'])) {
$register_success = sprintf(
'%s <a href="%s">%s</a>',
@@ -115,19 +116,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['user_login'], $_POST[
esc_url(aksrt_get_login_url())
);
}
if ($ref_notice !== '') {
$register_success .= ' ' . esc_html($ref_notice);
}
} else {
$register_error = $result['error'] ?? __('注册失败', 'aksrt');
}
}
}
$invite_prefill = '';
if (!empty($_GET['ref'])) {
$invite_prefill = sanitize_key(wp_unslash($_GET['ref']));
} elseif (!empty($_GET['invite'])) {
$invite_prefill = sanitize_key(wp_unslash($_GET['invite']));
} elseif (!empty($_COOKIE['aksrt_invite'])) {
$invite_prefill = sanitize_key(wp_unslash($_COOKIE['aksrt_invite']));
$ref_prefill = '';
if (!empty($_COOKIE['aksrt_referral'])) {
$ref_prefill = sanitize_key(wp_unslash($_COOKIE['aksrt_referral']));
} elseif (!empty($_GET['ref'])) {
$ref_prefill = sanitize_key(wp_unslash($_GET['ref']));
}
$agreement = function_exists('aksrt_get_auth_agreement_view')
@@ -246,18 +248,18 @@ $sign_css_ver = file_exists(get_template_directory() . '/assets/css/routes/sign.
</div>
</div>
<?php
$invite_cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_invite_registration_config() : null;
if ($invite_cfg && ($invite_cfg['register_field'] ?? 'hidden') !== 'hidden') {
$mode = (string) $invite_cfg['register_field'];
$invit_hint = $mode === 'required'
? (string) ($invite_cfg['must_desc'] ?? '')
: (string) ($invite_cfg['open_desc'] ?? '');
$ref_cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_referral_registration_settings() : null;
if ($ref_cfg && !empty($ref_cfg['enabled']) && ($ref_cfg['register_field'] ?? 'hidden') !== 'hidden') {
$mode = (string) $ref_cfg['register_field'];
$ref_hint = $mode === 'required'
? (string) ($ref_cfg['required_desc'] ?? '')
: (string) ($ref_cfg['open_desc'] ?? '');
?>
<div class="form-field">
<label for="sign-invite"><?php esc_html_e('邀请码', 'aksrt'); ?><?php echo $mode === 'optional' ? ' <small style="color:var(--muted-color);">(' . esc_html__('选填', 'aksrt') . ')</small>' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></label>
<div class="input-wrap"><input type="text" name="invite_code" id="sign-invite" maxlength="32" autocomplete="off" value="<?php echo esc_attr($invite_prefill); ?>" <?php echo $mode === 'required' ? 'required' : ''; ?>></div>
<?php if ($invit_hint !== '') : ?>
<p class="sign-hint"><?php echo wp_kses_post($invit_hint); ?></p>
<label for="sign-ref"><?php esc_html_e('推广码', 'aksrt'); ?><?php echo $mode === 'optional' ? ' <small style="color:var(--muted-color);">(' . esc_html__('选填', 'aksrt') . ')</small>' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></label>
<div class="input-wrap"><input type="text" name="ref" id="sign-ref" maxlength="12" autocomplete="off" value="<?php echo esc_attr($ref_prefill); ?>" <?php echo $mode === 'required' ? 'required' : ''; ?>></div>
<?php if ($ref_hint !== '') : ?>
<p class="sign-hint"><?php echo wp_kses_post($ref_hint); ?></p>
<?php endif; ?>
</div>
<?php } ?>