| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Devpri\Tinre; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Devpri\Tinre\Guards\TokenGuard; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Auth\RequestGuard; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Support\Facades\Auth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Support\Facades\Gate; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Support\ServiceProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class TinreServiceProvider extends ServiceProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * The policy mappings for the application. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     protected $policies = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         'Devpri\Tinre\Models\User' => 'Devpri\Tinre\Policies\UserPolicy', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         'Devpri\Tinre\Models\Url' => 'Devpri\Tinre\Policies\UrlPolicy', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         'Devpri\Tinre\Models\AccessToken' => 'Devpri\Tinre\Policies\AccessTokenPolicy', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * Perform post-registration booting of services. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 167 |  |     public function boot() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 167 |  |         $this->registerRoutes(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 167 |  |         $this->registerPolicies(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 167 |  |         $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'tinre'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 167 |  |         $this->loadJsonTranslationsFrom(resource_path('lang/vendor/tinre')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 167 |  |         $this->loadViewsFrom(__DIR__.'/../resources/views', 'tinre'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 167 |  |         $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 167 |  |         $this->listenEvents(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         // Publishing is only necessary when using the CLI. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 167 |  |         if ($this->app->runningInConsole()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 167 |  |             $this->bootForConsole(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 167 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * Register any package services. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 167 |  |     public function register() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 167 |  |         $this->mergeConfigFrom(__DIR__.'/../config/tinre.php', 'tinre'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 167 |  |         $this->registerTokenGuard(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 167 |  |         Tinre::addTranslation( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 167 |  |             resource_path('lang/vendor/tinre/'.app()->getLocale().'.json') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 167 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 167 |  |     protected function registerRoutes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 167 |  |         Tinre::routes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 167 |  |             ->withHomeRoute() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 167 |  |             ->withAuthenticationRoutes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 167 |  |             ->withRegisterRoutes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 167 |  |             ->withPasswordResetRoutes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 167 |  |             ->withVerificationRoutes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 167 |  |             ->withEmailChangeRoutes(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 167 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * Register the application's policies. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 167 |  |     public function registerPolicies() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 167 |  |         foreach ($this->policies as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 167 |  |             Gate::policy($key, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 167 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 167 |  |     protected function listenEvents() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 167 |  |         \Illuminate\Support\Facades\Event::listen( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 167 |  |             \Devpri\Tinre\Events\EmailChangeCreated::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 167 |  |             \Devpri\Tinre\Listeners\SendEmailChangeNotification::class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 167 |  |         \Illuminate\Support\Facades\Event::listen( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 167 |  |             \Devpri\Tinre\Events\UserRegistered::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 167 |  |             \Devpri\Tinre\Listeners\SendEmailVerificationNotification::class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 167 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * Get the services provided by the provider. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     public function provides() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         return ['tinre']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * Console-specific booting. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 118 | 167 |  |     protected function bootForConsole() | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |         // Publishing the configuration file. | 
            
                                                                        
                            
            
                                    
            
            
                | 121 | 167 |  |         $this->publishes([ | 
            
                                                                        
                            
            
                                    
            
            
                | 122 | 167 |  |             __DIR__.'/../config/tinre.php' => config_path('tinre.php'), | 
            
                                                                        
                            
            
                                    
            
            
                | 123 | 167 |  |         ], 'tinre-config'); | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 125 | 167 |  |         $this->publishes([ | 
            
                                                                        
                            
            
                                    
            
            
                | 126 | 167 |  |             __DIR__.'/../stubs/TinreServiceProvider.stub' => app_path('Providers/TinreServiceProvider.php'), | 
            
                                                                        
                            
            
                                    
            
            
                | 127 | 167 |  |         ], 'tinre-provider'); | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |         // Publishing the views. | 
            
                                                                        
                            
            
                                    
            
            
                | 130 | 167 |  |         $this->publishes([ | 
            
                                                                        
                            
            
                                    
            
            
                | 131 | 167 |  |             __DIR__.'/../resources/views/partials' => base_path('resources/views/vendor/tinre/partials'), | 
            
                                                                        
                            
            
                                    
            
            
                | 132 | 167 |  |         ], 'tinre-views'); | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |         // Publishing assets. | 
            
                                                                        
                            
            
                                    
            
            
                | 135 | 167 |  |         $this->publishes([ | 
            
                                                                        
                            
            
                                    
            
            
                | 136 | 167 |  |             __DIR__.'/../public' => public_path('vendor/tinre'), | 
            
                                                                        
                            
            
                                    
            
            
                | 137 | 167 |  |         ], 'tinre-assets'); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |         // Publishing the translation files. | 
            
                                                                        
                            
            
                                    
            
            
                | 140 | 167 |  |         $this->publishes([ | 
            
                                                                        
                            
            
                                    
            
            
                | 141 | 167 |  |             __DIR__.'/../resources/lang' => resource_path('lang/vendor/tinre'), | 
            
                                                                        
                            
            
                                    
            
            
                | 142 | 167 |  |         ], 'tinre-lang'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 167 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 167 |  |     protected function registerTokenGuard() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 167 |  |         Auth::resolved(function ($auth) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 | 112 |  |             $auth->extend('token', function ($app, $name, array $config) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 35 |  |                 return tap($this->makeTokenGuard(), function ($guard) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 35 |  |                     $this->app->refresh('request', $guard, 'setRequest'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 | 35 |  |                 }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 | 112 |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 | 167 |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 | 167 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 | 35 |  |     protected function makeTokenGuard() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 | 35 |  |         return new RequestGuard(function ($request) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 3 |  |             return (new TokenGuard( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 | 3 |  |                 $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 | 3 |  |             ))->user(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 35 |  |         }, $this->app['request']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 164 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 165 |  |  |  |