Page Access

When creating pages, administrators can specify access to the pages. Public pages can be accessed by anyone. Private pages can only be accessed by authenticated users. Protected pages can be accessed by anyone with the page password.

Protected Pages

When attempting to access a protected page, the PageLoader class checks the request for a password. If there is no password, then the session is checked to see if access has been granted for this page.

To access a protected page, either attach the page password to the url with the parameter "password", or of you wish to prompt users to enter a password, then create a route named 'page_login' and users will be redirected there. For example, you could create routes like this:

Route::get('/page_login/{page}', 'PageAccess@show')->name('page_login');
Route::post('/page_login', 'PageAccess@process')->name('check_access');

And the corresponding controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\View\View;
use Textstem\Models\WranglerPage;
use Illuminate\Validation\ValidationException;

class PageAccess extends Controller
{
    /**
     * Show the request access form
     *   $request
     *   $page
     *  
     */
    public function show(Request $request, WranglerPage $page): View
    {
        return view('requestaccess', ['page' => $page]);
    }

    /**
     * Process the request access form
     *   $request
     * @return \Illuminate\Http\RedirectResponse
     *  
     */
    public function process(Request $request)
    {
        $id = $request->get('id', '');
        $password = $request->get('password', '');
        $page = WranglerPage::where('id', $id)->where('password', $password)->first();
        if ($page) {
            $key = 'page_access_' . $page->id;
            $request->session()->put($key, 1);
            return redirect($page->url);
        } else {
            throw ValidationException::withMessages(['url' => 'This passcode is incorrect']);
        }
    }
}