refactor: rename the theme brand and every identifier from AKSRT to Jio
Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.
Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)
Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
(dropped 3 stale entries, added the 17 missing ones)
Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
when it is empty
Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.
Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5b16bc6e15
commit
35bb96e82f
997 files changed
+28216
-28188
No files matched your search
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* CaiHong aggregate OAuth client.
|
||||
*
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -30,7 +30,7 @@ final class CLoginClient {
|
||||
public function login(string $type, string $state): array {
|
||||
$type = sanitize_key($type);
|
||||
if (!in_array($type, ['qq', 'weixin', 'weibo'], true) || $state === '') {
|
||||
return ['code' => 1, 'msg' => __('聚合登录参数无效', 'aksrt')];
|
||||
return ['code' => 1, 'msg' => __('聚合登录参数无效', 'jio')];
|
||||
}
|
||||
return $this->request([
|
||||
'act' => 'login',
|
||||
@@ -75,28 +75,28 @@ final class CLoginClient {
|
||||
|
||||
private function request(array $params, bool $expect_url = false): array {
|
||||
if ($this->apiurl === '' || $this->appid === '' || $this->appkey === '') {
|
||||
return ['code' => 1, 'msg' => __('聚合登录配置无效', 'aksrt')];
|
||||
return ['code' => 1, 'msg' => __('聚合登录配置无效', 'jio')];
|
||||
}
|
||||
$url = $this->apiurl . '?' . http_build_query($params);
|
||||
$response = wp_safe_remote_get($url, [
|
||||
'timeout' => 15,
|
||||
'redirects' => 1,
|
||||
'limit_response_size' => 256 * 1024,
|
||||
'headers' => ['User-Agent' => 'AKSRT-CLogin/2.0'],
|
||||
'headers' => ['User-Agent' => 'Jio-CLogin/2.0'],
|
||||
]);
|
||||
if (is_wp_error($response)) {
|
||||
return ['code' => 1, 'msg' => $response->get_error_message()];
|
||||
}
|
||||
$status = (int) wp_remote_retrieve_response_code($response);
|
||||
if ($status < 200 || $status >= 300) {
|
||||
return ['code' => 1, 'msg' => __('聚合登录接口请求失败', 'aksrt')];
|
||||
return ['code' => 1, 'msg' => __('聚合登录接口请求失败', 'jio')];
|
||||
}
|
||||
$data = json_decode((string) wp_remote_retrieve_body($response), true);
|
||||
if (!is_array($data)) {
|
||||
return ['code' => 1, 'msg' => __('聚合登录接口返回异常', 'aksrt')];
|
||||
return ['code' => 1, 'msg' => __('聚合登录接口返回异常', 'jio')];
|
||||
}
|
||||
if ($expect_url && empty($data['code']) && OAuthUrlPolicy::public_https((string) ($data['url'] ?? '')) === '') {
|
||||
return ['code' => 1, 'msg' => __('聚合登录返回地址无效', 'aksrt')];
|
||||
return ['code' => 1, 'msg' => __('聚合登录返回地址无效', 'jio')];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
+30
-30
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -44,7 +44,7 @@ class Moderation {
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$this->config = get_option('aksrt_moderation_config', []);
|
||||
$this->config = get_option('jio_moderation_config', []);
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
@@ -97,10 +97,10 @@ class Moderation {
|
||||
public function process(array $commentdata): array {
|
||||
|
||||
$actor = get_current_user_id();
|
||||
if (!function_exists('aksrt_user_can') || !aksrt_user_can('comment_add', $actor, (int) ($commentdata['comment_post_ID'] ?? 0))) {
|
||||
if (!function_exists('jio_user_can') || !jio_user_can('comment_add', $actor, (int) ($commentdata['comment_post_ID'] ?? 0))) {
|
||||
wp_die(
|
||||
esc_html__('当前账号没有发表评论的权限。', 'aksrt'),
|
||||
esc_html__('评论提交失败', 'aksrt'),
|
||||
esc_html__('当前账号没有发表评论的权限。', 'jio'),
|
||||
esc_html__('评论提交失败', 'jio'),
|
||||
['response' => $actor > 0 ? 403 : 401, 'back_link' => true]
|
||||
);
|
||||
}
|
||||
@@ -111,14 +111,14 @@ class Moderation {
|
||||
if (isset($payload['captcha']) && is_array($payload['captcha'])) {
|
||||
$payload = array_merge($payload, $payload['captcha']);
|
||||
}
|
||||
$captcha_result = aksrt_require_captcha('comment', $payload);
|
||||
$captcha_result = jio_require_captcha('comment', $payload);
|
||||
if ($captcha_result !== true) {
|
||||
$msg = is_wp_error($captcha_result)
|
||||
? $captcha_result->get_error_message()
|
||||
: __('人机验证失败', 'aksrt');
|
||||
: __('人机验证失败', 'jio');
|
||||
wp_die(
|
||||
esc_html($msg !== '' ? $msg : __('人机验证失败', 'aksrt')),
|
||||
esc_html__('评论提交失败', 'aksrt'),
|
||||
esc_html($msg !== '' ? $msg : __('人机验证失败', 'jio')),
|
||||
esc_html__('评论提交失败', 'jio'),
|
||||
['response' => 400, 'back_link' => true]
|
||||
);
|
||||
}
|
||||
@@ -126,9 +126,9 @@ class Moderation {
|
||||
|
||||
// [防刷机制]评论限制(后台「扩展&增强 → 网站安全」),管理员不受限;
|
||||
// 未登录用户按 IP 判断,与下方审核限流(间隔/每小时)互为补充。
|
||||
if (!current_user_can('manage_options') && class_exists('\AKSRT\Extensions\SecurityHardening')) {
|
||||
$security = \AKSRT\Settings\ExtensionRuntime::get_security_settings();
|
||||
$brush = \AKSRT\Extensions\SecurityHardening::brush_allow(
|
||||
if (!current_user_can('manage_options') && class_exists('\Jio\Extensions\SecurityHardening')) {
|
||||
$security = \Jio\Settings\ExtensionRuntime::get_security_settings();
|
||||
$brush = \Jio\Extensions\SecurityHardening::brush_allow(
|
||||
'comment',
|
||||
$actor > 0 ? (string) $actor : $this->get_client_ip(),
|
||||
(int) $security['security_brush_comment_10min'],
|
||||
@@ -137,7 +137,7 @@ class Moderation {
|
||||
if ($brush !== true) {
|
||||
wp_die(
|
||||
'<p>' . esc_html((string) $brush) . '</p>',
|
||||
esc_html__('评论提交失败', 'aksrt'),
|
||||
esc_html__('评论提交失败', 'jio'),
|
||||
['response' => 429]
|
||||
);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ class Moderation {
|
||||
]);
|
||||
wp_die(
|
||||
'<p>' . esc_html($rate_result) . '</p>',
|
||||
__('Rate limit', 'aksrt'),
|
||||
__('Rate limit', 'jio'),
|
||||
['response' => 429]
|
||||
);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ class Moderation {
|
||||
]);
|
||||
wp_die(
|
||||
'<p>' . esc_html($geoip_result) . '</p>',
|
||||
__('Geo restriction', 'aksrt'),
|
||||
__('Geo restriction', 'jio'),
|
||||
['response' => 403]
|
||||
);
|
||||
}
|
||||
@@ -313,15 +313,15 @@ class Moderation {
|
||||
$decision = $this->resolve_result_from_runtime_or_default($commentdata, $comment);
|
||||
$decision = $this->enrich_moderation_result($decision, (array) $comment);
|
||||
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_result', (string) $decision['result']);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_source', (string) $decision['source']);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_reason', (string) $decision['reason']);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_akismet', (string) $decision['akismet']);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_ai_score', (string) $decision['ai_score']);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_ai_flagged', (string) $decision['ai_flagged']);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_ai_top_category', (string) $decision['ai_top_category']);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_keyword', (string) $decision['keyword']);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_keyword_match_type', (string) $decision['keyword_match_type']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_result', (string) $decision['result']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_source', (string) $decision['source']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_reason', (string) $decision['reason']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_akismet', (string) $decision['akismet']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_ai_score', (string) $decision['ai_score']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_ai_flagged', (string) $decision['ai_flagged']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_ai_top_category', (string) $decision['ai_top_category']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_keyword', (string) $decision['keyword']);
|
||||
update_comment_meta($comment_id, 'jio_moderation_keyword_match_type', (string) $decision['keyword_match_type']);
|
||||
|
||||
$moderation_user_id = isset($comment->user_id) ? (int) $comment->user_id : 0;
|
||||
$moderation_user_ip = trim((string) ($comment->comment_author_IP ?? ''));
|
||||
@@ -332,8 +332,8 @@ class Moderation {
|
||||
$moderation_user_ip = trim((string) ($commentdata['comment_author_IP'] ?? ($commentdata['comment_author_ip'] ?? '')));
|
||||
}
|
||||
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_user_id', (string) $moderation_user_id);
|
||||
update_comment_meta($comment_id, 'aksrt_moderation_user_ip', $moderation_user_ip);
|
||||
update_comment_meta($comment_id, 'jio_moderation_user_id', (string) $moderation_user_id);
|
||||
update_comment_meta($comment_id, 'jio_moderation_user_ip', $moderation_user_ip);
|
||||
|
||||
// Convenience marker for external tools expecting Akismet style keys.
|
||||
if ($decision['source'] === 'akismet' && $decision['akismet'] === 'spam') {
|
||||
@@ -355,11 +355,11 @@ class Moderation {
|
||||
foreach ($columns as $key => $label) {
|
||||
$new[$key] = $label;
|
||||
if ($key === 'comment') {
|
||||
$new['aksrt_moderation'] = __('Moderation', 'aksrt');
|
||||
$new['jio_moderation'] = __('Moderation', 'jio');
|
||||
}
|
||||
}
|
||||
if (!isset($new['aksrt_moderation'])) {
|
||||
$new['aksrt_moderation'] = __('Moderation', 'aksrt');
|
||||
if (!isset($new['jio_moderation'])) {
|
||||
$new['jio_moderation'] = __('Moderation', 'jio');
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
trait ModerationPart1 {
|
||||
|
||||
public function render_comments_custom_column(string $column, int $comment_id): void {
|
||||
if ($column !== 'aksrt_moderation') {
|
||||
if ($column !== 'jio_moderation') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,17 +23,17 @@ trait ModerationPart1 {
|
||||
}
|
||||
$status_label = $this->status_label($status);
|
||||
|
||||
$source = (string) get_comment_meta($comment_id, 'aksrt_moderation_source', true);
|
||||
$result_value = (string) get_comment_meta($comment_id, 'aksrt_moderation_result', true);
|
||||
$reason = (string) get_comment_meta($comment_id, 'aksrt_moderation_reason', true);
|
||||
$akismet = (string) get_comment_meta($comment_id, 'aksrt_moderation_akismet', true);
|
||||
$ai_score = (string) get_comment_meta($comment_id, 'aksrt_moderation_ai_score', true);
|
||||
$ai_flagged = (string) get_comment_meta($comment_id, 'aksrt_moderation_ai_flagged', true);
|
||||
$ai_top = (string) get_comment_meta($comment_id, 'aksrt_moderation_ai_top_category', true);
|
||||
$keyword = (string) get_comment_meta($comment_id, 'aksrt_moderation_keyword', true);
|
||||
$match_type = (string) get_comment_meta($comment_id, 'aksrt_moderation_keyword_match_type', true);
|
||||
$moderation_user_id = (string) get_comment_meta($comment_id, 'aksrt_moderation_user_id', true);
|
||||
$moderation_user_ip = (string) get_comment_meta($comment_id, 'aksrt_moderation_user_ip', true);
|
||||
$source = (string) get_comment_meta($comment_id, 'jio_moderation_source', true);
|
||||
$result_value = (string) get_comment_meta($comment_id, 'jio_moderation_result', true);
|
||||
$reason = (string) get_comment_meta($comment_id, 'jio_moderation_reason', true);
|
||||
$akismet = (string) get_comment_meta($comment_id, 'jio_moderation_akismet', true);
|
||||
$ai_score = (string) get_comment_meta($comment_id, 'jio_moderation_ai_score', true);
|
||||
$ai_flagged = (string) get_comment_meta($comment_id, 'jio_moderation_ai_flagged', true);
|
||||
$ai_top = (string) get_comment_meta($comment_id, 'jio_moderation_ai_top_category', true);
|
||||
$keyword = (string) get_comment_meta($comment_id, 'jio_moderation_keyword', true);
|
||||
$match_type = (string) get_comment_meta($comment_id, 'jio_moderation_keyword_match_type', true);
|
||||
$moderation_user_id = (string) get_comment_meta($comment_id, 'jio_moderation_user_id', true);
|
||||
$moderation_user_ip = (string) get_comment_meta($comment_id, 'jio_moderation_user_ip', true);
|
||||
|
||||
if ($source === '') {
|
||||
$source = 'wp_default';
|
||||
@@ -302,11 +302,11 @@ trait ModerationPart1 {
|
||||
}
|
||||
|
||||
// 委托给统一内容审核服务
|
||||
if (!class_exists('\AKSRT\Extensions\ContentAudit')) {
|
||||
if (!class_exists('\Jio\Extensions\ContentAudit')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$result = \AKSRT\Extensions\ContentAudit::get_instance()->audit_text($content);
|
||||
$result = \Jio\Extensions\ContentAudit::get_instance()->audit_text($content);
|
||||
if ($result['passed']) {
|
||||
return true;
|
||||
}
|
||||
@@ -338,11 +338,11 @@ trait ModerationPart1 {
|
||||
return ['passed' => true, 'reason' => 'disabled'];
|
||||
}
|
||||
|
||||
if (!class_exists('\AKSRT\Extensions\ContentAudit')) {
|
||||
if (!class_exists('\Jio\Extensions\ContentAudit')) {
|
||||
return ['passed' => true, 'reason' => 'audit_service_missing'];
|
||||
}
|
||||
|
||||
return \AKSRT\Extensions\ContentAudit::get_instance()->audit_image($image_path);
|
||||
return \Jio\Extensions\ContentAudit::get_instance()->audit_image($image_path);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -30,7 +30,7 @@ trait ModerationPart2 {
|
||||
|
||||
$min_interval = max(1, (int) ($config['rate_limit_min_interval'] ?? 8));
|
||||
$max_per_hour = max(1, (int) ($config['rate_limit_max_per_hour'] ?? 15));
|
||||
$prefix = 'aksrt_rate_';
|
||||
$prefix = 'jio_rate_';
|
||||
|
||||
$last_key = $prefix . md5($ip . '_last');
|
||||
$hour_key = $prefix . md5($ip . '_hourly');
|
||||
@@ -41,7 +41,7 @@ trait ModerationPart2 {
|
||||
$elapsed = time() - (int) $last_comment_time;
|
||||
if ($elapsed < $min_interval) {
|
||||
$wait_time = $min_interval - $elapsed;
|
||||
return sprintf(__('You are commenting too fast. Please wait %d seconds.', 'aksrt'), $wait_time);
|
||||
return sprintf(__('You are commenting too fast. Please wait %d seconds.', 'jio'), $wait_time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ trait ModerationPart2 {
|
||||
$reset_time = (int) (get_transient($exp_key) ?: time());
|
||||
$remaining = max(0, $reset_time - time());
|
||||
$minutes = (int) ceil($remaining / 60);
|
||||
return sprintf(__('You have reached the hourly comment limit. Try again in %d minutes.', 'aksrt'), $minutes);
|
||||
return sprintf(__('You have reached the hourly comment limit. Try again in %d minutes.', 'jio'), $minutes);
|
||||
}
|
||||
|
||||
if ($hourly_count === false) {
|
||||
@@ -86,7 +86,7 @@ trait ModerationPart2 {
|
||||
$country_code = strtoupper($country_code);
|
||||
$block_upper = array_map('strtoupper', $block_countries);
|
||||
if (in_array($country_code, $block_upper, true)) {
|
||||
return sprintf(__('Comments from your region (%s) are currently blocked.', 'aksrt'), esc_html($country_code));
|
||||
return sprintf(__('Comments from your region (%s) are currently blocked.', 'jio'), esc_html($country_code));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -110,8 +110,8 @@ trait ModerationPart2 {
|
||||
}
|
||||
|
||||
// Last resort: map IPGeo country label → ISO when possible.
|
||||
if (class_exists('\AKSRT\Extensions\IPGeo')) {
|
||||
$result = \AKSRT\Extensions\IPGeo::get_instance()->lookup($ip);
|
||||
if (class_exists('\Jio\Extensions\IPGeo')) {
|
||||
$result = \Jio\Extensions\IPGeo::get_instance()->lookup($ip);
|
||||
$label = trim((string) ($result['country'] ?? ''));
|
||||
if ($label !== '') {
|
||||
return $this->country_label_to_iso($label);
|
||||
@@ -205,8 +205,8 @@ trait ModerationPart2 {
|
||||
// ============================================================
|
||||
|
||||
private function get_client_ip(): string {
|
||||
if (function_exists('aksrt_get_client_ip')) {
|
||||
return (string) aksrt_get_client_ip();
|
||||
if (function_exists('jio_get_client_ip')) {
|
||||
return (string) jio_get_client_ip();
|
||||
}
|
||||
$keys = [
|
||||
'HTTP_CF_CONNECTING_IP',
|
||||
|
||||
+42
-42
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -36,23 +36,23 @@ final class OAuth {
|
||||
}, 30);
|
||||
add_action('template_redirect', [$this, 'handle_routes'], 8);
|
||||
add_action('rest_api_init', [$this, 'register_rest_routes']);
|
||||
add_action('wp_ajax_aksrt_oauth_unbind', [$this, 'ajax_unbind']);
|
||||
add_action('wp_ajax_jio_oauth_unbind', [$this, 'ajax_unbind']);
|
||||
}
|
||||
|
||||
public function add_rewrite_rules(): void {
|
||||
add_rewrite_rule('^oauth/start/([a-z0-9_-]+)/?$', 'index.php?aksrt_oauth=start&aksrt_oauth_provider=$matches[1]', 'top');
|
||||
add_rewrite_rule('^oauth/callback/?$', 'index.php?aksrt_oauth=callback', 'top');
|
||||
add_rewrite_rule('^oauth/clogin/?$', 'index.php?aksrt_oauth=clogin', 'top');
|
||||
add_rewrite_rule('^oauth/clogin/callback/?$', 'index.php?aksrt_oauth=clogin_callback', 'top');
|
||||
add_rewrite_rule('^oauth/start/([a-z0-9_-]+)/?$', 'index.php?jio_oauth=start&jio_oauth_provider=$matches[1]', 'top');
|
||||
add_rewrite_rule('^oauth/callback/?$', 'index.php?jio_oauth=callback', 'top');
|
||||
add_rewrite_rule('^oauth/clogin/?$', 'index.php?jio_oauth=clogin', 'top');
|
||||
add_rewrite_rule('^oauth/clogin/callback/?$', 'index.php?jio_oauth=clogin_callback', 'top');
|
||||
add_filter('query_vars', static function (array $vars): array {
|
||||
$vars[] = 'aksrt_oauth';
|
||||
$vars[] = 'aksrt_oauth_provider';
|
||||
$vars[] = 'jio_oauth';
|
||||
$vars[] = 'jio_oauth_provider';
|
||||
return $vars;
|
||||
});
|
||||
}
|
||||
|
||||
public function register_rest_routes(): void {
|
||||
register_rest_route('aksrt/v1', '/oauth/bind-pass', [
|
||||
register_rest_route('jio/v1', '/oauth/bind-pass', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'rest_issue_bind_pass'],
|
||||
'permission_callback' => static function (): bool {
|
||||
@@ -68,7 +68,7 @@ final class OAuth {
|
||||
return new \WP_REST_Response([
|
||||
'success' => false,
|
||||
'code' => 'oauth_bind_nonce_invalid',
|
||||
'message' => __('安全验证失败,请刷新页面重试', 'aksrt'),
|
||||
'message' => __('安全验证失败,请刷新页面重试', 'jio'),
|
||||
], 403);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ final class OAuth {
|
||||
return new \WP_REST_Response([
|
||||
'success' => false,
|
||||
'code' => 'oauth_bind_provider_invalid',
|
||||
'message' => __('该第三方登录方式不可用', 'aksrt'),
|
||||
'message' => __('该第三方登录方式不可用', 'jio'),
|
||||
], 400);
|
||||
}
|
||||
|
||||
@@ -88,25 +88,25 @@ final class OAuth {
|
||||
return new \WP_REST_Response([
|
||||
'success' => false,
|
||||
'code' => 'oauth_bind_provider_invalid',
|
||||
'message' => __('该第三方登录方式不可用', 'aksrt'),
|
||||
'message' => __('该第三方登录方式不可用', 'jio'),
|
||||
], 400);
|
||||
}
|
||||
$redirect = OAuthUrlPolicy::validated_redirect((string) ($payload['redirect_to'] ?? ''), home_url('/'));
|
||||
$url = add_query_arg('redirect_to', $redirect, $url);
|
||||
|
||||
if (!aksrt_is_captcha_enabled_for('bind')) {
|
||||
if (!jio_is_captcha_enabled_for('bind')) {
|
||||
return new \WP_REST_Response([
|
||||
'success' => true,
|
||||
'data' => ['url' => $url],
|
||||
], 200);
|
||||
}
|
||||
|
||||
$result = aksrt_require_captcha('bind', $payload);
|
||||
$result = jio_require_captcha('bind', $payload);
|
||||
if ($result !== true) {
|
||||
return new \WP_REST_Response([
|
||||
'success' => false,
|
||||
'code' => is_wp_error($result) ? $result->get_error_code() : 'aksrt_captcha_failed',
|
||||
'message' => is_wp_error($result) ? $result->get_error_message() : __('人机验证失败,请重试', 'aksrt'),
|
||||
'code' => is_wp_error($result) ? $result->get_error_code() : 'jio_captcha_failed',
|
||||
'message' => is_wp_error($result) ? $result->get_error_message() : __('人机验证失败,请重试', 'jio'),
|
||||
], 400);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ final class OAuth {
|
||||
return new \WP_REST_Response([
|
||||
'success' => false,
|
||||
'code' => 'oauth_bind_pass_issue_failed',
|
||||
'message' => __('无法创建绑定会话,请稍后重试', 'aksrt'),
|
||||
'message' => __('无法创建绑定会话,请稍后重试', 'jio'),
|
||||
], 500);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ final class OAuth {
|
||||
}
|
||||
|
||||
public static function validate_bind_pass(string $token, string $provider, int $user_id, bool $consume = true): bool {
|
||||
if (!aksrt_is_captcha_enabled_for('bind')) {
|
||||
if (!jio_is_captcha_enabled_for('bind')) {
|
||||
return true;
|
||||
}
|
||||
if ($token === '' || $user_id <= 0) {
|
||||
@@ -155,15 +155,15 @@ final class OAuth {
|
||||
}
|
||||
|
||||
public function maybe_flush_rewrite_rules(): void {
|
||||
$version = defined('AKSRT_VERSION') ? AKSRT_VERSION . ':oauth-v2' : 'oauth-v2';
|
||||
if (get_option('aksrt_oauth_routes_flushed') !== $version) {
|
||||
$version = defined('JIO_VERSION') ? JIO_VERSION . ':oauth-v2' : 'oauth-v2';
|
||||
if (get_option('jio_oauth_routes_flushed') !== $version) {
|
||||
flush_rewrite_rules(false);
|
||||
update_option('aksrt_oauth_routes_flushed', $version, false);
|
||||
update_option('jio_oauth_routes_flushed', $version, false);
|
||||
}
|
||||
}
|
||||
|
||||
public function handle_routes(): void {
|
||||
$route = sanitize_key((string) get_query_var('aksrt_oauth'));
|
||||
$route = sanitize_key((string) get_query_var('jio_oauth'));
|
||||
if ($route === '') {
|
||||
return;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ final class OAuth {
|
||||
? OAuthUrlPolicy::validated_redirect((string) wp_unslash($_GET['redirect_to']), home_url('/'))
|
||||
: '';
|
||||
if ($provider === 'weixingzh') {
|
||||
$url = function_exists('aksrt_get_sign_page_url') ? aksrt_get_sign_page_url('oauth') : home_url('/sign/?tab=oauth');
|
||||
$url = function_exists('jio_get_sign_page_url') ? jio_get_sign_page_url('oauth') : home_url('/sign/?tab=oauth');
|
||||
$url = add_query_arg('oauth_intent', $action, $url);
|
||||
return $redirect !== '' ? add_query_arg('redirect_to', $redirect, $url) : $url;
|
||||
}
|
||||
@@ -218,7 +218,7 @@ final class OAuth {
|
||||
$result[] = [
|
||||
'name' => $provider,
|
||||
'label' => OAuthProviderCatalog::label($provider),
|
||||
'icon' => function_exists('aksrt_brand_icon') ? aksrt_brand_icon(OAuthProviderCatalog::icon_key($provider)) : '',
|
||||
'icon' => function_exists('jio_brand_icon') ? jio_brand_icon(OAuthProviderCatalog::icon_key($provider)) : '',
|
||||
// Raw, matching get_frontend_bindings_data(): every surface escapes
|
||||
// once on output. esc_url() is idempotent on its own output, so
|
||||
// escaping here too was redundant rather than broken.
|
||||
@@ -242,7 +242,7 @@ final class OAuth {
|
||||
return '';
|
||||
}
|
||||
|
||||
$large = (bool) \AKSRT\Settings\Settings::get_value('oauth_button_lg', false);
|
||||
$large = (bool) \Jio\Settings\Settings::get_value('oauth_button_lg', false);
|
||||
$html = $title !== ''
|
||||
? '<p class="social-separator separator muted-3-color em09 mt10">' . esc_html($title) . '</p>'
|
||||
: '';
|
||||
@@ -263,10 +263,10 @@ final class OAuth {
|
||||
}
|
||||
$html .= '<a rel="nofollow" href="' . esc_url($url) . '" class="' . esc_attr($class) . '"'
|
||||
. ' data-provider="' . esc_attr($name) . '"'
|
||||
. ' aria-label="' . esc_attr(sprintf(__('%s登录', 'aksrt'), $label)) . '"'
|
||||
. ' title="' . esc_attr(sprintf(__('%s登录', 'aksrt'), $label)) . '">'
|
||||
. ' aria-label="' . esc_attr(sprintf(__('%s登录', 'jio'), $label)) . '"'
|
||||
. ' title="' . esc_attr(sprintf(__('%s登录', 'jio'), $label)) . '">'
|
||||
. $item['icon'] // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
. ($large ? '<span>' . esc_html(sprintf(__('%s登录', 'aksrt'), $label)) . '</span>' : '')
|
||||
. ($large ? '<span>' . esc_html(sprintf(__('%s登录', 'jio'), $label)) . '</span>' : '')
|
||||
. '</a>';
|
||||
}
|
||||
return $html . '</div>';
|
||||
@@ -294,30 +294,30 @@ final class OAuth {
|
||||
}
|
||||
|
||||
public function ajax_unbind(): void {
|
||||
check_ajax_referer('aksrt_oauth_unbind', 'nonce');
|
||||
check_ajax_referer('jio_oauth_unbind', 'nonce');
|
||||
$provider = sanitize_key((string) ($_POST['provider'] ?? ''));
|
||||
$user_id = isset($_POST['userId']) ? (int) $_POST['userId'] : 0;
|
||||
$current_id = get_current_user_id();
|
||||
if ($current_id <= 0 || $current_id !== $user_id || !current_user_can('read')) {
|
||||
wp_send_json_error(['message' => __('无权执行此操作', 'aksrt')], 403);
|
||||
wp_send_json_error(['message' => __('无权执行此操作', 'jio')], 403);
|
||||
}
|
||||
$result = OAuthAccountService::unbind($current_id, $provider);
|
||||
if (is_wp_error($result)) {
|
||||
$status = $result->get_error_code() === 'oauth_last_login_method' ? 409 : 400;
|
||||
wp_send_json_error(['message' => $result->get_error_message()], $status);
|
||||
}
|
||||
wp_send_json_success(['unbound' => true, 'message' => __('解除绑定成功', 'aksrt')]);
|
||||
wp_send_json_success(['unbound' => true, 'message' => __('解除绑定成功', 'jio')]);
|
||||
}
|
||||
|
||||
private function handle_start(): void {
|
||||
$provider = sanitize_key((string) get_query_var('aksrt_oauth_provider'));
|
||||
$provider = sanitize_key((string) get_query_var('jio_oauth_provider'));
|
||||
$action = isset($_GET['action']) && sanitize_key((string) $_GET['action']) === 'bind' ? 'bind' : 'login';
|
||||
if (!OAuthProviderCatalog::master_enabled() || !in_array($provider, OAuthProviderCatalog::enabled_login_keys(), true)) {
|
||||
$this->redirect_error('provider_disabled', $provider, $action);
|
||||
}
|
||||
$user_id = get_current_user_id();
|
||||
if ($action === 'bind' && $user_id <= 0) {
|
||||
wp_safe_redirect(function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url());
|
||||
wp_safe_redirect(function_exists('jio_get_login_url') ? jio_get_login_url() : wp_login_url());
|
||||
exit;
|
||||
}
|
||||
if ($action === 'bind') {
|
||||
@@ -380,7 +380,7 @@ final class OAuth {
|
||||
if (is_wp_error($result)) {
|
||||
throw new \RuntimeException($result->get_error_code());
|
||||
}
|
||||
$this->redirect_success('bind', $provider, function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('settings') : home_url('/'));
|
||||
$this->redirect_success('bind', $provider, function_exists('jio_get_user_center_url') ? jio_get_user_center_url('settings') : home_url('/'));
|
||||
}
|
||||
$this->complete_identity_login($provider, $identity, (string) ($payload['redirect_to'] ?? home_url('/')));
|
||||
} catch (\Throwable $e) {
|
||||
@@ -396,7 +396,7 @@ final class OAuth {
|
||||
$this->redirect_error('provider_disabled', 'clogin_' . $type, $action);
|
||||
}
|
||||
if ($action === 'bind' && !is_user_logged_in()) {
|
||||
wp_safe_redirect(function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url());
|
||||
wp_safe_redirect(function_exists('jio_get_login_url') ? jio_get_login_url() : wp_login_url());
|
||||
exit;
|
||||
}
|
||||
if ($action === 'bind') {
|
||||
@@ -468,7 +468,7 @@ final class OAuth {
|
||||
if (is_wp_error($result)) {
|
||||
$this->redirect_error('binding_conflict', $provider, $action);
|
||||
}
|
||||
$this->redirect_success('bind', $provider, function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('settings') : home_url('/'));
|
||||
$this->redirect_success('bind', $provider, function_exists('jio_get_user_center_url') ? jio_get_user_center_url('settings') : home_url('/'));
|
||||
}
|
||||
$this->complete_identity_login($provider, $identity, (string) ($payload['redirect_to'] ?? home_url('/')));
|
||||
}
|
||||
@@ -482,7 +482,7 @@ final class OAuth {
|
||||
'user_data' => $identity,
|
||||
'redirect_to' => OAuthUrlPolicy::validated_redirect($redirect, home_url('/')),
|
||||
], 15 * MINUTE_IN_SECONDS);
|
||||
$url = function_exists('aksrt_get_bind_url') ? aksrt_get_bind_url($obk) : home_url('/sign/?tab=bind&obk=' . rawurlencode($obk));
|
||||
$url = function_exists('jio_get_bind_url') ? jio_get_bind_url($obk) : home_url('/sign/?tab=bind&obk=' . rawurlencode($obk));
|
||||
wp_safe_redirect($url);
|
||||
exit;
|
||||
}
|
||||
@@ -497,7 +497,7 @@ final class OAuth {
|
||||
return [
|
||||
'key' => $provider,
|
||||
'name' => OAuthProviderCatalog::label($provider),
|
||||
'icon' => function_exists('aksrt_brand_icon') ? aksrt_brand_icon(OAuthProviderCatalog::icon_key($provider)) : '',
|
||||
'icon' => function_exists('jio_brand_icon') ? jio_brand_icon(OAuthProviderCatalog::icon_key($provider)) : '',
|
||||
'is_bound' => $bound,
|
||||
'url' => '',
|
||||
];
|
||||
@@ -512,9 +512,9 @@ final class OAuth {
|
||||
}
|
||||
|
||||
private function redirect_error(string $code, string $provider = '', string $action = 'login'): void {
|
||||
$target = $action === 'bind' && is_user_logged_in() && function_exists('aksrt_get_user_center_url')
|
||||
? aksrt_get_user_center_url('settings')
|
||||
: (function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url());
|
||||
$target = $action === 'bind' && is_user_logged_in() && function_exists('jio_get_user_center_url')
|
||||
? jio_get_user_center_url('settings')
|
||||
: (function_exists('jio_get_login_url') ? jio_get_login_url() : wp_login_url());
|
||||
wp_safe_redirect(add_query_arg([
|
||||
'oauth_action' => 'error',
|
||||
'oauth_provider' => sanitize_key($provider),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -28,7 +28,7 @@ final class OAuthAccountService {
|
||||
return is_wp_error($result) ? $result : $user;
|
||||
}
|
||||
}
|
||||
return new \WP_Error('oauth_no_match', __('需要绑定已有账号', 'aksrt'), [
|
||||
return new \WP_Error('oauth_no_match', __('需要绑定已有账号', 'jio'), [
|
||||
'provider' => $provider,
|
||||
'user_data' => $identity,
|
||||
]);
|
||||
@@ -40,7 +40,7 @@ final class OAuthAccountService {
|
||||
return null;
|
||||
}
|
||||
$users = get_users([
|
||||
'meta_key' => 'aksrt_' . $provider . '_id',
|
||||
'meta_key' => 'jio_' . $provider . '_id',
|
||||
'meta_value' => $provider_id,
|
||||
'number' => 1,
|
||||
'fields' => 'all',
|
||||
@@ -52,27 +52,27 @@ final class OAuthAccountService {
|
||||
$provider = sanitize_key($provider);
|
||||
$provider_id = trim((string) ($identity['provider_id'] ?? ''));
|
||||
if ($user_id <= 0 || !OAuthProviderCatalog::is_binding_provider($provider) || $provider_id === '') {
|
||||
return new \WP_Error('oauth_binding_invalid', __('第三方账号信息无效', 'aksrt'));
|
||||
return new \WP_Error('oauth_binding_invalid', __('第三方账号信息无效', 'jio'));
|
||||
}
|
||||
$scope = 'identity:' . $provider . ':' . $provider_id;
|
||||
$lock = OAuthTransactionStore::acquire_lock($scope, 20);
|
||||
if ($lock === false) {
|
||||
return new \WP_Error('oauth_binding_busy', __('该第三方账号正在绑定,请稍后重试', 'aksrt'));
|
||||
return new \WP_Error('oauth_binding_busy', __('该第三方账号正在绑定,请稍后重试', 'jio'));
|
||||
}
|
||||
try {
|
||||
$existing = self::find($provider, $provider_id);
|
||||
if ($existing && (int) $existing->ID !== $user_id) {
|
||||
return new \WP_Error('oauth_binding_conflict', __('该第三方账号已被其他用户绑定', 'aksrt'));
|
||||
return new \WP_Error('oauth_binding_conflict', __('该第三方账号已被其他用户绑定', 'jio'));
|
||||
}
|
||||
update_user_meta($user_id, 'aksrt_' . $provider . '_id', $provider_id);
|
||||
$bindings = get_user_meta($user_id, 'aksrt_oauth_bindings', true);
|
||||
update_user_meta($user_id, 'jio_' . $provider . '_id', $provider_id);
|
||||
$bindings = get_user_meta($user_id, 'jio_oauth_bindings', true);
|
||||
$bindings = is_array($bindings) ? array_values(array_intersect($bindings, OAuthProviderCatalog::all_binding_keys())) : [];
|
||||
if (!in_array($provider, $bindings, true)) {
|
||||
$bindings[] = $provider;
|
||||
}
|
||||
update_user_meta($user_id, 'aksrt_oauth_bindings', array_values(array_unique($bindings)));
|
||||
update_user_meta($user_id, 'jio_oauth_bindings', array_values(array_unique($bindings)));
|
||||
if (!empty($identity['avatar_url'])) {
|
||||
update_user_meta($user_id, 'aksrt_oauth_avatar', esc_url_raw((string) $identity['avatar_url']));
|
||||
update_user_meta($user_id, 'jio_oauth_avatar', esc_url_raw((string) $identity['avatar_url']));
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
@@ -83,17 +83,17 @@ final class OAuthAccountService {
|
||||
public static function unbind(int $user_id, string $provider) {
|
||||
$provider = sanitize_key($provider);
|
||||
if ($user_id <= 0 || !OAuthProviderCatalog::is_binding_provider($provider)) {
|
||||
return new \WP_Error('oauth_unbind_invalid', __('第三方账号类型无效', 'aksrt'));
|
||||
return new \WP_Error('oauth_unbind_invalid', __('第三方账号类型无效', 'jio'));
|
||||
}
|
||||
if (!self::has_recovery_after_unbind($user_id, $provider)) {
|
||||
return new \WP_Error('oauth_last_login_method', __('请先设置其他登录或找回方式,再解除当前绑定', 'aksrt'));
|
||||
return new \WP_Error('oauth_last_login_method', __('请先设置其他登录或找回方式,再解除当前绑定', 'jio'));
|
||||
}
|
||||
$bindings = get_user_meta($user_id, 'aksrt_oauth_bindings', true);
|
||||
$bindings = get_user_meta($user_id, 'jio_oauth_bindings', true);
|
||||
$bindings = is_array($bindings) ? $bindings : [];
|
||||
$bindings = array_values(array_diff($bindings, [$provider]));
|
||||
update_user_meta($user_id, 'aksrt_oauth_bindings', $bindings);
|
||||
delete_user_meta($user_id, 'aksrt_' . $provider . '_id');
|
||||
delete_user_meta($user_id, 'aksrt_' . $provider . '_token');
|
||||
update_user_meta($user_id, 'jio_oauth_bindings', $bindings);
|
||||
delete_user_meta($user_id, 'jio_' . $provider . '_id');
|
||||
delete_user_meta($user_id, 'jio_' . $provider . '_token');
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ final class OAuthAccountService {
|
||||
}
|
||||
|
||||
public static function bindings(int $user_id): array {
|
||||
$bindings = get_user_meta($user_id, 'aksrt_oauth_bindings', true);
|
||||
$bindings = get_user_meta($user_id, 'jio_oauth_bindings', true);
|
||||
return is_array($bindings) ? array_values(array_intersect($bindings, OAuthProviderCatalog::all_binding_keys())) : [];
|
||||
}
|
||||
|
||||
@@ -112,10 +112,10 @@ final class OAuthAccountService {
|
||||
$bindings = self::bindings($user_id);
|
||||
if (!in_array($provider, $bindings, true)) {
|
||||
$bindings[] = $provider;
|
||||
update_user_meta($user_id, 'aksrt_oauth_bindings', array_values(array_unique($bindings)));
|
||||
update_user_meta($user_id, 'jio_oauth_bindings', array_values(array_unique($bindings)));
|
||||
}
|
||||
if (!empty($identity['avatar_url'])) {
|
||||
update_user_meta($user_id, 'aksrt_oauth_avatar', esc_url_raw((string) $identity['avatar_url']));
|
||||
update_user_meta($user_id, 'jio_oauth_avatar', esc_url_raw((string) $identity['avatar_url']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ final class OAuthAccountService {
|
||||
if ($remaining !== []) {
|
||||
return true;
|
||||
}
|
||||
if (get_user_meta($user_id, 'aksrt_phone_verified', true) === '1') {
|
||||
if (get_user_meta($user_id, 'jio_phone_verified', true) === '1') {
|
||||
return true;
|
||||
}
|
||||
$user = get_user_by('id', $user_id);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -12,7 +12,7 @@ final class OAuthProviderBroker {
|
||||
public function auth_url(string $provider, string $redirect_uri, string $state): string {
|
||||
$config = OAuthProviderCatalog::provider_config($provider);
|
||||
if (!$config || !$config['configured']) {
|
||||
throw new \RuntimeException(__('未配置此第三方登录平台', 'aksrt'));
|
||||
throw new \RuntimeException(__('未配置此第三方登录平台', 'jio'));
|
||||
}
|
||||
if ($provider === 'google') {
|
||||
return 'https://accounts.google.com/o/oauth2/v2/auth?' . http_build_query([
|
||||
@@ -31,7 +31,7 @@ final class OAuthProviderBroker {
|
||||
public function identity(string $provider, string $code, string $redirect_uri, string $state): array {
|
||||
$config = OAuthProviderCatalog::provider_config($provider);
|
||||
if (!$config || !$config['configured']) {
|
||||
throw new \RuntimeException(__('未配置此第三方登录平台', 'aksrt'));
|
||||
throw new \RuntimeException(__('未配置此第三方登录平台', 'jio'));
|
||||
}
|
||||
if ($provider === 'google') {
|
||||
return $this->google_identity($config, $code, $redirect_uri);
|
||||
@@ -63,7 +63,7 @@ final class OAuthProviderBroker {
|
||||
case 'weixin':
|
||||
return new \Yurun\OAuthLogin\Weixin\OAuth2($config['client_id'], $config['client_secret'], $redirect_uri);
|
||||
}
|
||||
throw new \RuntimeException(__('不支持的第三方登录平台', 'aksrt'));
|
||||
throw new \RuntimeException(__('不支持的第三方登录平台', 'jio'));
|
||||
}
|
||||
|
||||
private function github_identity($oauth, array $info): array {
|
||||
@@ -106,11 +106,11 @@ final class OAuthProviderBroker {
|
||||
],
|
||||
]);
|
||||
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) {
|
||||
throw new \RuntimeException(is_wp_error($response) ? $response->get_error_message() : __('Google token 获取失败', 'aksrt'));
|
||||
throw new \RuntimeException(is_wp_error($response) ? $response->get_error_message() : __('Google token 获取失败', 'jio'));
|
||||
}
|
||||
$token = json_decode((string) wp_remote_retrieve_body($response), true);
|
||||
if (empty($token['access_token'])) {
|
||||
throw new \RuntimeException(__('Google token 获取失败', 'aksrt'));
|
||||
throw new \RuntimeException(__('Google token 获取失败', 'jio'));
|
||||
}
|
||||
$profile_response = wp_remote_get('https://openidconnect.googleapis.com/v1/userinfo', [
|
||||
'timeout' => 15,
|
||||
@@ -118,7 +118,7 @@ final class OAuthProviderBroker {
|
||||
'headers' => ['Authorization' => 'Bearer ' . $token['access_token']],
|
||||
]);
|
||||
if (is_wp_error($profile_response) || wp_remote_retrieve_response_code($profile_response) !== 200) {
|
||||
throw new \RuntimeException(is_wp_error($profile_response) ? $profile_response->get_error_message() : __('Google 用户信息获取失败', 'aksrt'));
|
||||
throw new \RuntimeException(is_wp_error($profile_response) ? $profile_response->get_error_message() : __('Google 用户信息获取失败', 'jio'));
|
||||
}
|
||||
$info = json_decode((string) wp_remote_retrieve_body($profile_response), true);
|
||||
return [
|
||||
@@ -178,6 +178,6 @@ final class OAuthProviderBroker {
|
||||
'avatar_url' => (string) ($info['headimgurl'] ?? ''),
|
||||
];
|
||||
}
|
||||
throw new \RuntimeException(__('不支持的第三方登录平台', 'aksrt'));
|
||||
throw new \RuntimeException(__('不支持的第三方登录平台', 'jio'));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
use AKSRT\Settings\Settings;
|
||||
use Jio\Settings\Settings;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -72,12 +72,12 @@ final class OAuthProviderCatalog {
|
||||
return self::DIRECT[$provider]['label'];
|
||||
}
|
||||
if ($provider === 'weixingzh') {
|
||||
return __('微信公众号', 'aksrt');
|
||||
return __('微信公众号', 'jio');
|
||||
}
|
||||
if (str_starts_with($provider, 'clogin_')) {
|
||||
$type = substr($provider, 7);
|
||||
if (in_array($type, self::CLOGIN_TYPES, true)) {
|
||||
return self::label($type) . ' · ' . __('聚合', 'aksrt');
|
||||
return self::label($type) . ' · ' . __('聚合', 'jio');
|
||||
}
|
||||
}
|
||||
return ucfirst($provider);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -27,18 +27,18 @@ final class OAuthProxyClient {
|
||||
}
|
||||
|
||||
public function add_rewrite_rules(): void {
|
||||
add_rewrite_rule('^oauth/proxy/callback/?$', 'index.php?aksrt_proxy_callback=1', 'top');
|
||||
add_rewrite_rule('^oauth/proxy/callback/?$', 'index.php?jio_proxy_callback=1', 'top');
|
||||
add_filter('query_vars', static function (array $vars): array {
|
||||
$vars[] = 'aksrt_proxy_callback';
|
||||
$vars[] = 'jio_proxy_callback';
|
||||
return $vars;
|
||||
});
|
||||
}
|
||||
|
||||
public function maybe_flush_rewrite_rules(): void {
|
||||
$version = defined('AKSRT_VERSION') ? AKSRT_VERSION . ':oauth-proxy-client-v2' : 'oauth-proxy-client-v2';
|
||||
if (get_option('aksrt_oauth_proxy_client_routes_flushed') !== $version) {
|
||||
$version = defined('JIO_VERSION') ? JIO_VERSION . ':oauth-proxy-client-v2' : 'oauth-proxy-client-v2';
|
||||
if (get_option('jio_oauth_proxy_client_routes_flushed') !== $version) {
|
||||
flush_rewrite_rules(false);
|
||||
update_option('aksrt_oauth_proxy_client_routes_flushed', $version, false);
|
||||
update_option('jio_oauth_proxy_client_routes_flushed', $version, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ final class OAuthProxyClient {
|
||||
}
|
||||
|
||||
public function handle_proxy_callback(): void {
|
||||
if (!get_query_var('aksrt_proxy_callback')) {
|
||||
if (!get_query_var('jio_proxy_callback')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -199,8 +199,8 @@ final class OAuthProxyClient {
|
||||
} catch (\Throwable $e) {
|
||||
$this->redirect_error('account_match_failed', $provider, $action);
|
||||
}
|
||||
$bind_url = function_exists('aksrt_get_bind_url')
|
||||
? aksrt_get_bind_url($obk)
|
||||
$bind_url = function_exists('jio_get_bind_url')
|
||||
? jio_get_bind_url($obk)
|
||||
: home_url('/sign/?tab=bind&obk=' . rawurlencode($obk));
|
||||
wp_safe_redirect($bind_url);
|
||||
exit;
|
||||
@@ -246,7 +246,7 @@ final class OAuthProxyClient {
|
||||
}
|
||||
|
||||
private function settings_url(): string {
|
||||
return function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('settings') : home_url('/');
|
||||
return function_exists('jio_get_user_center_url') ? jio_get_user_center_url('settings') : home_url('/');
|
||||
}
|
||||
|
||||
private function redirect_success(string $action, string $provider, string $target): void {
|
||||
@@ -260,7 +260,7 @@ final class OAuthProxyClient {
|
||||
private function redirect_error(string $code, string $provider = '', string $action = 'login'): void {
|
||||
$target = $action === 'bind' && is_user_logged_in()
|
||||
? $this->settings_url()
|
||||
: (function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url());
|
||||
: (function_exists('jio_get_login_url') ? jio_get_login_url() : wp_login_url());
|
||||
wp_safe_redirect(add_query_arg([
|
||||
'oauth_action' => 'error',
|
||||
'oauth_provider' => sanitize_key($provider),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -151,7 +151,7 @@ final class OAuthProxyProtocol {
|
||||
}
|
||||
ksort($fields, SORT_STRING);
|
||||
$payload = http_build_query($fields, '', '&', PHP_QUERY_RFC3986);
|
||||
$key = hash_hmac('sha256', 'aksrt-oauth-proxy-v2/' . $direction, $secret, true);
|
||||
$key = hash_hmac('sha256', 'jio-oauth-proxy-v2/' . $direction, $secret, true);
|
||||
return hash_hmac('sha256', $payload, $key);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -30,25 +30,25 @@ final class OAuthProxyServer {
|
||||
}
|
||||
|
||||
public function add_rewrite_rules(): void {
|
||||
add_rewrite_rule('^oauth/proxy/([a-z0-9_-]+)/?$', 'index.php?aksrt_proxy_provider=$matches[1]', 'top');
|
||||
add_rewrite_rule('^oauth/proxy/([a-z0-9_-]+)/callback/?$', 'index.php?aksrt_proxy_provider=$matches[1]&aksrt_proxy_server_callback=1', 'top');
|
||||
add_rewrite_rule('^oauth/proxy/([a-z0-9_-]+)/?$', 'index.php?jio_proxy_provider=$matches[1]', 'top');
|
||||
add_rewrite_rule('^oauth/proxy/([a-z0-9_-]+)/callback/?$', 'index.php?jio_proxy_provider=$matches[1]&jio_proxy_server_callback=1', 'top');
|
||||
add_filter('query_vars', static function (array $vars): array {
|
||||
$vars[] = 'aksrt_proxy_provider';
|
||||
$vars[] = 'aksrt_proxy_server_callback';
|
||||
$vars[] = 'jio_proxy_provider';
|
||||
$vars[] = 'jio_proxy_server_callback';
|
||||
return $vars;
|
||||
});
|
||||
}
|
||||
|
||||
public function maybe_flush_rewrite_rules(): void {
|
||||
$version = defined('AKSRT_VERSION') ? AKSRT_VERSION . ':oauth-proxy-server-v2' : 'oauth-proxy-server-v2';
|
||||
if (get_option('aksrt_oauth_proxy_server_routes_flushed') !== $version) {
|
||||
$version = defined('JIO_VERSION') ? JIO_VERSION . ':oauth-proxy-server-v2' : 'oauth-proxy-server-v2';
|
||||
if (get_option('jio_oauth_proxy_server_routes_flushed') !== $version) {
|
||||
flush_rewrite_rules(false);
|
||||
update_option('aksrt_oauth_proxy_server_routes_flushed', $version, false);
|
||||
update_option('jio_oauth_proxy_server_routes_flushed', $version, false);
|
||||
}
|
||||
}
|
||||
|
||||
public function handle_proxy_routes(): void {
|
||||
$provider = sanitize_key((string) get_query_var('aksrt_proxy_provider'));
|
||||
$provider = sanitize_key((string) get_query_var('jio_proxy_provider'));
|
||||
if ($provider === '') {
|
||||
return;
|
||||
}
|
||||
@@ -60,10 +60,10 @@ final class OAuthProxyServer {
|
||||
|| !OAuthProviderCatalog::is_direct($provider)
|
||||
|| !in_array($provider, OAuthProviderCatalog::proxy_server_providers(), true)
|
||||
) {
|
||||
wp_die(esc_html__('不支持的代理登录平台', 'aksrt'), '', ['response' => 403]);
|
||||
wp_die(esc_html__('不支持的代理登录平台', 'jio'), '', ['response' => 403]);
|
||||
}
|
||||
|
||||
if (get_query_var('aksrt_proxy_server_callback')) {
|
||||
if (get_query_var('jio_proxy_server_callback')) {
|
||||
$this->handle_proxy_callback($provider);
|
||||
}
|
||||
$this->handle_proxy_request($provider);
|
||||
@@ -87,13 +87,13 @@ final class OAuthProxyServer {
|
||||
|| !OAuthProxyProtocol::timestamp_valid($fields['ts'])
|
||||
|| !OAuthProxyProtocol::verify_request($fields, $secret, $signature)
|
||||
) {
|
||||
wp_die(esc_html__('代理请求验证失败', 'aksrt'), '', ['response' => 400]);
|
||||
wp_die(esc_html__('代理请求验证失败', 'jio'), '', ['response' => 400]);
|
||||
}
|
||||
|
||||
$replay_scope = 'proxy_server_request:' . $request_id;
|
||||
$lock = OAuthTransactionStore::acquire_lock($replay_scope, OAuthProxyProtocol::REPLAY_TTL);
|
||||
if ($lock === false) {
|
||||
wp_die(esc_html__('代理请求已使用', 'aksrt'), '', ['response' => 409]);
|
||||
wp_die(esc_html__('代理请求已使用', 'jio'), '', ['response' => 409]);
|
||||
}
|
||||
|
||||
$redirect_uri = home_url('/oauth/proxy/' . $provider . '/callback/');
|
||||
@@ -139,7 +139,7 @@ final class OAuthProxyServer {
|
||||
|| $agent_back_url === ''
|
||||
|| $redirect_uri === ''
|
||||
) {
|
||||
wp_die(esc_html__('代理回调状态无效', 'aksrt'), '', ['response' => 400]);
|
||||
wp_die(esc_html__('代理回调状态无效', 'jio'), '', ['response' => 400]);
|
||||
}
|
||||
|
||||
if (!empty($_GET['error'])) {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class OAuthTransactionStore {
|
||||
|
||||
private const PREFIX = 'aksrt_oauth_tx_';
|
||||
private const COOKIE = 'aksrt_oauth_browser';
|
||||
private const PREFIX = 'jio_oauth_tx_';
|
||||
private const COOKIE = 'jio_oauth_browser';
|
||||
private const LOCK_TTL = 30;
|
||||
|
||||
public static function browser_id(): string {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
|
||||
+27
-27
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -36,15 +36,15 @@ final class Router {
|
||||
}
|
||||
|
||||
public function register_query_vars(array $vars): array {
|
||||
$vars[] = 'aksrt_sign';
|
||||
$vars[] = 'aksrt_logout';
|
||||
$vars[] = 'jio_sign';
|
||||
$vars[] = 'jio_logout';
|
||||
return $vars;
|
||||
}
|
||||
|
||||
private function auth_route_map(): array {
|
||||
return [
|
||||
'sign' => 'index.php?aksrt_sign=1',
|
||||
'logout' => 'index.php?aksrt_logout=1',
|
||||
'sign' => 'index.php?jio_sign=1',
|
||||
'logout' => 'index.php?jio_logout=1',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ final class Router {
|
||||
}
|
||||
|
||||
public function handle_template_include(string $template): string {
|
||||
if (get_query_var('aksrt_sign')) {
|
||||
if (get_query_var('jio_sign')) {
|
||||
// §4.1 Global sign gate: when close_sign is active, block non-logged-in access to sign page
|
||||
if (class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::close_sign() && !is_user_logged_in()) {
|
||||
if (class_exists('\Jio\Settings\Settings') && \Jio\Settings\Settings::close_sign() && !is_user_logged_in()) {
|
||||
if (empty($_REQUEST['interim-login'])) {
|
||||
if (!headers_sent()) {
|
||||
wp_safe_redirect(home_url('/'), 302);
|
||||
@@ -66,7 +66,7 @@ final class Router {
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = aksrt_locate_template_file('templates/pages/page-sign.php');
|
||||
$tpl = jio_locate_template_file('templates/pages/page-sign.php');
|
||||
if ($tpl) {
|
||||
return $tpl;
|
||||
}
|
||||
@@ -76,10 +76,10 @@ final class Router {
|
||||
}
|
||||
|
||||
public function maybe_flush_rewrite_rules(): void {
|
||||
$rewrite_version = AKSRT_VERSION . ':sign-router-v3-single-route';
|
||||
if (get_option('aksrt_auth_routes_flushed') !== $rewrite_version) {
|
||||
$rewrite_version = JIO_VERSION . ':sign-router-v3-single-route';
|
||||
if (get_option('jio_auth_routes_flushed') !== $rewrite_version) {
|
||||
flush_rewrite_rules(false);
|
||||
update_option('aksrt_auth_routes_flushed', $rewrite_version);
|
||||
update_option('jio_auth_routes_flushed', $rewrite_version);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ final class Router {
|
||||
return $login_url;
|
||||
}
|
||||
|
||||
$custom_login_url = aksrt_get_login_url();
|
||||
$custom_login_url = jio_get_login_url();
|
||||
if ($redirect !== '') {
|
||||
$custom_login_url = add_query_arg('redirect_to', urlencode($redirect), $custom_login_url);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ final class Router {
|
||||
}
|
||||
|
||||
public function filter_lostpassword_url(string $lostpassword_url, string $redirect): string {
|
||||
$custom_url = aksrt_get_reset_password_url();
|
||||
$custom_url = jio_get_reset_password_url();
|
||||
if ($redirect !== '') {
|
||||
$custom_url = add_query_arg('redirect_to', urlencode($redirect), $custom_url);
|
||||
}
|
||||
@@ -108,22 +108,22 @@ final class Router {
|
||||
}
|
||||
|
||||
public function filter_register_url(string $register_url): string {
|
||||
return aksrt_get_register_url();
|
||||
return jio_get_register_url();
|
||||
}
|
||||
|
||||
public function filter_logout_url(string $logout_url, string $redirect): string {
|
||||
return aksrt_get_logout_url($redirect ?: home_url('/'));
|
||||
return jio_get_logout_url($redirect ?: home_url('/'));
|
||||
}
|
||||
|
||||
public function redirect_native_login(): void {
|
||||
if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::replace_wp_login()) {
|
||||
if (class_exists('\Jio\Settings\Settings') && !\Jio\Settings\Settings::replace_wp_login()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// §4.1 Emergency bypass key (admin_sign_key): allow wp-login.php direct access when key matches
|
||||
if (isset($_GET['aksrt_bypass'])) {
|
||||
$key = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::admin_sign_key() : '';
|
||||
if ($key !== '' && hash_equals($key, (string) $_GET['aksrt_bypass'])) {
|
||||
if (isset($_GET['jio_bypass'])) {
|
||||
$key = class_exists('\Jio\Settings\Settings') ? \Jio\Settings\Settings::admin_sign_key() : '';
|
||||
if ($key !== '' && hash_equals($key, (string) $_GET['jio_bypass'])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -133,23 +133,23 @@ final class Router {
|
||||
$reauth = !empty($_REQUEST['reauth']);
|
||||
|
||||
if ($action === 'logout') {
|
||||
wp_safe_redirect(aksrt_get_logout_url($redirect_to ?: home_url('/')), 302);
|
||||
wp_safe_redirect(jio_get_logout_url($redirect_to ?: home_url('/')), 302);
|
||||
exit;
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'register':
|
||||
$target = aksrt_get_sign_page_url('signup');
|
||||
$target = jio_get_sign_page_url('signup');
|
||||
break;
|
||||
case 'lostpassword':
|
||||
$target = aksrt_get_sign_page_url('resetpassword');
|
||||
$target = jio_get_sign_page_url('resetpassword');
|
||||
break;
|
||||
case 'rp':
|
||||
case 'resetpass':
|
||||
$target = aksrt_get_sign_page_url('resetpassword');
|
||||
$target = jio_get_sign_page_url('resetpassword');
|
||||
break;
|
||||
default:
|
||||
$target = aksrt_get_sign_page_url('signin');
|
||||
$target = jio_get_sign_page_url('signin');
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -185,11 +185,11 @@ final class Router {
|
||||
$nonce = isset($_GET['_wpnonce']) ? sanitize_text_field((string) $_GET['_wpnonce']) : '';
|
||||
// Accept theme nonce and core log-out nonce (wp_logout_url default).
|
||||
$nonce_ok = ($nonce !== '' && (
|
||||
wp_verify_nonce($nonce, 'aksrt-logout')
|
||||
wp_verify_nonce($nonce, 'jio-logout')
|
||||
|| wp_verify_nonce($nonce, 'log-out')
|
||||
));
|
||||
if (!$nonce_ok) {
|
||||
wp_die(esc_html__('退出登录请求无效,请重试。', 'aksrt'), esc_html__('退出登录', 'aksrt'), ['response' => 403]);
|
||||
wp_die(esc_html__('退出登录请求无效,请重试。', 'jio'), esc_html__('退出登录', 'jio'), ['response' => 403]);
|
||||
}
|
||||
|
||||
$redirect_to = isset($_GET['redirect_to']) ? wp_unslash((string) $_GET['redirect_to']) : home_url('/');
|
||||
|
||||
+14
-14
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -12,7 +12,7 @@ final class Service {
|
||||
use ServicePart1b;
|
||||
|
||||
|
||||
public const EMAIL_VERIFIED_META = 'aksrt_email_verified';
|
||||
public const EMAIL_VERIFIED_META = 'jio_email_verified';
|
||||
|
||||
public static function get_oauth_bind_context(string $obk): ?array {
|
||||
$obk = sanitize_text_field($obk);
|
||||
@@ -45,9 +45,9 @@ final class Service {
|
||||
public static function resolve_email_to_username(string $login): string {
|
||||
$login = trim($login);
|
||||
if (
|
||||
\AKSRT\Sms\SMS::is_phonenumber($login)
|
||||
&& class_exists('\AKSRT\Settings\Settings')
|
||||
&& \AKSRT\Settings\Settings::signin_phone_enabled()
|
||||
\Jio\Sms\SMS::is_phonenumber($login)
|
||||
&& class_exists('\Jio\Settings\Settings')
|
||||
&& \Jio\Settings\Settings::signin_phone_enabled()
|
||||
) {
|
||||
$users = get_users([
|
||||
'meta_key' => 'phone_number',
|
||||
@@ -71,7 +71,7 @@ final class Service {
|
||||
$msg_lower = wp_strip_all_tags(strtolower($raw_message));
|
||||
|
||||
if (false !== strpos($msg_lower, 'incorrect password') || false !== strpos($msg_lower, '密码不正确')) {
|
||||
return __('用户名或密码错误,请重新输入', 'aksrt');
|
||||
return __('用户名或密码错误,请重新输入', 'jio');
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -79,7 +79,7 @@ final class Service {
|
||||
false !== strpos($msg_lower, 'invalid email') ||
|
||||
false !== strpos($msg_lower, '<strong>error</strong>: 该用户不存在')
|
||||
) {
|
||||
return __('账号不存在,请检查输入或先注册', 'aksrt');
|
||||
return __('账号不存在,请检查输入或先注册', 'jio');
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -87,10 +87,10 @@ final class Service {
|
||||
false !== strpos($msg_lower, 'empty username') ||
|
||||
false !== strpos($msg_lower, 'empty')
|
||||
) {
|
||||
return __('请填写用户名和密码', 'aksrt');
|
||||
return __('请填写用户名和密码', 'jio');
|
||||
}
|
||||
|
||||
return sprintf(__('登录失败:%s', 'aksrt'), wp_strip_all_tags($raw_message));
|
||||
return sprintf(__('登录失败:%s', 'jio'), wp_strip_all_tags($raw_message));
|
||||
}
|
||||
|
||||
public static function mark_verified_email(int $user_id): void {
|
||||
@@ -99,19 +99,19 @@ final class Service {
|
||||
|
||||
public static function validate_password(string $password, string $confirm = '') {
|
||||
if ($password === '') {
|
||||
return __('请输入密码', 'aksrt');
|
||||
return __('请输入密码', 'jio');
|
||||
}
|
||||
|
||||
if (mb_strlen($password) < 6) {
|
||||
return __('密码长度至少6位', 'aksrt');
|
||||
return __('密码长度至少6位', 'jio');
|
||||
}
|
||||
|
||||
if (mb_strlen($password) > 128) {
|
||||
return __('密码过长,请控制在128位以内', 'aksrt');
|
||||
return __('密码过长,请控制在128位以内', 'jio');
|
||||
}
|
||||
|
||||
if ($confirm !== '' && $password !== $confirm) {
|
||||
return __('两次输入的密码不一致', 'aksrt');
|
||||
return __('两次输入的密码不一致', 'jio');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
+46
-46
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -17,44 +17,44 @@ trait ServicePart1a {
|
||||
$confirm = (string) ($post['user_pass_confirm'] ?? '');
|
||||
|
||||
if (
|
||||
class_exists('\AKSRT\Settings\Settings')
|
||||
&& \AKSRT\Settings\Settings::signup_verification_enabled()
|
||||
class_exists('\Jio\Settings\Settings')
|
||||
&& \Jio\Settings\Settings::signup_verification_enabled()
|
||||
&& !$verification_completed
|
||||
) {
|
||||
return ['success' => false, 'error' => __('请先完成邮箱或手机验证', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请先完成邮箱或手机验证', 'jio')];
|
||||
}
|
||||
|
||||
$agreement = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::user_agreement_settings()
|
||||
$agreement = class_exists('\Jio\Settings\Settings')
|
||||
? \Jio\Settings\Settings::user_agreement_settings()
|
||||
: ['enabled' => false, 'privacy' => false, 'required' => false];
|
||||
if ((!empty($agreement['enabled']) || !empty($agreement['privacy'])) && !empty($agreement['required']) && empty($post['agree_terms'])) {
|
||||
return ['success' => false, 'error' => __('请先同意服务条款', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请先同意服务条款', 'jio')];
|
||||
}
|
||||
|
||||
if (empty($user_login) || !validate_username($user_login)) {
|
||||
return ['success' => false, 'error' => __('请输入有效的用户名', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请输入有效的用户名', 'jio')];
|
||||
}
|
||||
|
||||
if (mb_strlen($user_login) < 3 || mb_strlen($user_login) > 60) {
|
||||
return ['success' => false, 'error' => __('用户名长度需在 3-60 个字符之间', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('用户名长度需在 3-60 个字符之间', 'jio')];
|
||||
}
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
foreach (\AKSRT\Settings\Settings::nickname_blacklist() as $keyword) {
|
||||
if (class_exists('\Jio\Settings\Settings')) {
|
||||
foreach (\Jio\Settings\Settings::nickname_blacklist() as $keyword) {
|
||||
if ($keyword !== '' && mb_stripos($user_login, $keyword) !== false) {
|
||||
return ['success' => false, 'error' => __('用户名包含禁止使用的关键词', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('用户名包含禁止使用的关键词', 'jio')];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (username_exists($user_login)) {
|
||||
return ['success' => false, 'error' => __('该用户名已被使用', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('该用户名已被使用', 'jio')];
|
||||
}
|
||||
|
||||
if (empty($user_email) || !is_email($user_email)) {
|
||||
return ['success' => false, 'error' => __('请输入有效的邮箱地址', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请输入有效的邮箱地址', 'jio')];
|
||||
}
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
$email_limit = \AKSRT\Settings\Settings::email_limit();
|
||||
if (class_exists('\Jio\Settings\Settings')) {
|
||||
$email_limit = \Jio\Settings\Settings::email_limit();
|
||||
$matches = false;
|
||||
foreach ((array) ($email_limit['domains'] ?? []) as $keyword) {
|
||||
if ($keyword !== '' && stripos($user_email, (string) $keyword) !== false) {
|
||||
@@ -63,18 +63,18 @@ trait ServicePart1a {
|
||||
}
|
||||
}
|
||||
if ((($email_limit['type'] ?? 'not') === 'not' && $matches) || (($email_limit['type'] ?? 'not') === 'allow' && !empty($email_limit['domains']) && !$matches)) {
|
||||
return ['success' => false, 'error' => __('该邮箱不符合本站注册规则', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('该邮箱不符合本站注册规则', 'jio')];
|
||||
}
|
||||
}
|
||||
|
||||
if (email_exists($user_email)) {
|
||||
return ['success' => false, 'error' => __('该邮箱已被其他账号使用', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('该邮箱已被其他账号使用', 'jio')];
|
||||
}
|
||||
|
||||
if (
|
||||
class_exists('\AKSRT\Settings\Settings')
|
||||
&& \AKSRT\Settings\Settings::signup_verification_enabled()
|
||||
&& \AKSRT\Settings\Settings::signup_omit_password_confirmation()
|
||||
class_exists('\Jio\Settings\Settings')
|
||||
&& \Jio\Settings\Settings::signup_verification_enabled()
|
||||
&& \Jio\Settings\Settings::signup_omit_password_confirmation()
|
||||
) {
|
||||
$confirm = $password;
|
||||
}
|
||||
@@ -83,14 +83,14 @@ trait ServicePart1a {
|
||||
return ['success' => false, 'error' => $password_check];
|
||||
}
|
||||
|
||||
$ref_service = class_exists('\AKSRT\Payment\ReferralAttribution')
|
||||
? \AKSRT\Payment\ReferralAttribution::get_instance()
|
||||
$ref_service = class_exists('\Jio\Payment\ReferralAttribution')
|
||||
? \Jio\Payment\ReferralAttribution::get_instance()
|
||||
: null;
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
$registration = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_referral_registration_settings()
|
||||
$registration = class_exists('\Jio\Settings\Settings')
|
||||
? \Jio\Settings\Settings::get_referral_registration_settings()
|
||||
: ['enabled' => false, 'register_field' => 'hidden', 'reject_invalid' => true];
|
||||
$submitted_ref = isset($post['ref']) ? sanitize_key((string) wp_unslash($post['ref'])) : '';
|
||||
$field_mode = !empty($registration['enabled'])
|
||||
@@ -106,45 +106,45 @@ trait ServicePart1a {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => __('请填写推广码', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请填写推广码', 'jio')];
|
||||
}
|
||||
if (!empty($registration['reject_invalid'])) {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'jio')];
|
||||
}
|
||||
}
|
||||
if ($submitted_ref !== '' && empty($ref_context['valid']) && !empty($registration['reject_invalid'])) {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'jio')];
|
||||
}
|
||||
|
||||
$invite_service = class_exists('\AKSRT\Payment\InviteCode')
|
||||
? \AKSRT\Payment\InviteCode::get_instance()
|
||||
$invite_service = class_exists('\Jio\Payment\InviteCode')
|
||||
? \Jio\Payment\InviteCode::get_instance()
|
||||
: null;
|
||||
if ($invite_service) {
|
||||
$invite_service->clear_registration_context();
|
||||
$invite_mode = $invite_service->field_mode();
|
||||
$submitted_invite = isset($post['invite_code']) ? sanitize_key((string) wp_unslash($post['invite_code'])) : '';
|
||||
if ($invite_mode === 'required' && $submitted_invite === '') {
|
||||
return ['success' => false, 'error' => __('请填写邀请码', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请填写邀请码', 'jio')];
|
||||
}
|
||||
if ($submitted_invite !== '') {
|
||||
if (!$invite_service->is_valid($submitted_invite)) {
|
||||
return ['success' => false, 'error' => __('邀请码无效或已用完,请检查后重试', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('邀请码无效或已用完,请检查后重试', 'jio')];
|
||||
}
|
||||
$invite_service->set_registration_context($submitted_invite);
|
||||
}
|
||||
}
|
||||
|
||||
// [防刷机制]注册限制(后台「扩展&增强 → 网站安全」),按 IP 判断且不豁免管理员。
|
||||
if (class_exists('\AKSRT\Extensions\SecurityHardening')) {
|
||||
$security = \AKSRT\Settings\ExtensionRuntime::get_security_settings();
|
||||
$brush_ip = function_exists('aksrt_get_client_ip') ? aksrt_get_client_ip() : (string) ($_SERVER['REMOTE_ADDR'] ?? '');
|
||||
$brush = \AKSRT\Extensions\SecurityHardening::brush_allow('register', $brush_ip, (int) $security['security_brush_register_10min'], (int) $security['security_brush_register_day']);
|
||||
if (class_exists('\Jio\Extensions\SecurityHardening')) {
|
||||
$security = \Jio\Settings\ExtensionRuntime::get_security_settings();
|
||||
$brush_ip = function_exists('jio_get_client_ip') ? jio_get_client_ip() : (string) ($_SERVER['REMOTE_ADDR'] ?? '');
|
||||
$brush = \Jio\Extensions\SecurityHardening::brush_allow('register', $brush_ip, (int) $security['security_brush_register_10min'], (int) $security['security_brush_register_day']);
|
||||
if ($brush !== true) {
|
||||
return ['success' => false, 'error' => (string) $brush];
|
||||
}
|
||||
@@ -164,13 +164,13 @@ trait ServicePart1a {
|
||||
|
||||
$user = get_userdata($user_id);
|
||||
if (!$user || is_wp_error($user)) {
|
||||
return ['success' => false, 'error' => __('注册成功,但读取用户信息失败,请联系管理员', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('注册成功,但读取用户信息失败,请联系管理员', 'jio')];
|
||||
}
|
||||
if ($user instanceof \WP_User && is_email($user->user_email)) {
|
||||
\AKSRT\Settings\Mail::send_event_email('reg_success', $user->user_email, [
|
||||
\Jio\Settings\Mail::send_event_email('reg_success', $user->user_email, [
|
||||
'{username}' => $user->display_name,
|
||||
'{site_name}' => get_bloginfo('name'),
|
||||
'{url}' => function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/'),
|
||||
'{url}' => function_exists('jio_get_user_center_url') ? jio_get_user_center_url() : home_url('/'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -178,8 +178,8 @@ trait ServicePart1a {
|
||||
if (
|
||||
!$defer_login
|
||||
&& $verification_completed
|
||||
&& class_exists('\AKSRT\Settings\Settings')
|
||||
&& \AKSRT\Settings\Settings::signup_verification_enabled()
|
||||
&& class_exists('\Jio\Settings\Settings')
|
||||
&& \Jio\Settings\Settings::signup_verification_enabled()
|
||||
) {
|
||||
self::mark_email_verified($user_id);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ trait ServicePart1a {
|
||||
|
||||
public static function finalize_oauth_binding(int $user_id, array $oauth_data, string $obk = '') {
|
||||
if ($user_id <= 0 || $obk === '') {
|
||||
return new \WP_Error('oauth_binding_invalid', __('绑定会话无效', 'aksrt'));
|
||||
return new \WP_Error('oauth_binding_invalid', __('绑定会话无效', 'jio'));
|
||||
}
|
||||
|
||||
$payload = $oauth_data;
|
||||
@@ -207,14 +207,14 @@ trait ServicePart1a {
|
||||
$row = OAuthTransactionStore::claim(sanitize_text_field($obk), 'obk');
|
||||
$payload = is_array($row['payload'] ?? null) ? $row['payload'] : [];
|
||||
if (!$row || $payload === []) {
|
||||
return new \WP_Error('oauth_binding_consumed', __('绑定会话已过期或已使用,请重新授权', 'aksrt'));
|
||||
return new \WP_Error('oauth_binding_consumed', __('绑定会话已过期或已使用,请重新授权', 'jio'));
|
||||
}
|
||||
}
|
||||
unset($payload['_oauth_claimed']);
|
||||
$provider = sanitize_key((string) ($payload['provider'] ?? ''));
|
||||
$identity = is_array($payload['user_data'] ?? null) ? $payload['user_data'] : [];
|
||||
if ($provider === '' || empty($identity['provider_id'])) {
|
||||
return new \WP_Error('oauth_binding_invalid', __('第三方账号信息无效', 'aksrt'));
|
||||
return new \WP_Error('oauth_binding_invalid', __('第三方账号信息无效', 'jio'));
|
||||
}
|
||||
return OAuthAccountService::bind($user_id, $provider, $identity);
|
||||
}
|
||||
@@ -222,7 +222,7 @@ trait ServicePart1a {
|
||||
|
||||
private static function mark_email_verified(int $user_id): void {
|
||||
update_user_meta($user_id, self::EMAIL_VERIFIED_META, '1');
|
||||
do_action('aksrt_email_verified', $user_id);
|
||||
do_action('jio_email_verified', $user_id);
|
||||
}
|
||||
|
||||
}
|
||||
+42
-42
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -21,30 +21,30 @@ trait ServicePart1b {
|
||||
$confirm = (string) ($post['password_confirm'] ?? '');
|
||||
$username = sanitize_user(wp_unslash((string) ($post['user_login'] ?? '')), true);
|
||||
|
||||
if (!\AKSRT\Sms\SMS::is_phonenumber($phone)) {
|
||||
return ['success' => false, 'error' => __('手机号格式不正确', 'aksrt')];
|
||||
if (!\Jio\Sms\SMS::is_phonenumber($phone)) {
|
||||
return ['success' => false, 'error' => __('手机号格式不正确', 'jio')];
|
||||
}
|
||||
if (!$verification_completed) {
|
||||
return ['success' => false, 'error' => __('请先完成手机验证', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请先完成手机验证', 'jio')];
|
||||
}
|
||||
if ($username === '' || !validate_username($username) || mb_strlen($username) < 3 || mb_strlen($username) > 60) {
|
||||
return ['success' => false, 'error' => __('请输入 3-60 个字符的有效用户名', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请输入 3-60 个字符的有效用户名', 'jio')];
|
||||
}
|
||||
if (username_exists($username)) {
|
||||
return ['success' => false, 'error' => __('该用户名已被使用', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('该用户名已被使用', 'jio')];
|
||||
}
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
foreach (\AKSRT\Settings\Settings::nickname_blacklist() as $keyword) {
|
||||
if (class_exists('\Jio\Settings\Settings')) {
|
||||
foreach (\Jio\Settings\Settings::nickname_blacklist() as $keyword) {
|
||||
if ($keyword !== '' && mb_stripos($username, $keyword) !== false) {
|
||||
return ['success' => false, 'error' => __('用户名包含禁止使用的关键词', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('用户名包含禁止使用的关键词', 'jio')];
|
||||
}
|
||||
}
|
||||
if (\AKSRT\Settings\Settings::signup_omit_password_confirmation()) {
|
||||
if (\Jio\Settings\Settings::signup_omit_password_confirmation()) {
|
||||
$confirm = $pass;
|
||||
}
|
||||
$agreement = \AKSRT\Settings\Settings::user_agreement_settings();
|
||||
$agreement = \Jio\Settings\Settings::user_agreement_settings();
|
||||
if ((!empty($agreement['enabled']) || !empty($agreement['privacy'])) && !empty($agreement['required']) && empty($post['agree_terms'])) {
|
||||
return ['success' => false, 'error' => __('请先同意服务条款', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请先同意服务条款', 'jio')];
|
||||
}
|
||||
}
|
||||
$password_check = self::validate_password($pass, $confirm);
|
||||
@@ -55,17 +55,17 @@ trait ServicePart1b {
|
||||
// 检查手机号是否已注册
|
||||
$existing_user = self::get_user_by_phone($phone);
|
||||
if ($existing_user) {
|
||||
return ['success' => false, 'error' => __('该手机号已注册', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('该手机号已注册', 'jio')];
|
||||
}
|
||||
|
||||
$ref_service = class_exists('\AKSRT\Payment\ReferralAttribution')
|
||||
? \AKSRT\Payment\ReferralAttribution::get_instance()
|
||||
$ref_service = class_exists('\Jio\Payment\ReferralAttribution')
|
||||
? \Jio\Payment\ReferralAttribution::get_instance()
|
||||
: null;
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
$registration = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_referral_registration_settings()
|
||||
$registration = class_exists('\Jio\Settings\Settings')
|
||||
? \Jio\Settings\Settings::get_referral_registration_settings()
|
||||
: ['enabled' => false, 'register_field' => 'hidden', 'reject_invalid' => true];
|
||||
$submitted_ref = sanitize_key((string) ($post['ref'] ?? ''));
|
||||
$field_mode = !empty($registration['enabled'])
|
||||
@@ -80,45 +80,45 @@ trait ServicePart1b {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => __('请填写推广码', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请填写推广码', 'jio')];
|
||||
}
|
||||
if (!empty($registration['reject_invalid'])) {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'jio')];
|
||||
}
|
||||
}
|
||||
if ($submitted_ref !== '' && empty($ref_context['valid']) && !empty($registration['reject_invalid'])) {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'jio')];
|
||||
}
|
||||
|
||||
$invite_service = class_exists('\AKSRT\Payment\InviteCode')
|
||||
? \AKSRT\Payment\InviteCode::get_instance()
|
||||
$invite_service = class_exists('\Jio\Payment\InviteCode')
|
||||
? \Jio\Payment\InviteCode::get_instance()
|
||||
: null;
|
||||
if ($invite_service) {
|
||||
$invite_service->clear_registration_context();
|
||||
$invite_mode = $invite_service->field_mode();
|
||||
$submitted_invite = sanitize_key((string) ($post['invite_code'] ?? ''));
|
||||
if ($invite_mode === 'required' && $submitted_invite === '') {
|
||||
return ['success' => false, 'error' => __('请填写邀请码', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请填写邀请码', 'jio')];
|
||||
}
|
||||
if ($submitted_invite !== '') {
|
||||
if (!$invite_service->is_valid($submitted_invite)) {
|
||||
return ['success' => false, 'error' => __('邀请码无效或已用完,请检查后重试', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('邀请码无效或已用完,请检查后重试', 'jio')];
|
||||
}
|
||||
$invite_service->set_registration_context($submitted_invite);
|
||||
}
|
||||
}
|
||||
|
||||
// [防刷机制]注册限制(后台「扩展&增强 → 网站安全」),按 IP 判断且不豁免管理员。
|
||||
if (class_exists('\AKSRT\Extensions\SecurityHardening')) {
|
||||
$security = \AKSRT\Settings\ExtensionRuntime::get_security_settings();
|
||||
$brush_ip = function_exists('aksrt_get_client_ip') ? aksrt_get_client_ip() : (string) ($_SERVER['REMOTE_ADDR'] ?? '');
|
||||
$brush = \AKSRT\Extensions\SecurityHardening::brush_allow('register', $brush_ip, (int) $security['security_brush_register_10min'], (int) $security['security_brush_register_day']);
|
||||
if (class_exists('\Jio\Extensions\SecurityHardening')) {
|
||||
$security = \Jio\Settings\ExtensionRuntime::get_security_settings();
|
||||
$brush_ip = function_exists('jio_get_client_ip') ? jio_get_client_ip() : (string) ($_SERVER['REMOTE_ADDR'] ?? '');
|
||||
$brush = \Jio\Extensions\SecurityHardening::brush_allow('register', $brush_ip, (int) $security['security_brush_register_10min'], (int) $security['security_brush_register_day']);
|
||||
if ($brush !== true) {
|
||||
return ['success' => false, 'error' => (string) $brush];
|
||||
}
|
||||
@@ -138,7 +138,7 @@ trait ServicePart1b {
|
||||
|
||||
// 绑定手机号
|
||||
update_user_meta($user_id, 'phone_number', $phone);
|
||||
update_user_meta($user_id, 'aksrt_phone_verified', '1');
|
||||
update_user_meta($user_id, 'jio_phone_verified', '1');
|
||||
|
||||
// 自动登录
|
||||
$user = get_userdata($user_id);
|
||||
@@ -150,15 +150,15 @@ trait ServicePart1b {
|
||||
}
|
||||
}
|
||||
|
||||
$redirect = function_exists('aksrt_get_user_center_url')
|
||||
? aksrt_get_user_center_url()
|
||||
$redirect = function_exists('jio_get_user_center_url')
|
||||
? jio_get_user_center_url()
|
||||
: home_url('/');
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'user_id' => $user_id,
|
||||
'redirect' => $redirect,
|
||||
'message' => __('注册成功', 'aksrt'),
|
||||
'message' => __('注册成功', 'jio'),
|
||||
'notice' => $ref_service ? $ref_service->take_registration_notice() : '',
|
||||
];
|
||||
}
|
||||
@@ -171,35 +171,35 @@ trait ServicePart1b {
|
||||
*/
|
||||
public static function bind_phone(array $post, bool $verification_completed = false): array {
|
||||
if (!is_user_logged_in()) {
|
||||
return ['success' => false, 'error' => __('请先登录', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('请先登录', 'jio')];
|
||||
}
|
||||
|
||||
$phone = sanitize_text_field((string) ($post['phone'] ?? ''));
|
||||
if (!\AKSRT\Sms\SMS::is_phonenumber($phone)) {
|
||||
return ['success' => false, 'error' => __('手机号格式不正确', 'aksrt')];
|
||||
if (!\Jio\Sms\SMS::is_phonenumber($phone)) {
|
||||
return ['success' => false, 'error' => __('手机号格式不正确', 'jio')];
|
||||
}
|
||||
|
||||
if (!$verification_completed) {
|
||||
return ['success' => false, 'error' => __('验证码错误或已过期', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('验证码错误或已过期', 'jio')];
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$existing = self::get_user_by_phone($phone);
|
||||
if ($existing && (int) $existing->ID !== $user_id) {
|
||||
return ['success' => false, 'error' => __('该手机号已被其他账号绑定', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('该手机号已被其他账号绑定', 'jio')];
|
||||
}
|
||||
if ($existing && (int) $existing->ID === $user_id) {
|
||||
return ['success' => false, 'error' => __('手机号不能与当前绑定号码相同', 'aksrt')];
|
||||
return ['success' => false, 'error' => __('手机号不能与当前绑定号码相同', 'jio')];
|
||||
}
|
||||
|
||||
$old_phone = (string) get_user_meta($user_id, 'phone_number', true);
|
||||
update_user_meta($user_id, 'phone_number', $phone);
|
||||
update_user_meta($user_id, 'aksrt_phone_verified', '1');
|
||||
do_action('aksrt_user_phone_changed', $user_id, $phone, $old_phone);
|
||||
update_user_meta($user_id, 'jio_phone_verified', '1');
|
||||
do_action('jio_user_phone_changed', $user_id, $phone, $old_phone);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => $old_phone !== '' ? __('手机号修改成功', 'aksrt') : __('手机号绑定成功', 'aksrt'),
|
||||
'message' => $old_phone !== '' ? __('手机号修改成功', 'jio') : __('手机号绑定成功', 'jio'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+47
-47
@@ -2,21 +2,21 @@
|
||||
/**
|
||||
* WeChat Official Account QR and verification-code authentication.
|
||||
*
|
||||
* @package AKSRT
|
||||
* @package Jio
|
||||
*/
|
||||
|
||||
namespace AKSRT\Auth;
|
||||
namespace Jio\Auth;
|
||||
|
||||
use AKSRT\Settings\Settings;
|
||||
use Jio\Settings\Settings;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class WeixinGzh {
|
||||
|
||||
private const ACCESS_OPTION = 'aksrt_weixingzh_access_token';
|
||||
private const SCENE_OPTION_PREFIX = 'aksrt_weixingzh_scene_';
|
||||
private const CODE_OPTION_PREFIX = 'aksrt_weixingzh_code_';
|
||||
private const DEDUPE_OPTION_PREFIX = 'aksrt_weixingzh_event_';
|
||||
private const ACCESS_OPTION = 'jio_weixingzh_access_token';
|
||||
private const SCENE_OPTION_PREFIX = 'jio_weixingzh_scene_';
|
||||
private const CODE_OPTION_PREFIX = 'jio_weixingzh_code_';
|
||||
private const DEDUPE_OPTION_PREFIX = 'jio_weixingzh_event_';
|
||||
private const SCAN_KIND = 'weixingzh_scan';
|
||||
private const CODE_KIND = 'weixingzh_code';
|
||||
private const SCAN_TTL = 5 * MINUTE_IN_SECONDS;
|
||||
@@ -42,17 +42,17 @@ final class WeixinGzh {
|
||||
}
|
||||
|
||||
public function register_routes(): void {
|
||||
register_rest_route('aksrt/v1', '/auth/qrcode-login', [
|
||||
register_rest_route('jio/v1', '/auth/qrcode-login', [
|
||||
'methods' => ['GET', 'POST'],
|
||||
'callback' => [$this, 'rest_qrcode_login'],
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
register_rest_route('aksrt/v1', '/auth/check-qrcode-login', [
|
||||
register_rest_route('jio/v1', '/auth/check-qrcode-login', [
|
||||
'methods' => ['GET', 'POST'],
|
||||
'callback' => [$this, 'rest_check_qrcode_login'],
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
register_rest_route('aksrt/v1', '/auth/weixingzh-code', [
|
||||
register_rest_route('jio/v1', '/auth/weixingzh-code', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'rest_code_login'],
|
||||
'permission_callback' => '__return_true',
|
||||
@@ -96,7 +96,7 @@ final class WeixinGzh {
|
||||
return $limited;
|
||||
}
|
||||
if (!self::is_enabled()) {
|
||||
return $this->error_response(__('微信公众号登录未开启或配置不完整', 'aksrt'), 400);
|
||||
return $this->error_response(__('微信公众号登录未开启或配置不完整', 'jio'), 400);
|
||||
}
|
||||
$context = $this->request_context($request);
|
||||
if (is_wp_error($context)) {
|
||||
@@ -108,7 +108,7 @@ final class WeixinGzh {
|
||||
$data = $this->request_data($request);
|
||||
$bind_pass = sanitize_text_field((string) ($data['bind_pass'] ?? ''));
|
||||
if (!OAuth::validate_bind_pass($bind_pass, 'weixingzh', $context['user_id'], false)) {
|
||||
return $this->error_response(__('请先完成人机验证后再绑定', 'aksrt'), 403);
|
||||
return $this->error_response(__('请先完成人机验证后再绑定', 'jio'), 403);
|
||||
}
|
||||
$context['bind_pass'] = $bind_pass;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ final class WeixinGzh {
|
||||
|
||||
$appid = trim((string) ($config['appid'] ?? ''));
|
||||
$secret = trim((string) ($config['appsecret'] ?? ''));
|
||||
$scene = 'aksrt_' . rtrim(strtr(base64_encode(random_bytes(18)), '+/', '-_'), '=');
|
||||
$scene = 'jio_' . rtrim(strtr(base64_encode(random_bytes(18)), '+/', '-_'), '=');
|
||||
$transaction = '';
|
||||
try {
|
||||
$transaction = OAuthTransactionStore::issue(self::SCAN_KIND, [
|
||||
@@ -147,8 +147,8 @@ final class WeixinGzh {
|
||||
throw new \RuntimeException((string) ($created['errmsg'] ?? 'qrcode_create_failed'));
|
||||
}
|
||||
$image = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . rawurlencode((string) $created['ticket']);
|
||||
$html = '<img class="signin-qrcode-img" src="' . esc_url($image) . '" alt="' . esc_attr__('微信公众号扫码登录二维码', 'aksrt') . '" style="width:160px;height:160px;" />';
|
||||
$html .= '<p class="text-center mt10 em09 muted-2-color"><i class="fa fab fa-weixin c-green"></i> ' . esc_html__('微信扫码登录', 'aksrt') . '</p>';
|
||||
$html = '<img class="signin-qrcode-img" src="' . esc_url($image) . '" alt="' . esc_attr__('微信公众号扫码登录二维码', 'jio') . '" style="width:160px;height:160px;" />';
|
||||
$html .= '<p class="text-center mt10 em09 muted-2-color"><i class="fa fab fa-weixin c-green"></i> ' . esc_html__('微信扫码登录', 'jio') . '</p>';
|
||||
return new \WP_REST_Response([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
@@ -164,7 +164,7 @@ final class WeixinGzh {
|
||||
OAuthTransactionStore::delete($transaction);
|
||||
$this->delete_scene_mapping($scene, $transaction);
|
||||
}
|
||||
return $this->error_response(__('创建微信登录二维码失败,请稍后重试', 'aksrt'), 502);
|
||||
return $this->error_response(__('创建微信登录二维码失败,请稍后重试', 'jio'), 502);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,12 +174,12 @@ final class WeixinGzh {
|
||||
return $limited;
|
||||
}
|
||||
if (!self::is_enabled()) {
|
||||
return $this->error_response(__('微信公众号登录未开启或配置不完整', 'aksrt'), 400);
|
||||
return $this->error_response(__('微信公众号登录未开启或配置不完整', 'jio'), 400);
|
||||
}
|
||||
$data = $this->request_data($request);
|
||||
$token = sanitize_text_field((string) ($data['token'] ?? ''));
|
||||
if ($token === '') {
|
||||
return $this->error_response(__('缺少 token', 'aksrt'), 400);
|
||||
return $this->error_response(__('缺少 token', 'jio'), 400);
|
||||
}
|
||||
$row = OAuthTransactionStore::peek($token, self::SCAN_KIND, true);
|
||||
if (!$row) {
|
||||
@@ -194,7 +194,7 @@ final class WeixinGzh {
|
||||
], 200);
|
||||
}
|
||||
if (!$this->binding_user_matches($payload)) {
|
||||
return $this->error_response(__('绑定会话与当前用户不匹配', 'aksrt'), 403);
|
||||
return $this->error_response(__('绑定会话与当前用户不匹配', 'jio'), 403);
|
||||
}
|
||||
$claimed = OAuthTransactionStore::claim($token, self::SCAN_KIND, true);
|
||||
if (!$claimed) {
|
||||
@@ -210,12 +210,12 @@ final class WeixinGzh {
|
||||
return $limited;
|
||||
}
|
||||
if (!self::is_enabled()) {
|
||||
return $this->error_response(__('微信公众号登录未开启或配置不完整', 'aksrt'), 400);
|
||||
return $this->error_response(__('微信公众号登录未开启或配置不完整', 'jio'), 400);
|
||||
}
|
||||
$data = $this->request_data($request);
|
||||
$code = strtoupper(sanitize_text_field((string) ($data['code'] ?? '')));
|
||||
if (preg_match('/^[A-Z0-9]{6,12}$/', $code) !== 1) {
|
||||
return $this->error_response(__('请输入至少 6 位的有效验证码', 'aksrt'), 400);
|
||||
return $this->error_response(__('请输入至少 6 位的有效验证码', 'jio'), 400);
|
||||
}
|
||||
$context = $this->request_context($request);
|
||||
if (is_wp_error($context)) {
|
||||
@@ -225,12 +225,12 @@ final class WeixinGzh {
|
||||
if ($context['action'] === 'bind') {
|
||||
$bind_pass = sanitize_text_field((string) ($data['bind_pass'] ?? ''));
|
||||
if (!OAuth::validate_bind_pass($bind_pass, 'weixingzh', $context['user_id'], false)) {
|
||||
return $this->error_response(__('请先完成人机验证后再绑定', 'aksrt'), 403);
|
||||
return $this->error_response(__('请先完成人机验证后再绑定', 'jio'), 403);
|
||||
}
|
||||
}
|
||||
$claimed = $this->claim_code_transaction($code, $context);
|
||||
if (!$claimed) {
|
||||
return $this->error_response(__('验证码无效、已过期或尝试次数过多', 'aksrt'), 400);
|
||||
return $this->error_response(__('验证码无效、已过期或尝试次数过多', 'jio'), 400);
|
||||
}
|
||||
$payload = is_array($claimed['payload'] ?? null) ? $claimed['payload'] : [];
|
||||
if ($context['action'] === 'bind') {
|
||||
@@ -243,7 +243,7 @@ final class WeixinGzh {
|
||||
* WeChat server URL verification.
|
||||
*/
|
||||
public function maybe_server_verify(): void {
|
||||
if (empty($_GET['aksrt_weixingzh']) || ($_SERVER['REQUEST_METHOD'] ?? '') !== 'GET' || !isset($_GET['echostr'])) {
|
||||
if (empty($_GET['jio_weixingzh']) || ($_SERVER['REQUEST_METHOD'] ?? '') !== 'GET' || !isset($_GET['echostr'])) {
|
||||
return;
|
||||
}
|
||||
if (!self::is_enabled() || !$this->verify_webhook_signature()) {
|
||||
@@ -264,7 +264,7 @@ final class WeixinGzh {
|
||||
* Receive plaintext WeChat server messages.
|
||||
*/
|
||||
public function maybe_server_message(): void {
|
||||
if (empty($_GET['aksrt_weixingzh']) || ($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || isset($_GET['echostr'])) {
|
||||
if (empty($_GET['jio_weixingzh']) || ($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || isset($_GET['echostr'])) {
|
||||
return;
|
||||
}
|
||||
if (!self::is_enabled() || !$this->verify_webhook_signature()) {
|
||||
@@ -312,18 +312,18 @@ final class WeixinGzh {
|
||||
*/
|
||||
private function code_mode_response(array $config, array $context): \WP_REST_Response {
|
||||
$qr = trim((string) ($config['code_qrcode'] ?? ''));
|
||||
$keyword = trim((string) ($config['code_keyword'] ?? __('登录', 'aksrt')));
|
||||
$html = '<img class="signin-qrcode-img" src="' . esc_url($qr) . '" alt="' . esc_attr__('微信公众号验证码登录二维码', 'aksrt') . '" style="width:160px;height:160px;object-fit:contain;" />';
|
||||
$html .= '<form class="aksrt-weixingzh-code-form" data-aksrt-weixingzh-code>';
|
||||
$html .= '<p class="muted-2-color em09">' . esc_html(sprintf(__('关注公众号后发送「%s」获取验证码', 'aksrt'), $keyword)) . '</p>';
|
||||
$keyword = trim((string) ($config['code_keyword'] ?? __('登录', 'jio')));
|
||||
$html = '<img class="signin-qrcode-img" src="' . esc_url($qr) . '" alt="' . esc_attr__('微信公众号验证码登录二维码', 'jio') . '" style="width:160px;height:160px;object-fit:contain;" />';
|
||||
$html .= '<form class="jio-weixingzh-code-form" data-jio-weixingzh-code>';
|
||||
$html .= '<p class="muted-2-color em09">' . esc_html(sprintf(__('关注公众号后发送「%s」获取验证码', 'jio'), $keyword)) . '</p>';
|
||||
$html .= '<input type="hidden" name="action" value="' . esc_attr($context['action']) . '" />';
|
||||
$html .= '<input type="hidden" name="user_id" value="' . esc_attr((string) $context['user_id']) . '" />';
|
||||
$html .= '<input type="hidden" name="redirect_to" value="' . esc_attr($context['redirect_to']) . '" />';
|
||||
if (!empty($context['bind_pass'])) {
|
||||
$html .= '<input type="hidden" name="bind_pass" value="' . esc_attr((string) $context['bind_pass']) . '" />';
|
||||
}
|
||||
$html .= '<input type="text" name="code" class="form-control" minlength="6" maxlength="12" autocomplete="one-time-code" placeholder="' . esc_attr__('请输入验证码', 'aksrt') . '" required />';
|
||||
$html .= '<button type="submit" class="but c-blue btn-block mt10">' . esc_html__('登录', 'aksrt') . '</button>';
|
||||
$html .= '<input type="text" name="code" class="form-control" minlength="6" maxlength="12" autocomplete="one-time-code" placeholder="' . esc_attr__('请输入验证码', 'jio') . '" required />';
|
||||
$html .= '<button type="submit" class="but c-blue btn-block mt10">' . esc_html__('登录', 'jio') . '</button>';
|
||||
$html .= '</form>';
|
||||
return new \WP_REST_Response([
|
||||
'success' => true,
|
||||
@@ -341,10 +341,10 @@ final class WeixinGzh {
|
||||
$requested_user_id = isset($data['user_id']) ? (int) $data['user_id'] : 0;
|
||||
if ($action === 'bind') {
|
||||
if ($current_user_id <= 0) {
|
||||
return new \WP_Error('weixingzh_bind_login_required', __('请先登录后再绑定微信公众号', 'aksrt'));
|
||||
return new \WP_Error('weixingzh_bind_login_required', __('请先登录后再绑定微信公众号', 'jio'));
|
||||
}
|
||||
if ($requested_user_id > 0 && $requested_user_id !== $current_user_id) {
|
||||
return new \WP_Error('weixingzh_bind_user_mismatch', __('绑定请求与当前用户不匹配', 'aksrt'));
|
||||
return new \WP_Error('weixingzh_bind_user_mismatch', __('绑定请求与当前用户不匹配', 'jio'));
|
||||
}
|
||||
}
|
||||
$redirect = OAuthUrlPolicy::validated_redirect((string) ($data['redirect_to'] ?? ''), home_url('/'));
|
||||
@@ -381,7 +381,7 @@ final class WeixinGzh {
|
||||
private function complete_browser_identity(array $payload): \WP_REST_Response {
|
||||
$openid = trim((string) ($payload['openid'] ?? ''));
|
||||
if ($openid === '') {
|
||||
return $this->error_response(__('微信身份信息无效', 'aksrt'), 400);
|
||||
return $this->error_response(__('微信身份信息无效', 'jio'), 400);
|
||||
}
|
||||
$profile = is_array($payload['profile'] ?? null) ? $payload['profile'] : [];
|
||||
$identity = [
|
||||
@@ -395,17 +395,17 @@ final class WeixinGzh {
|
||||
];
|
||||
if ((string) ($payload['action'] ?? 'login') === 'bind') {
|
||||
if (!$this->binding_user_matches($payload)) {
|
||||
return $this->error_response(__('绑定会话与当前用户不匹配', 'aksrt'), 403);
|
||||
return $this->error_response(__('绑定会话与当前用户不匹配', 'jio'), 403);
|
||||
}
|
||||
$bind_pass = sanitize_text_field((string) ($payload['bind_pass'] ?? ''));
|
||||
if (!OAuth::validate_bind_pass($bind_pass, 'weixingzh', get_current_user_id(), true)) {
|
||||
return $this->error_response(__('绑定验证已过期,请重新完成人机验证', 'aksrt'), 403);
|
||||
return $this->error_response(__('绑定验证已过期,请重新完成人机验证', 'jio'), 403);
|
||||
}
|
||||
$result = OAuthAccountService::bind(get_current_user_id(), 'weixingzh', $identity);
|
||||
if (is_wp_error($result)) {
|
||||
return $this->error_response($result->get_error_message(), 409);
|
||||
}
|
||||
$redirect = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('settings') : home_url('/');
|
||||
$redirect = function_exists('jio_get_user_center_url') ? jio_get_user_center_url('settings') : home_url('/');
|
||||
$redirect = add_query_arg(['oauth_action' => 'bind', 'oauth_provider' => 'weixingzh'], $redirect);
|
||||
return new \WP_REST_Response([
|
||||
'success' => true,
|
||||
@@ -423,8 +423,8 @@ final class WeixinGzh {
|
||||
'user_data' => $identity,
|
||||
'redirect_to' => $redirect,
|
||||
], 15 * MINUTE_IN_SECONDS, true);
|
||||
$bind_url = function_exists('aksrt_get_bind_url')
|
||||
? aksrt_get_bind_url($obk)
|
||||
$bind_url = function_exists('jio_get_bind_url')
|
||||
? jio_get_bind_url($obk)
|
||||
: add_query_arg(['tab' => 'bind', 'obk' => $obk], home_url('/sign/'));
|
||||
return new \WP_REST_Response([
|
||||
'success' => true,
|
||||
@@ -436,11 +436,11 @@ final class WeixinGzh {
|
||||
],
|
||||
], 200);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error_response(__('无法创建账号绑定会话,请重试', 'aksrt'), 500);
|
||||
return $this->error_response(__('无法创建账号绑定会话,请重试', 'jio'), 500);
|
||||
}
|
||||
}
|
||||
if (!$user instanceof \WP_User) {
|
||||
return $this->error_response(is_wp_error($user) ? $user->get_error_message() : __('微信账号匹配失败', 'aksrt'), 400);
|
||||
return $this->error_response(is_wp_error($user) ? $user->get_error_message() : __('微信账号匹配失败', 'jio'), 400);
|
||||
}
|
||||
OAuthAccountService::complete_login($user, true);
|
||||
$redirect = OAuthUrlPolicy::validated_redirect((string) ($payload['redirect_to'] ?? ''), home_url('/'));
|
||||
@@ -500,7 +500,7 @@ final class WeixinGzh {
|
||||
$code = $this->issue_code($from);
|
||||
$template = trim((string) ($config['code_reply'] ?? ''));
|
||||
if ($template === '') {
|
||||
$template = __('您的验证码是:%s,有效期 %d 分钟。', 'aksrt');
|
||||
$template = __('您的验证码是:%s,有效期 %d 分钟。', 'jio');
|
||||
}
|
||||
$message = str_replace(['%code%', '%time%', '%s', '%d'], [$code, '5', $code, '5'], $template);
|
||||
$this->echo_text_reply($from, $to, $message);
|
||||
@@ -854,14 +854,14 @@ final class WeixinGzh {
|
||||
}
|
||||
|
||||
private function rate_limit(string $scope, int $max, int $window, int $minimum_interval): ?\WP_REST_Response {
|
||||
$ip = function_exists('aksrt_get_client_ip')
|
||||
? trim((string) aksrt_get_client_ip())
|
||||
$ip = function_exists('jio_get_client_ip')
|
||||
? trim((string) jio_get_client_ip())
|
||||
: trim((string) ($_SERVER['REMOTE_ADDR'] ?? 'unknown'));
|
||||
$key = 'aksrt_weixingzh_rate_' . hash('sha256', $scope . '|' . $ip);
|
||||
$key = 'jio_weixingzh_rate_' . hash('sha256', $scope . '|' . $ip);
|
||||
$lock_scope = 'weixingzh-rate:' . $key;
|
||||
$lock = OAuthTransactionStore::acquire_lock($lock_scope, 5);
|
||||
if ($lock === false) {
|
||||
return $this->error_response(__('请求过于频繁,请稍后重试', 'aksrt'), 429);
|
||||
return $this->error_response(__('请求过于频繁,请稍后重试', 'jio'), 429);
|
||||
}
|
||||
try {
|
||||
$now = time();
|
||||
@@ -871,7 +871,7 @@ final class WeixinGzh {
|
||||
}
|
||||
$last_at = (float) ($row['last_at'] ?? 0);
|
||||
if ((int) ($row['count'] ?? 0) >= $max || microtime(true) - $last_at < $minimum_interval) {
|
||||
return $this->error_response(__('请求过于频繁,请稍后重试', 'aksrt'), 429);
|
||||
return $this->error_response(__('请求过于频繁,请稍后重试', 'jio'), 429);
|
||||
}
|
||||
$row['count'] = (int) $row['count'] + 1;
|
||||
$row['last_at'] = microtime(true);
|
||||
|
||||
Reference in new issue
Block a user