handel request

This commit is contained in:
2025-07-15 16:59:35 +03:30
parent b23b66a02b
commit ce1ee62d66
18 changed files with 941 additions and 2 deletions
+51
View File
@@ -1 +1,52 @@
<?php
/**
* Plugin Name: Dabestaniha Authenticate Bridge
* Description: Authenticate WordPress user via json web token from Laravel Application.
* Version: 1.0
* Author: Dabestaniha
*/
require_once __DIR__ . '/vendor/autoload.php';
use Dabestaniha\AuthenticateBridge\Requests\DabestanihaAuthenticateRequest;
add_action('init', function () {
$request = DabestanihaAuthenticateRequest::make();
if (!$request->shouldContinue()) {
return;
}
$request->validate();
$token = $request->string('token');
var_dump($token);
die();
// اینجا توکن رو اعتبارسنجی می‌کنیم
$user_id = verify_laravel_token_and_get_user_id($token); // این تابع رو بعداً می‌نویسیم
if ($user_id) {
wp_set_auth_cookie($user_id);
wp_set_current_user($user_id);
do_action('wp_login', get_userdata($user_id)->user_login, get_userdata($user_id));
// انتقال به پنل
wp_redirect(home_url('/dashboard'));
exit;
} else {
wp_die('توکن نامعتبر است.');
}
});
function verify_laravel_token_and_get_user_id($token): bool|int
{
// مثلا: رمزگشایی JWT، یا بررسی دیتابیس توکن‌ها
// برای تست می‌تونیم یک توکن ثابت بذاریم
if ($token === 'sample_token_123') {
return 2; // ID یک کاربر موجود
}
return false;
}