cerbero/auth

Laravel module to implement the authentication system into your applications.

1.6.4 2015-12-28 13:20 UTC

This package is auto-updated.

Last update: 2024-11-04 22:11:20 UTC


README

Auth

Author Build Status Latest Version Software License Code Climate Quality Score Gratipay

SensioLabsInsight

Auth is a Laravel package to quickly implement the authentication system into your applications, avoiding you to reinvent the wheel every time you start a new project and letting you customize every single aspect of the process.

This package is intended to be a more customizable alternative to the authentication system shipped by Laravel out of the box and also includes some security features like honeypot and login throttling.

Features

List of features included in this package:

  • Login
  • Registration
  • Password reset
  • Logout
  • Full customization
  • CSRF protection
  • Honeypot trap
  • Login throttling
  • Event dispatching

Install

Run this command in your application root:

composer require cerbero/auth

Add the service provider to the providers list in config/app.php:

Cerbero\Auth\AuthServiceProvider::class,

Add the following route middleware in app/Http/Kernel.php:

'honeypot' => \Cerbero\Auth\Http\Middleware\Honeypot::class,

And then run these two commands in your terminal:

php artisan vendor:publish --provider="Cerbero\Auth\AuthServiceProvider”
php artisan migrate

Now you have the database migrated with the users table and can customize the behavior of the authentication system by editing the file config/_auth.php as well as modify/translate the messages in resources/lang/packages.

Finally, in order to display custom messages to the users, add the DisplaysExceptions trait to your exceptions handler:

use Cerbero\Auth\Exceptions\DisplaysExceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler {

	use DisplaysExceptions;

	public function render($request, Exception $e)
	{
		if($printable = $this->displayExceptions($e)) return $printable;

		return parent::render($request, $e);
	}

}

So now you can display the custom messages in your views:

@if ($error = session('error'))
	<div class="alert alert-danger">{{ $error }}</div>
@elseif ($success = session('success'))
	<div class="alert alert-success">{{ $success }}</div>
@endif

Events

All authentication processes are preceded and followed by events to provide an easy way to extend the package functionalities. The following list shows all the available events:

  • auth.login.start
  • auth.login.end
  • auth.logout.start
  • auth.logout.end
  • auth.register.start
  • auth.register.end
  • auth.recover.start
  • auth.recover.end
  • auth.reset.start
  • auth.reset.end