【XIUNOX插件】用户认证 v1.0.5 [复制链接]

管理员组

xnx_verify 用户认证

功能

  • 站长认证(webmaster)与开发者认证(developer)两类,申请 → 审核 → 颁发 / 驳回完整流程
  • 前台申请页:站长填网站名 / 域名 / 简介 / 身份证明;开发者填开发名 / 官方链接 / 3 组作品
  • 申请前置条件(AND 关系):注册天数、发帖数、积分、用户组(多选 OR)
  • 申请扣除积分(deduct_credits_type / value),提交时扣除,无论通过 / 驳回不返还
  • 冷却期:驳回后 N 天内不可重新申请(按 reject_time 计算),前台展示剩余天数
  • 互斥规则:一个用户只能拥有一种认证,新认证通过自动撤销另一种
  • 有效期:站长 / 开发者可分别配置有效天数(0=永久),每日 cron 自动撤销过期认证 + 通知 + 回收勋章
  • 后台管理:待审列表分页 + 通过 / 驳回(必填原因)+ 已认证列表(可按类型筛选)+ 撤销 + 手动颁发
  • 联动 xnx_medal 勋章系统:通过 medal_condition_* hook 提供 condition_type='verified_webmaster' / 'verified_developer' 勋章条件
  • 通知:通过 / 驳回 / 撤销 / 过期均通过 notify_create 通知用户
  • 联动 DiscoverService:可注册到发现页
  • 缓存:CacheHelper::registerKeys('xnx_verify', ...) + 静态缓存避免列表页 N+1
  • 多语言(zh-cn / zh-tw / en-us)

文件结构

plugin/xnx_verify/
├── conf.json
├── install.php / uninstall.php        # 建 xnx_verify_apply / xnx_verify_user 表
├── setting.php                        # 后台管理 + 设置
├── icon.png
├── model/
│   └── VerifyService.php              # 核心服务(申请 / 审核 / 查询 / 撤销 / 勋章联动)
├── route/
│   └── verify.php                     # 前台路由:apply / submit / status
├── view/htm/
│   ├── verify_apply.htm               # 申请表单页
│   ├── verify_status.htm              # 我的认证状态页
│   ├── my_verify.htm                  # 个人中心入口
│   └── setting.htm                    # 后台管理页
├── static/js/verify.js
└── hook/
    ├── model_inc_file.php             # 自动加载 VerifyService
    ├── model_route_table_end.php      # 注册 verify 路由
    ├── index_route_case_end.php
    ├── admin_index_route_case_end.php
    ├── my_sidebar_nav_threads_before.htm  # 个人中心侧栏入口
    ├── my_action_before.php
    ├── model_cron_daily_end.php       # 每日 cron 调用 checkExpired()
    ├── medal_condition_check.php       # ↓ 提供给 xnx_medal 的勋章条件
    ├── medal_condition_progress.php
    ├── medal_condition_description.php
    ├── medal_condition_build_value.php
    ├── medal_condition_options.htm
    ├── medal_condition_inputs.htm
    ├── lang_zh_cn_bbs.php
    ├── lang_zh_tw_bbs.php
    └── lang_en_us_bbs.php

配置流程

  1. 后台「插件管理」安装并启用 xnx_verify
  2. 进入「插件设置」→「配置」→ 设置冷却天数、前置条件(注册天数 / 发帖数 / 积分 / 用户组)、申请扣分、有效期
  3. 测试:用户前台访问 /verify-apply → 通过前置检查后填写表单 → 提交后扣除积分(如配置)
  4. 后台「待审列表」→ 通过 / 驳回(必填原因)→ 用户收到通知;通过时自动颁发对应勋章(需 xnx_medal 已配置 condition_type='verified_webmaster' / 'verified_developer' 勋章)
  5. 后台「已认证列表」可撤销认证;手动颁发可绕过申请直接授予指定用户
  6. 按需在「发现页配置」开启插件入口到发现页

扩展说明

