PHP code example of hamidmp / otp-manager

1. Go to this page and download the library: Download hamidmp/otp-manager 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/ */

    

hamidmp / otp-manager example snippets


        //config/otpmanage.php
        
        return [
        
        //...
        'message_provider'=>\App\Srvice\SMSProvider::class,
        //...
        
        ];
        

        //config/otpmanage.php
        
        return [
        
        //...
        'user_model'=>App\Models\User::class,
        //...
        
        ];
        

    // App/Http/Controllers/SiteController
    
    OTPManager::generateAndSendNewOTP($request);
    

    // App/Http/Controllers/SiteController
    
    $result = OTPManager::checkUserOTPAndVerification($request, $request->code);
    

    // App/Http/Controllers/SiteController
    
    $result = OTPManager::checkUserOTPAndVerification($request, $request->code);
    
    //just after verification
    if($result!==false){
        $user=User::find(1);
        OTPManager::assignUserTo($result,$user);
    }
    

    //routes/web.php
    
    
    Route::middleware('auth:otpmanager')
        ->group(function () {
            //...
  
            Route::get('/user',function (){
                $user = \request()->user();
                //or
                $user = \Illuminate\Support\Facades\Auth::user();
            });
  
        });
    

    //routes/web.php
    
    
    Route::middleware([\App\Http\Middleware\OTPManagerMiddleware::class])
        ->group(function () {
            //OTP verification has passed completely
              
        });
    
    Route::middleware('\App\Http\Middleware\OTPManagerMiddleware:false')
        ->group(function () {
            //OTP verification has passed its fist step at least (sending PIN code and having Token)
              
        });
    
shell script
    php artisan vendor:publish --tag otpmanager
    
shell script
    php artisan config:cache
    
shell script
    php artisan migrate