| 
									
										
										
										
											2016-03-28 19:50:24 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2016-04-01 16:44:46 +02:00
										 |  |  | declare(strict_types = 1); | 
					
						
							| 
									
										
										
										
											2016-03-28 19:50:24 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * AttachUserRole.php | 
					
						
							| 
									
										
										
										
											2016-04-01 16:44:46 +02:00
										 |  |  |  * Copyright (C) 2016 thegrumpydictator@gmail.com | 
					
						
							| 
									
										
										
										
											2016-03-28 19:50:24 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This software may be modified and distributed under the terms | 
					
						
							|  |  |  |  * of the MIT license.  See the LICENSE file for details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Handlers\Events; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use FireflyIII\Events\UserRegistration; | 
					
						
							|  |  |  | use FireflyIII\Repositories\User\UserRepositoryInterface; | 
					
						
							|  |  |  | use Log; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class AttachUserRole | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package FireflyIII\Handlers\Events | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class AttachUserRole | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Create the event listener. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         //
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Handle the event. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  UserRegistration $event | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function handle(UserRegistration $event) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Log::debug('Trigger attachuserrole'); | 
					
						
							|  |  |  |         /** @var UserRepositoryInterface $repository */ | 
					
						
							|  |  |  |         $repository = app('FireflyIII\Repositories\User\UserRepositoryInterface'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // first user ever?
 | 
					
						
							|  |  |  |         if ($repository->count() == 1) { | 
					
						
							|  |  |  |             Log::debug('Will attach role.'); | 
					
						
							|  |  |  |             $repository->attachRole($event->user, 'owner'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 16:17:06 +02:00
										 |  |  | } |