mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 16:37:31 -04:00 
			
		
		
		
	* Privacy Policy & TOS * configure additional dependency packages for redis and modules, middleware implementation for multi-db * Stub the signup
		
			
				
	
	
		
			70 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Libraries;
 | |
| 
 | |
| use App\Models\User;
 | |
| 
 | |
| /**
 | |
|  * Class MultiDB
 | |
|  * @package App\Libraries
 | |
|  */
 | |
| class MultiDB
 | |
| {
 | |
| 
 | |
|     /**
 | |
|      * @param $email
 | |
|      * @return bool
 | |
|      */
 | |
|     public static function checkUserEmailExists($email) : bool
 | |
|     {
 | |
|         if (config('auth.providers.users.driver') == 'eloquent') //default eloquent = single DB
 | |
|         {
 | |
|             return User::where(['email' => $email])->get()->count() >= 1 ?? false; // true >= 1 emails found / false -> == emails found
 | |
|         }
 | |
| 
 | |
|             //multi-db active
 | |
|             foreach (unserialize(MULTI_DBS) as $db)
 | |
|             {
 | |
|                 if(User::on($db)->where(['email' => $email])->get()->count() >=1) // if user already exists, validation will fail
 | |
|                     return true;
 | |
|             }
 | |
| 
 | |
|             return false;
 | |
| 
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param array $data
 | |
|      * @return bool
 | |
|      */
 | |
|     public static function hasUser(array $data)
 | |
|     {
 | |
|         if (config('auth.providers.users.driver') == 'eloquent') //default eloquent = single DB
 | |
|         {
 | |
|             return User::where($data)->first();
 | |
|         }
 | |
| 
 | |
|             foreach (unserialize(MULTI_DBS) as $db)
 | |
|             {
 | |
|                 self::setDB($db);
 | |
| 
 | |
|                 $user = User::where($data)->first();
 | |
| 
 | |
|                     if($user)
 | |
|                         return $user;
 | |
|             }
 | |
| 
 | |
|             return false;
 | |
|     }
 | |
| 
 | |
| 
 | |
|     /**
 | |
|      * @param $database
 | |
|      */
 | |
|     public static function setDB($database) : void
 | |
|     {
 | |
|         /* This will set the database connection for the request */
 | |
|         config(['database.default' => $database]);
 | |
|     }
 | |
| 
 | |
| } |