PHP code example of browner12 / reauthenticate

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

    

browner12 / reauthenticate example snippets


protected $routeMiddleware = [
    'auth'           => \Illuminate\Auth\Middleware\Authenticate::class,
    'auth.basic'     => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings'       => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'can'            => \Illuminate\Auth\Middleware\Authorize::class,
    'guest'          => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle'       => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'reauthenticate' => \browner12\reauthenticate\Reauthenticate::class,
];

Route::get('reauthenticate', 'ReauthenticateController@reauthenticate')->name('reauthenticate');
Route::post('reauthenticate', 'ReauthenticateController@processReauthenticate')->name('reauthenticate.process');

namespace App\Http\Controllers;

use browner12\reauthenticate\Concerns\Reauthenticates;
use Illuminate\Http\Request;

class ReauthenticateController extends Controller
{
    use Reauthenticates;
    
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function reauthenticate()
    {
        //load view
        return view('main/auth/reauthenticate');
    }

    /**
     * @param \Illuminate\Http\Request             $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function processReauthenticate(Request $request)
    {
        //good password
        if ($url = $this->checkReauthenticationPassword($request->get('password'), $request->user()->password)){
        
            return redirect()->to($url);
        }
        
        //send back
        return back();
    }
}

Route::get('users', 'UserController')->middleware('reauthenticate');

class UserController extends Controller
{
    /**
     * constructor
     */
    public function __construct()
    {
        //parent
        parent::__construct();
    
        //middleware
        $this->middleware('auth');
    
        //reauthenticate
        $this->middleware('reauthenticate')->only(['index']);
    }
}
 php
'providers' => [
    browner12\reauthenticate\ReauthenticateServiceProvider::class,
];
 php
php artisan vendor:publish --provider="browner12\reauthenticate\ReauthenticateServiceProvider"
sh
php artisan make:controller ReauthenticateController