feat: 添加身份认证服务商配置页
This commit is contained in:
1 parent
cc33664c1b
commit
92e445dbd4
7 files changed
+538
-1
No files matched your search
@@ -11,6 +11,7 @@ class UserController extends ControllerBase {
|
||||
use UserControllerReportOperations;
|
||||
use UserControllerInviteOperations;
|
||||
use UserControllerVerifyIntegrations;
|
||||
use UserControllerIdentitySettings;
|
||||
use UserControllerAuthPhoneOperations;
|
||||
use UserControllerRestrictionOperations;
|
||||
use UserControllerFollowOperations;
|
||||
@@ -260,6 +261,25 @@ class UserController extends ControllerBase {
|
||||
'permission_callback' => function () { return is_user_logged_in(); },
|
||||
]);
|
||||
|
||||
// Identity verification provider settings (admin only)
|
||||
register_rest_route(self::API_NAMESPACE, '/identity/settings', [
|
||||
[
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'get_identity_settings'],
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
],
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'update_identity_settings'],
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
],
|
||||
]);
|
||||
register_rest_route(self::API_NAMESPACE, '/identity/settings/test', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'test_identity_settings'],
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
]);
|
||||
|
||||
// SMS provider status
|
||||
register_rest_route(self::API_NAMESPACE, '/sms/status', [
|
||||
'methods' => 'GET',
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin REST handlers for identity provider configuration.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Admin;
|
||||
|
||||
use AKSRT\Settings\IdentityAdmin;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
trait UserControllerIdentitySettings {
|
||||
public function get_identity_settings(): \WP_REST_Response {
|
||||
return $this->success([
|
||||
'data' => $this->identity_settings_response(IdentityAdmin::read()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update_identity_settings(\WP_REST_Request $request): \WP_REST_Response {
|
||||
$settings = IdentityAdmin::update($this->get_json_params($request));
|
||||
|
||||
return $this->success([
|
||||
'message' => __('身份认证服务商配置已保存', 'aksrt'),
|
||||
'data' => $this->identity_settings_response($settings),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_identity_settings(\WP_REST_Request $request): \WP_REST_Response {
|
||||
$params = $this->get_json_params($request);
|
||||
$provider = sanitize_key((string) ($params['provider'] ?? ''));
|
||||
$result = IdentityAdmin::test($provider);
|
||||
|
||||
if (empty($result['success'])) {
|
||||
return $this->error((string) ($result['message'] ?? __('配置检查失败', 'aksrt')), 422);
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'message' => (string) $result['message'],
|
||||
'data' => ['provider' => $provider, 'configured' => true],
|
||||
]);
|
||||
}
|
||||
|
||||
private function identity_settings_response(array $settings): array {
|
||||
$settings['callback_url'] = rest_url(self::API_NAMESPACE . '/identity/callback');
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user