diff --git a/dabestaniha-authenticate-bridge.php b/dabestaniha-authenticate-bridge.php index 1c1322b..0760231 100644 --- a/dabestaniha-authenticate-bridge.php +++ b/dabestaniha-authenticate-bridge.php @@ -32,6 +32,8 @@ add_action('init', function () { exit(); }); +require_once 'settings-page.php'; + function verify_laravel_token_and_get_user_id($token): bool|int { return 0; diff --git a/settings-page.php b/settings-page.php new file mode 100644 index 0000000..b1d4fcc --- /dev/null +++ b/settings-page.php @@ -0,0 +1,89 @@ +"; + + foreach (config('da.user-identifiers') as $identifier) { + $selected = $value === $identifier ? "selected='selected'" : null; + $translate = config("da.translations.$identifier"); + $html .= ""; + } + + $html .= ""; + echo $html; + }, + config('da.settings-page'), + config('da.section-id') + ); + + add_settings_field( + config('da.options.jwt-secret'), + config('da.translations.jwt-secret'), + function () { + $name = config('da.options.jwt-secret'); + $value = esc_attr(get_option($name, '')); + echo ""; + }, + config('da.settings-page'), + config('da.section-id') + ); + + add_settings_field( + config('da.options.login-route'), + config('da.translations.login-route'), + function () { + $name = config('da.options.login-route'); + $value = esc_attr(get_option($name, config('da.login_route_default'))); + echo ""; + }, + config('da.settings-page'), + config('da.section-id') + ); +}); + + +function dabestaniha_authenticate_settings_page(): void +{ + ?> +
+

+
+ +
+
+ 'dabestaniha-authenticate-settings', + 'settings-group' => 'dabestaniha_authenticate_settings', + 'section-id' => 'dabestaniha_authenticate_main', + + + 'options' => [ + 'jwt-secret' => 'da_jwt_secret', + 'user-identifier' => 'da_user_identifier', + 'login-route' => 'da_login_route', + ], + + 'user-identifiers' => [ + 'mobile', + 'email', + 'username', + ], + + 'login_route_default' => 'dabestaniha/login', + + 'translations' => [ + 'mobile' => 'تلفن همراه', + 'email' => 'ایمیل', + 'username' => 'نام کاربری', + + 'section-id' => 'تنظیمات عمومی', + 'settings-page-title' => 'تنظیمات احراز هویت دبستانی ها', + 'settings-page-menu' => 'احراز هویت دبستانی ها', + + 'jwt-secret' => 'کلید JWT', + 'user-identifier' => 'فیلد شناسایی کاربر', + 'login-route' => 'آدرس لاگین از لاراول', + ], +]; \ No newline at end of file diff --git a/src/helpers.php b/src/helpers.php index 42e59bb..3917363 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -15,4 +15,21 @@ if (!function_exists('dd')) { array_map(function($arg) {var_dump($arg);}, func_get_args()); die; } -} \ No newline at end of file +} + + +define("DA_CASHED_CONFIG", [ + 'da' => require plugin_dir_path(__FILE__) . 'configs/da.php', +]); + + +if (!function_exists('config')) { + function config(string $key, ?string $default = null): null|string|array + { + $value = DA_CASHED_CONFIG; + foreach (explode('.', $key) as $key) { + $value = $value[$key] ?? $default; + } + return $value; + } +}