mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-01 20:17:35 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			69 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php namespace App\Listeners;
 | |
| 
 | |
| use Auth;
 | |
| use Carbon;
 | |
| use Session;
 | |
| use App\Events\UserLoggedIn;
 | |
| use App\Events\UserSignedUp;
 | |
| use App\Ninja\Repositories\AccountRepository;
 | |
| use App\Libraries\HistoryUtils;
 | |
| 
 | |
| /**
 | |
|  * Class HandleUserLoggedIn
 | |
|  */
 | |
| class HandleUserLoggedIn
 | |
| {
 | |
| 
 | |
|     /**
 | |
|      * @var AccountRepository
 | |
|      */
 | |
|     protected $accountRepo;
 | |
| 
 | |
|     /**
 | |
|      * Create the event handler.
 | |
|      *
 | |
|      * @param AccountRepository $accountRepo
 | |
|      */
 | |
|     public function __construct(AccountRepository $accountRepo)
 | |
|     {
 | |
|         $this->accountRepo = $accountRepo;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Handle the event.
 | |
|      *
 | |
|      * @param  UserLoggedIn  $event
 | |
|      *
 | |
|      * @return void
 | |
|      */
 | |
|     public function handle(UserLoggedIn $event)
 | |
|     {
 | |
|         $account = Auth::user()->account;
 | |
| 
 | |
|         if (empty($account->last_login)) {
 | |
|             event(new UserSignedUp());
 | |
|         }
 | |
| 
 | |
|         $account->last_login = Carbon::now()->toDateTimeString();
 | |
|         $account->save();
 | |
| 
 | |
|         $users = $this->accountRepo->loadAccounts(Auth::user()->id);
 | |
|         Session::put(SESSION_USER_ACCOUNTS, $users);
 | |
|         HistoryUtils::loadHistory($users ?: Auth::user()->id);
 | |
| 
 | |
|         $account->loadLocalizationSettings();
 | |
| 
 | |
|         if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
 | |
|             Session::flash('warning', trans('texts.iphone_app_message', ['link' => link_to(NINJA_IOS_APP_URL, trans('texts.iphone_app'))]));
 | |
|         }
 | |
| 
 | |
|         // if they're using Stripe make sure they're using Stripe.js
 | |
|         $accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE);
 | |
|         if ($accountGateway && ! $accountGateway->getPublishableStripeKey()) {
 | |
|             Session::flash('warning', trans('texts.missing_publishable_key'));
 | |
|         } elseif ($account->isLogoTooLarge()) {
 | |
|             Session::flash('warning', trans('texts.logo_too_large', ['size' => $account->getLogoSize() . 'KB']));
 | |
|         }
 | |
|     }
 | |
| }
 |