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:
David Bomba 2019-12-04 13:27:28 +11:00 committed by GitHub
parent c71f49a6db
commit bc85bcd747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View File

@ -49,10 +49,17 @@ class GmailTransportConfig
/********************* 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'))
->setAuthMode('XOAUTH2')
->setUsername('turbo124@gmail.com')
->setPassword('');
->setUsername($user->email)
->setPassword($user->oauth_user_token);
// set new swift mailer
Mail::setSwiftMailer(new \Swift_Mailer($transport));

View File

@ -307,6 +307,8 @@ class LoginController extends BaseController
'oauth_provider_id' => $provider
];
MultiDB::setDefaultDatabase();
$account = CreateAccount::dispatchNow($new_account);
Auth::login($account->default_company->owner(), true);

View File

@ -201,5 +201,10 @@ class MultiDB
config(['database.default' => $database]);
}
public static function setDefaultDatabase()
{
config(['database.default' => config('ninja.db.default')]);
}
}

View File

@ -111,5 +111,6 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
Route::post('support/messages/send', 'Support\Messages\SendingController');
});
Route::get('test_email', 'GmailTransportConfig');
Route::fallback('BaseController@notFound');