GithubHelp home page GithubHelp logo

stagerightlabs / centaur Goto Github PK

View Code? Open in Web Editor NEW
60.0 4.0 25.0 146 KB

An opinionated implementation of Cartalyst's Sentinel package for Laravel

Home Page: http://stagerightlabs.com/projects/centaur

License: MIT License

JavaScript 1.09% PHP 75.06% Blade 23.86%

centaur's Introduction

Centaur

Tests Packagist Packagist Packagist

This package provides an opinionated implementation of Cartalyst Sentinel for Laravel.

If you are using an older version of Laravel, there are other versions available.

Installation

Install the Package Via Composer:

$ composer require srlabs/centaur

Add the Service Provider to your config/app.php file:

'providers' => array(
    ...
    Centaur\CentaurServiceProvider::class,
    ...
)

This package will not make use of automatic package discovery - you will need to register it manually. This is intentional.

Usage in New Applications

If you are starting a new Laravel 5.* application, this package provides a convenient way to get up and running with Cartalyst\Sentinel very quickly. Start by removing the default auth scaffolding that ships with a new Laravel 5.1 application:

$ php artisan centaur:spruce

Next, use Centaur's scaffolding command to create basic Auth Controllers and Views in your application:

$ php artisan centaur:scaffold

Publish the Cartalyst\Sentinel assets:

$ php artisan vendor:publish --provider="Cartalyst\Sentinel\Laravel\SentinelServiceProvider"

Run your database migrations:

$ php artisan migrate

Run the Database Seeder. You may need to re-generate the autoloader before this will work:

$ composer dump-autoload
$ php artisan db:seed --class="SentinelDatabaseSeeder"

You will also need to add these routes to your routes.php file:

// Authorization
Route::get('login', 'Auth\SessionController@getLogin')->name('auth.login.form');
Route::post('login', 'Auth\SessionController@postLogin')->name('auth.login.attempt');
Route::any('logout', 'Auth\SessionController@getLogout')->name('auth.logout');

// Registration
Route::get('register', 'Auth\RegistrationController@getRegister')->name('auth.register.form');
Route::post('register', 'Auth\RegistrationController@postRegister')->name('auth.register.attempt');

// Activation
Route::get('activate/{code}', 'Auth\RegistrationController@getActivate')->name('auth.activation.attempt');
Route::get('resend', 'Auth\RegistrationController@getResend')->name('auth.activation.request');
Route::post('resend', 'Auth\RegistrationController@postResend')->name('auth.activation.resend');

// Password Reset
Route::get('password/reset/{code}', 'Auth\PasswordController@getReset')->name('auth.password.reset.form');
Route::post('password/reset/{code}', 'Auth\PasswordController@postReset')->name('auth.password.reset.attempt');
Route::get('password/reset', 'Auth\PasswordController@getRequest')->name('auth.password.request.form');
Route::post('password/reset', 'Auth\PasswordController@postRequest')->name('auth.password.request.attempt');

// Users
Route::resource('users', 'UserController');

// Roles
Route::resource('roles', 'RoleController');

// Dashboard
Route::get('dashboard', function () {
    return view('Centaur::dashboard');
})->name('dashboard');

This is only meant to be a starting point; you can change them as you see fit. Make sure you read through your new Auth Controllers and understand how they work before you make any changes.

Centaur automatically installs Sentinel and registers the Sentinel, Activations, and Reminders aliases for you. Detailed instructions for using Sentinel can be found here.

If you do decide to make use of Laravel's Route::resource() option, you will need to use Form Method Spoofing to access some of those generated routes.

Usage in Existing Applications

If you already have already built out your auth views and controllers, the best way to make use of this package is to inject the AuthManager into your controllers and use it as a wrapper for Sentinel. Detailed information about the AuthManager methods can be found here.

Using Customized Middleware

It is possible that the behavior of the Middleware that comes with this package might not suit your exact needs. To adjust the middleware, create a copy of the problematic Centaur Middleware class in your app/Http/Middleware directory - this new class can be given any name you would like. You can then adjust the middleware references in your controllers and/or routes file to use the new class, or you can bind the new class to the Centaur Middleware class name in your App service provider, as such:

// app/providers/AppServiceProvider.php
/**
 * Register any application services.
 *
 * @return void
 */
public function register()
{
    $this->app->bind('Centaur\Middleware\SentinelGuest', function ($app) {
        return new \App\Http\Middleware\AlternativeGuestMiddleware;
    });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.