Initial commit
This commit is contained in:
27
app/Http/Controllers/AuthController.php
Normal file
27
app/Http/Controllers/AuthController.php
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login(Request $request)
|
||||
{
|
||||
$credentials = $request->only('email', 'password');
|
||||
|
||||
if (!Auth::attempt($credentials)) {
|
||||
return response()->json([
|
||||
'errors' => ['password' => 'اطلاعات ورود اشتباه است.']
|
||||
], 401);
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
$token = $user->createToken('auth_token')->plainTextToken;
|
||||
|
||||
return response()->json([
|
||||
'accessToken' => $token,
|
||||
'userData' => $user,
|
||||
'userAbilityRules' => [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
8
app/Http/Controllers/Controller.php
Normal file
8
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
32
app/Http/Controllers/OpenRouterController.php
Normal file
32
app/Http/Controllers/OpenRouterController.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class OpenRouterController extends Controller
|
||||
{
|
||||
public function sendMessage(Request $request)
|
||||
{
|
||||
$client = new Client();
|
||||
|
||||
$response = $client->post('https://openrouter.ai/api/v1/chat/completions', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . env('OPENROUTER_API_KEY'),
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'json' => [
|
||||
'model' => 'openai/gpt-4o',
|
||||
'messages' => [
|
||||
['role' => 'user', 'content' => $request->message]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$body = $response->getBody();
|
||||
$data = json_decode($body, true);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user