{"id":109,"date":"2016-12-19T21:04:07","date_gmt":"2016-12-19T18:04:07","guid":{"rendered":"http:\/\/antyat.ru\/?p=109"},"modified":"2016-12-19T21:04:07","modified_gmt":"2016-12-19T18:04:07","slug":"centaur-an-opinionated-implementation-of-cartalyst-sentinel-for-laravel-5","status":"publish","type":"post","link":"http:\/\/antyat.ru\/?p=109","title":{"rendered":"Centaur  &#8212; An opinionated implementation of Cartalyst Sentinel for Laravel 5"},"content":{"rendered":"<h2>Installation<\/h2>\n<p><strong>Install the Package Via Composer:<\/strong><\/p>\n<pre><code class=\"language-shell\">$ composer require srlabs\/centaur<\/code><\/pre>\n<p><strong>Add the Service Provider to your <code>config\/app.php<\/code> file:<\/strong><\/p>\n<pre><code class=\"language-php hljs\"><span class=\"hljs-string\">'providers'<\/span> =&gt; <span class=\"hljs-keyword\">array<\/span>(\r\n    ...\r\n    Centaur\\CentaurServiceProvider::class, \r\n    ...\r\n)<\/code><\/pre>\n<h2>Usage in New Applications<\/h2>\n<p>If you are starting a new Laravel 5.1 application, this package provides a convenient way to get up and running with <code>Cartalyst\\Sentinel<\/code> very quickly. Start by removing the default auth scaffolding that ships with a new Laravel 5.1 application:<\/p>\n<pre><code class=\"language-shell\">$ php artisan centaur:spruce<\/code><\/pre>\n<p>Next, use Centaur&#8217;s scaffolding command to create basic Auth Controllers and Views in your application:<\/p>\n<pre><code class=\"language-shell\">$ php artisan centaur:scaffold<\/code><\/pre>\n<p>Publish the <code>Cartalyst\\Sentinel<\/code> assets:<\/p>\n<pre><code class=\"language-shell\">$ php artisan vendor:publish --provider=\"Cartalyst\\Sentinel\\Laravel\\SentinelServiceProvider\"<\/code><\/pre>\n<p>Run your database migrations:<\/p>\n<pre><code class=\"language-shell\">$ php artisan migrate<\/code><\/pre>\n<p>Run the Database Seeder. You may need to re-generate the autoloader before this will work:<\/p>\n<pre><code class=\"language-shell\">$ composer dump-autoload\r\n$ php artisan db:seed --class=\"SentinelDatabaseSeeder\"<\/code><\/pre>\n<p>You will also need to add these routes to your <code>routes.php<\/code> file:<\/p>\n<pre><code class=\"language-php hljs\"><span class=\"hljs-comment\">\/\/ Authorization<\/span>\r\nRoute::get(<span class=\"hljs-string\">'\/login'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.login.form'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\SessionController@getLogin'<\/span>]);\r\nRoute::post(<span class=\"hljs-string\">'\/login'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.login.attempt'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\SessionController@postLogin'<\/span>]);\r\nRoute::get(<span class=\"hljs-string\">'\/logout'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.logout'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\SessionController@getLogout'<\/span>]);\r\n\r\n<span class=\"hljs-comment\">\/\/ Registration<\/span>\r\nRoute::get(<span class=\"hljs-string\">'register'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.register.form'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\RegistrationController@getRegister'<\/span>]);\r\nRoute::post(<span class=\"hljs-string\">'register'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.register.attempt'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\RegistrationController@postRegister'<\/span>]);\r\n\r\n<span class=\"hljs-comment\">\/\/ Activation<\/span>\r\nRoute::get(<span class=\"hljs-string\">'activate\/{code}'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.activation.attempt'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\RegistrationController@getActivate'<\/span>]);\r\nRoute::get(<span class=\"hljs-string\">'resend'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.activation.request'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\RegistrationController@getResend'<\/span>]);\r\nRoute::post(<span class=\"hljs-string\">'resend'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.activation.resend'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\RegistrationController@postResend'<\/span>]);\r\n\r\n<span class=\"hljs-comment\">\/\/ Password Reset<\/span>\r\nRoute::get(<span class=\"hljs-string\">'password\/reset\/{code}'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.password.reset.form'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\PasswordController@getReset'<\/span>]);\r\nRoute::post(<span class=\"hljs-string\">'password\/reset\/{code}'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.password.reset.attempt'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\PasswordController@postReset'<\/span>]);\r\nRoute::get(<span class=\"hljs-string\">'password\/reset'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.password.request.form'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\PasswordController@getRequest'<\/span>]);\r\nRoute::post(<span class=\"hljs-string\">'password\/reset'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'auth.password.request.attempt'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-string\">'Auth\\PasswordController@postRequest'<\/span>]);\r\n\r\n<span class=\"hljs-comment\">\/\/ Users<\/span>\r\nRoute::resource(<span class=\"hljs-string\">'users'<\/span>, <span class=\"hljs-string\">'UserController'<\/span>);\r\n\r\n<span class=\"hljs-comment\">\/\/ Roles<\/span>\r\nRoute::resource(<span class=\"hljs-string\">'roles'<\/span>, <span class=\"hljs-string\">'RoleController'<\/span>);\r\n\r\n<span class=\"hljs-comment\">\/\/ Dashboard<\/span>\r\nRoute::get(<span class=\"hljs-string\">'dashboard'<\/span>, [<span class=\"hljs-string\">'as'<\/span> =&gt; <span class=\"hljs-string\">'dashboard'<\/span>, <span class=\"hljs-string\">'uses'<\/span> =&gt; <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span> <\/span>{\r\n    <span class=\"hljs-keyword\">return<\/span> view(<span class=\"hljs-string\">'centaur.dashboard'<\/span>);\r\n}]);<\/code><\/pre>\n<p>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.<\/p>\n<p>Centaur automatically installs Sentinel and registers the <code>Sentinel<\/code>, <code>Activations<\/code>, and <code>Reminders<\/code> aliases for you. Detailed instructions for using Sentinel <a href=\"https:\/\/cartalyst.com\/manual\/sentinel\/2.0\">can be found here<\/a>.<\/p>\n<h2>Usage in Existing Applications<\/h2>\n<p>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 <code>AuthManager<\/code> into your controllers and use it as a wrapper for Sentinel. Detailed information about the <code>AuthManager<\/code> methods and responses <a href=\"https:\/\/github.com\/SRLabs\/Centaur\/wiki\/AuthManager-Methods-and-Responses\">can be found here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installation Install the Package Via Composer: $ composer require srlabs\/centaur Add the Service Provider to your config\/app.php file: &#8216;providers&#8217; =&gt; array( &#8230; Centaur\\CentaurServiceProvider::class, &#8230; ) Usage in New Applications If you are starting a new Laravel 5.1 application, this package provides a convenient way to get up and running with Cartalyst\\Sentinel very quickly. Start by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=109"}],"version-history":[{"count":1,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":110,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions\/110"}],"wp:attachment":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}