change dabestaniha to mahak
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace Dabestaniha\AuthenticateBridge\App\Http\Controllers;
|
||||
|
||||
use Dabestaniha\AuthenticateBridge\App\Http\Requests\DabestanihaAuthenticateRequest;
|
||||
use Dabestaniha\AuthenticateBridge\App\Http\Requests\MahakAuthenticateRequest;
|
||||
use ReflectionMethod;
|
||||
use Firebase\JWT;
|
||||
|
||||
class AuthenticateController extends InvocableController
|
||||
{
|
||||
public function __invoke(DabestanihaAuthenticateRequest $request)
|
||||
public function __invoke(MahakAuthenticateRequest $request)
|
||||
{
|
||||
$token = $request->string('token');
|
||||
|
||||
@@ -17,7 +17,7 @@ class AuthenticateController extends InvocableController
|
||||
$identifier_name = get_configured_option('user-identifier');
|
||||
$identifier_value = $payload[$identifier_name] ?? null;
|
||||
|
||||
$name = $payload['name'] ?? config('da.translates.new-user');
|
||||
$name = $payload['name'] ?? config('mahak.translates.new-user');
|
||||
$user_id = $this->find_or_create_user($identifier_name, $identifier_value, $name);
|
||||
|
||||
$this->login_user($user_id);
|
||||
|
||||
@@ -9,10 +9,10 @@ abstract class InvocableController
|
||||
{
|
||||
public static function resolve(): void
|
||||
{
|
||||
$r = new ReflectionMethod(static::class, '__invoke');
|
||||
$reflection = new ReflectionMethod(static::class, '__invoke');
|
||||
|
||||
$args = [];
|
||||
foreach ($r->getParameters() as $param) {
|
||||
foreach ($reflection->getParameters() as $param) {
|
||||
$class = $param->getType()->getName();
|
||||
|
||||
if (is_subclass_of($class, BaseFormRequest::class)) {
|
||||
|
||||
@@ -6,55 +6,55 @@ class SettingsPageFormController extends InvocableController
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
foreach (config('da.options') as $configured => $options_key) {
|
||||
register_setting(config('da.settings-group'), $options_key);
|
||||
foreach (config('mahak.options') as $configured => $options_key) {
|
||||
register_setting(config('mahak.settings-group'), $options_key);
|
||||
}
|
||||
|
||||
add_settings_section(
|
||||
config('da.section-id'),
|
||||
config('da.translations.section-id'),
|
||||
config('mahak.section-id'),
|
||||
config('mahak.translations.section-id'),
|
||||
null,
|
||||
config('da.settings-page')
|
||||
config('mahak.settings-page')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
config('da.options.user-identifier'),
|
||||
config('da.translations.user-identifier'),
|
||||
config('mahak.options.user-identifier'),
|
||||
config('mahak.translations.user-identifier'),
|
||||
fn () => $this->user_identifier(),
|
||||
config('da.settings-page'),
|
||||
config('da.section-id')
|
||||
config('mahak.settings-page'),
|
||||
config('mahak.section-id')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
config('da.options.jwt-secret'),
|
||||
config('da.translations.jwt-secret'),
|
||||
config('mahak.options.jwt-secret'),
|
||||
config('mahak.translations.jwt-secret'),
|
||||
fn () => $this->jwt_secret(),
|
||||
config('da.settings-page'),
|
||||
config('da.section-id')
|
||||
config('mahak.settings-page'),
|
||||
config('mahak.section-id')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
config('da.options.login-route'),
|
||||
config('da.translations.login-route'),
|
||||
config('mahak.options.login-route'),
|
||||
config('mahak.translations.login-route'),
|
||||
fn () => $this->login_route(),
|
||||
config('da.settings-page'),
|
||||
config('da.section-id')
|
||||
config('mahak.settings-page'),
|
||||
config('mahak.section-id')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
config('da.options.after-login-route'),
|
||||
config('da.translations.after-login-route'),
|
||||
config('mahak.options.after-login-route'),
|
||||
config('mahak.translations.after-login-route'),
|
||||
fn () => $this->after_login_route(),
|
||||
config('da.settings-page'),
|
||||
config('da.section-id')
|
||||
config('mahak.settings-page'),
|
||||
config('mahak.section-id')
|
||||
);
|
||||
|
||||
$loginRouteOptionName = config('da.options.login-route');
|
||||
$loginRouteOptionName = config('mahak.options.login-route');
|
||||
add_filter("pre_update_option_{$loginRouteOptionName}", function ($value) {
|
||||
return trim($value, '/');
|
||||
});
|
||||
|
||||
$afterLoginRouteOptionName = config('da.options.after-login-route');
|
||||
$afterLoginRouteOptionName = config('mahak.options.after-login-route');
|
||||
add_filter("pre_update_option_{$afterLoginRouteOptionName}", function ($value) {
|
||||
return trim($value, '/');
|
||||
});
|
||||
@@ -62,14 +62,14 @@ class SettingsPageFormController extends InvocableController
|
||||
|
||||
public function user_identifier(): void
|
||||
{
|
||||
$name = config('da.options.user-identifier');
|
||||
$name = config('mahak.options.user-identifier');
|
||||
$value = get_option($name, 'mobile');
|
||||
|
||||
$html = "<select name='$name'>";
|
||||
|
||||
foreach (config('da.user-identifiers') as $identifier) {
|
||||
foreach (config('mahak.user-identifiers') as $identifier) {
|
||||
$selected = $value === $identifier ? "selected='selected'" : null;
|
||||
$translate = config("da.translations.$identifier");
|
||||
$translate = config("mahak.translations.$identifier");
|
||||
$html .= "<option value='$identifier' $selected>$translate</option>";
|
||||
}
|
||||
|
||||
@@ -79,15 +79,15 @@ class SettingsPageFormController extends InvocableController
|
||||
|
||||
public function jwt_secret(): void
|
||||
{
|
||||
$name = config('da.options.jwt-secret');
|
||||
$name = config('mahak.options.jwt-secret');
|
||||
$value = esc_attr(get_option($name, ''));
|
||||
echo "<input type='text' name='$name' value='$value' class='regular-text ltr' />";
|
||||
}
|
||||
|
||||
public function login_route(): void
|
||||
{
|
||||
$name = config('da.options.login-route');
|
||||
$value = esc_attr(get_option($name, config('da.login_route_default')));
|
||||
$name = config('mahak.options.login-route');
|
||||
$value = esc_attr(get_option($name, config('mahak.login_route_default')));
|
||||
echo '<div class="ltr" style="float: right; display: flex; align-items: center; gap: 5px;">';
|
||||
echo '<span style="color: #666;">'.home_url('/').'</span>';
|
||||
echo "<input type='text' name='$name' value='$value' class='regular-text' />";
|
||||
@@ -96,8 +96,8 @@ class SettingsPageFormController extends InvocableController
|
||||
|
||||
public function after_login_route(): void
|
||||
{
|
||||
$name = config('da.options.after-login-route');
|
||||
$value = esc_attr(get_option($name, config('da.after_login_route_default')));
|
||||
$name = config('mahak.options.after-login-route');
|
||||
$value = esc_attr(get_option($name, config('mahak.after_login_route_default')));
|
||||
echo '<div class="ltr" style="float: right; display: flex; align-items: center; gap: 5px;">';
|
||||
echo '<span style="color: #666;">'.home_url('/').'</span>';
|
||||
echo "<input type='text' name='$name' value='$value' class='regular-text' />";
|
||||
|
||||
@@ -7,23 +7,23 @@ class SettingsPageMenuController extends InvocableController
|
||||
public function __invoke()
|
||||
{
|
||||
add_options_page(
|
||||
config('da.translations.settings-page-title'),
|
||||
config('da.translations.settings-page-menu'),
|
||||
config('mahak.translations.settings-page-title'),
|
||||
config('mahak.translations.settings-page-menu'),
|
||||
'manage_options',
|
||||
config('da.settings-page'),
|
||||
fn() => $this->dabestaniha_authenticate_settings_page(),
|
||||
config('mahak.settings-page'),
|
||||
fn() => $this->mahak_authenticate_settings_page(),
|
||||
);
|
||||
}
|
||||
|
||||
function dabestaniha_authenticate_settings_page(): void
|
||||
function mahak_authenticate_settings_page(): void
|
||||
{
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?= config('da.translations.settings-page-title') ?></h1>
|
||||
<h1><?= config('mahak.translations.settings-page-title') ?></h1>
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
settings_fields(config('da.settings-group'));
|
||||
do_settings_sections(config('da.settings-page'));
|
||||
settings_fields(config('mahak.settings-group'));
|
||||
do_settings_sections(config('mahak.settings-page'));
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
|
||||
+2
-2
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace Dabestaniha\AuthenticateBridge\App\Http\Requests;
|
||||
|
||||
class DabestanihaAuthenticateRequest extends BaseFormRequest
|
||||
class MahakAuthenticateRequest extends BaseFormRequest
|
||||
{
|
||||
|
||||
public function getRequestRoutePath(): string
|
||||
{
|
||||
return get_configured_option('login-route');
|
||||
return get_configured_option('login-route', config('mahak.login_route_default'));
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
@@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'settings-page' => 'dabestaniha-authenticate-settings',
|
||||
'settings-group' => 'dabestaniha_authenticate_settings',
|
||||
'section-id' => 'dabestaniha_authenticate_main',
|
||||
'settings-page' => 'mahak-authenticate-settings',
|
||||
'settings-group' => 'mahak_authenticate_settings',
|
||||
'section-id' => 'mahak_authenticate_main',
|
||||
|
||||
|
||||
'options' => [
|
||||
'jwt-secret' => 'da_jwt_secret',
|
||||
'user-identifier' => 'da_user_identifier',
|
||||
'login-route' => 'da_login_route',
|
||||
'after-login-route' => 'da_after_login_route',
|
||||
'jwt-secret' => 'mahak_jwt_secret',
|
||||
'user-identifier' => 'mahak_user_identifier',
|
||||
'login-route' => 'mahak_login_route',
|
||||
'after-login-route' => 'mahak_after_login_route',
|
||||
],
|
||||
|
||||
'user-identifiers' => [
|
||||
@@ -19,7 +19,7 @@ return [
|
||||
'username',
|
||||
],
|
||||
|
||||
'login_route_default' => 'dabestaniha/login',
|
||||
'login_route_default' => 'mahak/login',
|
||||
'after_login_route_default' => 'dashboard',
|
||||
|
||||
'translations' => [
|
||||
@@ -28,12 +28,12 @@ return [
|
||||
'username' => 'نام کاربری',
|
||||
|
||||
'section-id' => 'تنظیمات عمومی',
|
||||
'settings-page-title' => 'تنظیمات احراز هویت دبستانی ها',
|
||||
'settings-page-menu' => 'احراز هویت دبستانی ها',
|
||||
'settings-page-title' => 'تنظیمات احراز هویت ماهک',
|
||||
'settings-page-menu' => 'احراز هویت ماهک',
|
||||
|
||||
'jwt-secret' => 'کلید JWT',
|
||||
'user-identifier' => 'فیلد شناسایی کاربر',
|
||||
'login-route' => 'مسیر لاگین دبستانی ها',
|
||||
'login-route' => 'مسیر لاگین ماهک',
|
||||
'after-login-route' => 'مسیر بعد از لاگین',
|
||||
|
||||
'new-user' => 'کاربر جدید',
|
||||
+3
-3
@@ -27,14 +27,14 @@ function setup_configs(): void
|
||||
$configs[basename($configs_file, '.php')] = include $configs_file;
|
||||
}
|
||||
|
||||
define("DA_CASHED_CONFIG", $configs);
|
||||
define("MAHAK_CASHED_CONFIG", $configs);
|
||||
}
|
||||
setup_configs();
|
||||
|
||||
if (!function_exists('config')) {
|
||||
function config(string $key, ?string $default = null): null|string|array
|
||||
{
|
||||
$value = DA_CASHED_CONFIG;
|
||||
$value = MAHAK_CASHED_CONFIG;
|
||||
foreach (explode('.', $key) as $key) {
|
||||
$value = $value[$key] ?? $default;
|
||||
}
|
||||
@@ -46,6 +46,6 @@ if (!function_exists('config')) {
|
||||
if (!function_exists('get_configured_option')) {
|
||||
function get_configured_option(string $key, ?string $default = null): null|string|array
|
||||
{
|
||||
return get_option(config("da.options.$key"), $default);
|
||||
return get_option(config("mahak.options.$key"), $default);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user