feat(rewards): add toast and captcha flow

This commit is contained in:
kate522 committed 2026-10-05 03:51:18 +08:00
1 parent 356f7fe5bd
commit 979639342a
6 files changed
+192 -32

No files matched your search

+18 -2
View File
@@ -82,10 +82,16 @@ if (!function_exists('aksrt_render_rewards_template_for_user')) {
<?php endforeach; ?>
</div>
<?php if (!empty($settings['rewards_custom'])) : ?>
<label class="aksrt-reward__custom"><span><?php esc_html_e('自定义金额', 'aksrt'); ?></span><input class="aksrt-reward__input" type="number" min="<?php echo esc_attr((string) ($settings['rewards_min'] ?? 1)); ?>" max="<?php echo esc_attr((string) ($settings['rewards_max'] ?? 1000)); ?>" step="0.01" data-aksrt-reward-custom placeholder="<?php esc_attr_e('输入金额', 'aksrt'); ?>"></label>
<label class="aksrt-reward__custom">
<span class="aksrt-reward__custom-label"><?php esc_html_e('自定义金额', 'aksrt'); ?></span>
<span class="aksrt-reward__input-wrap"><span class="aksrt-reward__input-currency" aria-hidden="true">¥</span><input class="aksrt-reward__input" type="number" inputmode="decimal" autocomplete="off" min="<?php echo esc_attr((string) ($settings['rewards_min'] ?? 1)); ?>" max="<?php echo esc_attr((string) ($settings['rewards_max'] ?? 1000)); ?>" step="0.01" data-aksrt-reward-custom placeholder="<?php esc_attr_e('输入金额', 'aksrt'); ?>"></span>
</label>
<?php endif; ?>
<?php if (function_exists('aksrt_is_captcha_enabled_for') && aksrt_is_captcha_enabled_for('tip_user') && function_exists('aksrt_render_captcha')) : ?>
<div class="aksrt-reward__captcha"><?php aksrt_render_captcha('tip_user'); ?></div>
<?php endif; ?>
<button type="button" class="but jb-blue btn-block aksrt-reward__submit" data-aksrt-reward-submit><?php esc_html_e('余额赞赏', 'aksrt'); ?></button>
<div class="aksrt-reward__message" data-aksrt-reward-message role="status" aria-live="polite"></div>
<div class="aksrt-reward__message" data-aksrt-reward-message role="status" aria-live="polite" aria-atomic="true"></div>
</div>
</template>
<?php
@@ -152,6 +158,16 @@ add_action('wp_ajax_aksrt_submit_tip', function (): void {
if ($recent_operation !== '' && !hash_equals($recent_operation, $operation_key)) {
wp_send_json_error(['message' => __('操作太频繁,请稍后再试', 'aksrt')], 429);
}
$captcha_result = aksrt_require_captcha('tip_user', wp_unslash($_POST));
if ($captcha_result !== true) {
$captcha_error = is_wp_error($captcha_result) ? $captcha_result : null;
$captcha_data = $captcha_error ? $captcha_error->get_error_data() : null;
$captcha_status = is_array($captcha_data) ? (int) ($captcha_data['status'] ?? 400) : 400;
wp_send_json_error([
'code' => $captcha_error ? ($captcha_error->get_error_code() ?: 'aksrt_captcha_failed') : 'aksrt_captcha_failed',
'message' => $captcha_error ? ($captcha_error->get_error_message() ?: __('人机验证失败,请重试', 'aksrt')) : __('人机验证失败,请重试', 'aksrt'),
], $captcha_status > 0 ? $captcha_status : 400);
}
set_transient($rate_key, $operation_key, 3);
$result = \AKSRT\Ledger\LedgerService::get_instance()->transfer(
+1
View File
@@ -374,6 +374,7 @@ function aksrt_captcha_scenes(): array {
'download' => __('资源下载', 'aksrt'),
'signin' => __('每日签到', 'aksrt'),
'front_submit' => __('前台投稿', 'aksrt'),
'tip_user' => __('打赏用户', 'aksrt'),
];
}