PHP code example of masoudghadimi / two-factor-auth

1. Go to this page and download the library: Download masoudghadimi/two-factor-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

masoudghadimi / two-factor-auth example snippets



protected $fillable = [
     'name',
     'email',
     'password',
     'phone_number',
     'two_factor_type'
];



public function verifyCodes()
{
    return $this->hasMany(VerifyCode::class);
}


use TwoFactorAuthenticate;

protected function authenticated(Request $request, $user)
{
     return $this->loggedIn($request , $user);
}



class SmsVerifyCodeChannel
{
    public function send($notifiable, Notification $notification)
    {
        if (! method_exists($notification , 'toSendVerifyCode')) {
            throw new \Exception('toSendVerifyCode not found');
        }

        $data = $notification->toSendVerifyCode($notifiable);

        $message = $data['message'];
        $phone = $data['number'];

        try{
            $lineNumber = 1111111;
            $api = new \Ghasedak\GhasedakApi('token');
            $api->SendSimple($phone, $message, $lineNumber);
        }
        catch(ApiException $e){
            echo $e->errorMessage();
        }
        catch(HttpException $e){
            echo $e->errorMessage();
        }
    }
}



'notificationsChannels' => \App\channels\SmsVerifyCodeChannel::class,