3.0 DOCUMENTATION
NOTE: This version is in active development.

AUTHENTICATION COMPONENT

API:

The best way to authenticate is to use the commands. You can use the raw Eloquent but its more convenient to use the built-in commands for ease of use.

Authenticating a user:

On your controller:


// NOTE:
// Throttling feature is enabled by default

$commandDispatcher = app('Darryldecode\Backend\Base\Contracts\Bus\Dispatcher');

$result = $commandDispatcher->dispatchFromArray(
    'Darryldecode\Backend\Components\Auth\Commands\AuthenticateCommand',
    array(
        'email' => 'admin@gmail.com',
        'password' => 'admin'
    )
);

// if authentication is good
if( $result->isSuccessful() )
{
    // redirect to admin dashboard or any route you want
    // you may use Darryldecode\Backend\Utility\Helpers get get dashboard route
    return redirect()->intended(Helpers::getDashboardRoute());
}
else
{
    // if authentication fails
    return redirect()->back()->withInput(array(
        'email' => 'admin@gmail.com',
        'password' => 'admin'
    ))->withErrors(array('errors' => $result->getMessage()));
}

// Some useful methods
$result->isSuccessful(); // check if authentication was successful
$result->getStatusCode(); // the status code Ex 200, 401
$result->getMessage(); // the message (success or error)
    

Logging out a user:

You can use the typical logout, On your controller:


Auth::logout();

Built-in Middleware:

On your controller:


// if you want it for authenticated users only
$this->middleware('backend.authenticated');

// if you want it for non-authenticated users only
$this->middleware('backend.guest');

Backend Authentication Event Hooks:

EVENT: PARAMETERS PASSED: DESCRIPTION:
backend.auth.success
Param 1: User Object This event is triggered after successful authentication on backend and before any redirection.
backend.auth.logut
Param: N/A This event is triggered after successful logout on backend and before any redirection.
More documentation coming soon or you may help us improve the docs by making pull request here: https://github.com/darryldecode/laravelbackend-site