Oct 18, 2024
0
Level 1
how to use a send sms trait to create 2FA in filament dashbaord
I need to use a custom trait I was using to send OTP messages to sms by Restful API to create 2FA in filament. I couldn't custom the plugins and didn't know what to do. note that I'm using the Admin model as the filament auth guard
that's the Trait I'm using, can someone help me how to enable 2FA using this trait in filament
<?php
namespace App;
use GuzzleHttp\Client;
trait OTPmessageTrait
{
protected $client;
protected $baseUrl = '/api.oursms.com/api-a/msgs';
public function __construct()
{
$this->client = new Client();
}
public function sendOtp($recipients, $message)
{
try {
$response = $this->client->post($this->baseUrl, [
'form_params' => [
'username' => env('SMS_API_USERNAME'),
'token' => env('SMS_API_TOKEN'),
'src' => env('SMS_API_SENDER_ID'),
'dests' => $recipients, // Example: '96654XXXXXX,96656XXXXXX'
'body' => $message,
'priority' => 0,
'delay' => 0,
'validity' => 0,
'maxParts' => 0,
'dlr' => 0,
'prevDups' => 0,
]
]);
$responseBody = json_decode($response->getBody(), true);
return $responseBody;
} catch (\Exception $e) {
return ['error' => $e->getMessage()];
}
}
}
Please or to participate in this conversation.