mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 16:37:31 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			84 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /**
 | |
|  * Invoice Ninja (https://invoiceninja.com).
 | |
|  *
 | |
|  * @link https://github.com/invoiceninja/invoiceninja source repository
 | |
|  *
 | |
|  * @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
 | |
|  *
 | |
|  * @license https://opensource.org/licenses/AAL
 | |
|  */
 | |
| 
 | |
| namespace App\Http\Middleware;
 | |
| 
 | |
| use App\Libraries\MultiDB;
 | |
| use App\Models\Client;
 | |
| use App\Models\ClientContact;
 | |
| use App\Models\CompanyToken;
 | |
| use Auth;
 | |
| use Closure;
 | |
| 
 | |
| class ContactKeyLogin
 | |
| {
 | |
|     /**
 | |
|      * Handle an incoming request.
 | |
|      *
 | |
|      * Sets a contact LOGGED IN if an appropriate client_hash is provided as a query parameter
 | |
|      * OR
 | |
|      * If the contact_key is provided in the route
 | |
|      * 
 | |
|      * @param  \Illuminate\Http\Request  $request
 | |
|      * @param  \Closure  $next
 | |
|      * @return mixed
 | |
|      */
 | |
|     public function handle($request, Closure $next)
 | |
|     {
 | |
|         info($request->segment(3));
 | |
|         info($request->route('contact_key'));
 | |
| 
 | |
|         if(Auth::guard('contact')->check())
 | |
|             Auth::guard('contact')->logout();
 | |
| 
 | |
|         if ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
 | |
| 
 | |
|             if (MultiDB::findAndSetDbByContactKey($request->segment(3))) {
 | |
|                 
 | |
|                 $client_contact = ClientContact::where('contact_key', $request->segment(3))->first();
 | |
|                 Auth::guard('contact')->login($client_contact, true);
 | |
|                 return redirect()->to('client/dashboard');
 | |
| 
 | |
|             }
 | |
| 
 | |
|         } 
 | |
|         else if ($request->has('contact_key')) {
 | |
| 
 | |
|             if($client_contact = ClientContact::where('contact_key', $request->segment(3))->first()){
 | |
|                 Auth::guard('contact')->login($client_contact, true);
 | |
|                 return redirect()->to('client/dashboard');
 | |
|             }
 | |
| 
 | |
|         }
 | |
|         else if($request->has('client_hash') && config('ninja.db.multi_db_enabled')){
 | |
| 
 | |
|             if (MultiDB::findAndSetDbByClientHash($request->input('client_hash'))) {
 | |
|                 
 | |
|                 $client = Client::where('client_hash', $request->input('client_hash'))->first();
 | |
|                 Auth::guard('contact')->login($client->primary_contact()->first(), true);
 | |
|                 return redirect()->to('client/dashboard');
 | |
| 
 | |
|             }
 | |
| 
 | |
|         }
 | |
|         else if($request->has('client_hash')){
 | |
| 
 | |
|             if($client = Client::where('client_hash', $request->input('client_hash'))->first()){
 | |
|                 Auth::guard('contact')->login($client->primary_contact()->first(), true);
 | |
|                 return redirect()->to('client/dashboard');
 | |
|             }
 | |
| 
 | |
|         }
 | |
| 
 | |
|         return $next($request);
 | |
|     }
 | |
| }
 |