VerifyService 通过 hook/model_inc_file.php 自动加载,公开静态方法可被其他插件调用;同时通过 medal_condition_* hook 给 xnx_medal 提供勋章条件。

Service 类与方法签名

VerifyService::getInstance(): VerifyService        // 构造时注册缓存键

// ---- 配置 ----
VerifyService::getSettings(): array               // cooldown_days / require_* / deduct_credits_* / *_expire_days
VerifyService::saveSettings(array $settings): void
VerifyService::getDefaultExpireDays(string $type): int

// ---- 前置检查 ----
VerifyService::checkPrerequisites(int $uid): array  // ['ok'=>bool, 'items'=>[...]]

// ---- 申请 ----
VerifyService::createApply(int $uid, string $type, array $data): array
//   type: 'webmaster' | 'developer',data 为表单数据
//   内部:前置条件检查 → 已有认证检查 → 互斥(待审中不可再申请)→ 冷却期 → 扣分 → 写库
VerifyService::approveApply(int $apply_id, int $audit_uid): array   // 颁发认证 + 撤销其他类型 + 颁发勋章 + 通知
VerifyService::rejectApply(int $apply_id, int $audit_uid, string $reason): array  // reason 必填

// ---- 状态查询 ----
VerifyService::getUserVerifications(int $uid): array   // [type => verify_data],带静态缓存
VerifyService::isVerified(int $uid, string $type): bool   // 常用查询:用户是否拥有某类认证
VerifyService::getUserApplyList(int $uid): array       // 用户所有申请记录(按 id 倒序)
VerifyService::getCooldownRemaining(int $uid, string $type): int  // 0=可申请

// ---- 撤销与手动颁发 ----
VerifyService::revokeVerify(int $uid, string $type, string $reason = ''): array  // reason 非空时发通知
VerifyService::grantManual(int $uid, string $type, string $data_json = '', int $expireDays = 0): array  // 管理员手动颁发

// ---- 有效期 ----
VerifyService::checkExpired(): int    // 每日 cron 调用,撤销过期认证 + 回收勋章 + 通知,返回处理条数

// ---- 勋章联动(被 xnx_medal 调用 / 可被其他插件复用)----
VerifyService::grantMedalForVerify(int $uid, string $type): void   // 颁发 condition_type='verified_'.$type 的所有勋章
VerifyService::revokeMedalForVerify(int $uid, string $type): void  // 回收对应勋章

// ---- 后台查询 ----
VerifyService::getPendingApplies(int $page, int $pagesize): array  // 待审列表
VerifyService::getVerifiedList(int $page, int $pagesize, string $type = ''): array  // 已认证列表
VerifyService::getApply(int $id): array

数据表与触发时机

  • xnx_verify_apply:申请记录(uid+type+status 索引,status 0 待审 / 1 通过 / -1 驳回)
  • xnx_verify_user:用户认证状态(uid+type 联合主键,含 expire_time 0=永久)
  • 互斥规则:approveApplygrantManual 都会调用 revokeOtherTypeVerify() 撤销另一种认证(前者不发通知避免轰炸,后者发通知)
  • hook/model_cron_daily_end.php 每日 0 点触发 checkExpired(),需注意 hook 内 try/catch 包裹且不可 return,否则会绕过 cache_delete('cron_lock_2') 导致 cron 锁不释放
  • 勋章条件 hook(medal_condition_check.php 等 6 个)由 MedalService::checkCondition()default 分支前触发,可用变量 $uid / $condition_type / $condition_value / $result(引用),约定 $result = ['ok'=>bool, 'message'=>string, 'handled'=>true]
  • 缓存键通过 CacheHelper::registerKeys('xnx_verify', ...) 注册:user_verifications / apply_stats,写操作后通过 clearCache() 清理

版本 1.0.5 | 兼容 Xiuno 1.1+



版本:v1.0.5
适用版本:1.1
开发者:贰先生

请登录后查看此内容
最新回复

请先登录后再回复 登录