refactor: flatten src/AKSRT → src (drop theme-identifier dir)
Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/**
|
||||
* Identity verification facade for existing presentation call sites.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\User;
|
||||
|
||||
use AKSRT\Identity\ApplicationRepository;
|
||||
use AKSRT\Identity\EvidenceService;
|
||||
use AKSRT\Identity\EventRepository;
|
||||
use AKSRT\Identity\TransitionService;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class AuthApply {
|
||||
|
||||
private static ?self $instance = null;
|
||||
|
||||
public static function get_instance(): self {
|
||||
return self::$instance ??= new self();
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
if (is_admin()) {
|
||||
add_filter('manage_users_columns', [$this, 'add_admin_user_column']);
|
||||
add_filter('manage_users_custom_column', [$this, 'render_admin_user_column'], 10, 3);
|
||||
add_action('show_user_profile', [$this, 'render_admin_profile_status']);
|
||||
add_action('edit_user_profile', [$this, 'render_admin_profile_status']);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public static function settings(): array {
|
||||
$identity = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_user_identity_settings() : [];
|
||||
return is_array($identity['verify'] ?? null) ? $identity['verify'] : [];
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public static function type_settings(string $type): array {
|
||||
$types = self::settings()['types'] ?? [];
|
||||
$type = sanitize_key($type);
|
||||
return is_array($types[$type] ?? null) ? $types[$type] : [];
|
||||
}
|
||||
|
||||
public static function application_count(int $user_id, string $type): int {
|
||||
return (new ApplicationRepository())->count_user_type($user_id, sanitize_key($type));
|
||||
}
|
||||
|
||||
public static function get_status(int $user_id): string {
|
||||
$repo = new ApplicationRepository();
|
||||
$application = $repo->verified_for_user($user_id) ?: $repo->latest_for_user($user_id);
|
||||
return $application ? TransitionService::public_status((string) $application['status']) : '';
|
||||
}
|
||||
|
||||
public static function is_verified(int $user_id): bool {
|
||||
return (new ApplicationRepository())->verified_for_user($user_id) !== null;
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public static function get_auth_info(int $user_id): array {
|
||||
$application = (new ApplicationRepository())->verified_for_user($user_id);
|
||||
return $application ? [
|
||||
'name' => (string) $application['public_name'],
|
||||
'desc' => (string) $application['public_desc'],
|
||||
'type' => (string) $application['type'],
|
||||
'time' => (string) ($application['completed_at'] ?: $application['updated_at']),
|
||||
] : [];
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public static function get_apply_payload(int $user_id): array {
|
||||
$application = (new ApplicationRepository())->latest_for_user($user_id);
|
||||
if (!$application) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
'application_uuid' => (string) $application['application_uuid'],
|
||||
'user_id' => (int) $application['user_id'],
|
||||
'name' => (string) $application['public_name'],
|
||||
'real_name' => (string) $application['person_name_masked'],
|
||||
'desc' => (string) $application['public_desc'],
|
||||
'msg' => (string) ($application['manual_reason'] ?? ''),
|
||||
'type' => (string) $application['type'],
|
||||
'time' => (string) $application['created_at'],
|
||||
'fee' => (float) $application['fee_amount'],
|
||||
'_application' => $application,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<int,array{id:int,url:string,thumbnail_url:string}> */
|
||||
public static function get_evidence_items(array $application, int $owner_id = 0, bool $admin_context = false): array {
|
||||
$record = is_array($application['_application'] ?? null) ? $application['_application'] : null;
|
||||
if (!$record && !empty($application['application_uuid'])) {
|
||||
$record = (new ApplicationRepository())->find_by_uuid((string) $application['application_uuid']);
|
||||
}
|
||||
return $record ? (new EvidenceService())->items($record, $admin_context) : [];
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public static function application_view(array $application, int $owner_id = 0, bool $admin_context = false): array {
|
||||
return [
|
||||
'name' => (string) ($application['name'] ?? ''),
|
||||
'real_name' => (string) ($application['real_name'] ?? ''),
|
||||
'desc' => (string) ($application['desc'] ?? ''),
|
||||
'msg' => (string) ($application['msg'] ?? ''),
|
||||
'type' => sanitize_key((string) ($application['type'] ?? '')),
|
||||
'time' => (string) ($application['time'] ?? ''),
|
||||
'evidence' => self::get_evidence_items($application, $owner_id, $admin_context),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<int,array<string,mixed>> */
|
||||
public static function get_review_history(int $user_id): array {
|
||||
$application = (new ApplicationRepository())->latest_for_user($user_id);
|
||||
if (!$application) {
|
||||
return [];
|
||||
}
|
||||
$history = [];
|
||||
foreach ((new EventRepository())->for_application((int) $application['id']) as $event) {
|
||||
$history[] = [
|
||||
'status' => TransitionService::public_status((string) ($event['to_status'] ?? '')),
|
||||
'reason' => (string) ($event['result_code'] ?? ''),
|
||||
'reviewer' => (int) ($event['actor_user_id'] ?? 0),
|
||||
'time' => (string) ($event['created_at'] ?? ''),
|
||||
];
|
||||
}
|
||||
return $history;
|
||||
}
|
||||
|
||||
public static function review(int $user_id, string $status, string $note, int $reviewer_id) {
|
||||
$repo = new ApplicationRepository();
|
||||
$application = $repo->latest_for_user($user_id);
|
||||
if (!$application) {
|
||||
return new \WP_Error('aksrt_verify_missing', __('认证申请不存在', 'aksrt'));
|
||||
}
|
||||
$status = sanitize_key($status);
|
||||
$note = sanitize_textarea_field($note);
|
||||
if (!in_array($status, ['verified', 'rejected', 'cancelled'], true)) {
|
||||
return new \WP_Error('aksrt_verify_status', __('审核状态无效', 'aksrt'));
|
||||
}
|
||||
if (in_array($status, ['rejected', 'cancelled'], true) && $note === '') {
|
||||
return new \WP_Error('aksrt_verify_note', __('请填写处理原因', 'aksrt'));
|
||||
}
|
||||
$result = (new TransitionService($repo))->transition($application, $status, [
|
||||
'review_note' => $note,
|
||||
'reviewer_id' => $reviewer_id,
|
||||
], ['source' => 'admin', 'event_type' => 'manual_review', 'actor_user_id' => $reviewer_id]);
|
||||
return is_wp_error($result) ? $result : ['status' => $status, 'reviewed_at' => (string) $result['completed_at']];
|
||||
}
|
||||
|
||||
public function add_admin_user_column(array $columns): array {
|
||||
$columns['aksrt_identity_status'] = __('身份认证', 'aksrt');
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function render_admin_user_column(string $output, string $column_name, int $user_id): string {
|
||||
if ($column_name !== 'aksrt_identity_status') {
|
||||
return $output;
|
||||
}
|
||||
$status = self::get_status($user_id);
|
||||
$labels = ['pending' => __('进行中', 'aksrt'), 'verified' => __('已认证', 'aksrt'), 'rejected' => __('未通过', 'aksrt'), 'cancelled' => __('已取消', 'aksrt')];
|
||||
return $status === '' ? esc_html__('未认证', 'aksrt') : esc_html($labels[$status] ?? $status);
|
||||
}
|
||||
|
||||
public function render_admin_profile_status(\WP_User $user): void {
|
||||
$status = self::get_status((int) $user->ID);
|
||||
$info = self::get_auth_info((int) $user->ID);
|
||||
?>
|
||||
<h2><?php esc_html_e('身份认证(AKSRT)', 'aksrt'); ?></h2>
|
||||
<table class="form-table" role="presentation">
|
||||
<tr><th><?php esc_html_e('认证状态', 'aksrt'); ?></th><td><?php echo esc_html($status ?: __('未认证', 'aksrt')); ?></td></tr>
|
||||
<?php if (!empty($info['name'])) : ?><tr><th><?php esc_html_e('认证身份', 'aksrt'); ?></th><td><?php echo esc_html((string) $info['name']); ?></td></tr><?php endif; ?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user