mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:37:33 -05:00 
			
		
		
		
	Test Gmail Sending using oauth (#3121)
* Reset DB connection after a DB scan in the same request * Testing Gmail Oauth Email
This commit is contained in:
		
							parent
							
								
									c71f49a6db
								
							
						
					
					
						commit
						bc85bcd747
					
				@ -49,10 +49,17 @@ class GmailTransportConfig
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/********************* We may need to fetch a new token on behalf of the client ******************************/
 | 
					/********************* We may need to fetch a new token on behalf of the client ******************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $query = [
 | 
				
			||||||
 | 
					            'email' => 'david@invoicninja.com',
 | 
				
			||||||
 | 
					            'oauth_provider_id'=>'google'
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $user = MultiDB::hasUser($query);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$transport = (new Swift_SmtpTransport('smtp.gmail.com', 587, 'tls'))
 | 
							$transport = (new Swift_SmtpTransport('smtp.gmail.com', 587, 'tls'))
 | 
				
			||||||
		    ->setAuthMode('XOAUTH2')
 | 
							    ->setAuthMode('XOAUTH2')
 | 
				
			||||||
		    ->setUsername('turbo124@gmail.com')
 | 
							    ->setUsername($user->email)
 | 
				
			||||||
		    ->setPassword('');
 | 
							    ->setPassword($user->oauth_user_token);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// set new swift mailer
 | 
							// set new swift mailer
 | 
				
			||||||
		Mail::setSwiftMailer(new \Swift_Mailer($transport));
 | 
							Mail::setSwiftMailer(new \Swift_Mailer($transport));
 | 
				
			||||||
 | 
				
			|||||||
@ -307,6 +307,8 @@ class LoginController extends BaseController
 | 
				
			|||||||
                'oauth_provider_id' => $provider
 | 
					                'oauth_provider_id' => $provider
 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            MultiDB::setDefaultDatabase();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            $account = CreateAccount::dispatchNow($new_account);
 | 
					            $account = CreateAccount::dispatchNow($new_account);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Auth::login($account->default_company->owner(), true);
 | 
					            Auth::login($account->default_company->owner(), true);
 | 
				
			||||||
 | 
				
			|||||||
@ -201,5 +201,10 @@ class MultiDB
 | 
				
			|||||||
        config(['database.default' => $database]);
 | 
					        config(['database.default' => $database]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static function setDefaultDatabase()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        config(['database.default' => config('ninja.db.default')]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -111,5 +111,6 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
 | 
				
			|||||||
   Route::post('support/messages/send', 'Support\Messages\SendingController');
 | 
					   Route::post('support/messages/send', 'Support\Messages\SendingController');
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Route::get('test_email', 'GmailTransportConfig');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Route::fallback('BaseController@notFound');
 | 
					Route::fallback('BaseController@notFound');
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user