1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Minor fixes for Gmail API (#3125)

This commit is contained in:
David Bomba 2019-12-04 16:26:07 +11:00 committed by GitHub
parent 1b6ec9699a
commit a2cf42766d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 8 deletions

View File

@ -15,6 +15,7 @@ use App\Libraries\MultiDB;
use App\Models\User;
use Dacastro4\LaravelGmail\Services\Message\Mail;
use Illuminate\Mail\Transport\Transport;
use Swift_Mime_SimpleMessage;
/**
* GmailTransport
@ -42,7 +43,7 @@ class GmailTransport extends Transport
public function __construct(Mail $gmail, string $token)
{
$this->gmail = $gmail;
$this->token = $token
$this->token = $token;
}
@ -54,8 +55,8 @@ class GmailTransport extends Transport
$this->gmail->to($message->getTo());
$this->gmail->from($message->getFrom());
$this->gmail->subject($message->getSubject());
//$this->gmail->message($message->getBody());
$this->gmail->message($message->toString());
$this->gmail->message($message->getBody());
//$this->gmail->message($message->toString());
$this->gmail->cc($message->getCc());
$this->gmail->bcc($message->getBcc());
@ -65,3 +66,4 @@ class GmailTransport extends Transport
return $this->numberOfRecipients($message);
}
}

View File

@ -12,10 +12,12 @@
namespace App\Helpers\Mail;
use App\Libraries\MultiDB;
use App\Mail\SupportMessageSent;
use App\Models\User;
use App\Providers\MailServiceProvider;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Mail;
use Laravel\Socialite\Facades\Socialite;
/**
* GmailTransportConfig
@ -31,6 +33,10 @@ class GmailTransportConfig
];
$user = MultiDB::hasUser($query);
// $oauth_user = Socialite::driver('google')->stateless()->userFromToken($user->oauth_user_token);
// $user->oauth_user_token = $oauth_user->refreshToken;
// $user->save();
Config::set('mail.driver', 'gmail');
Config::set('services.gmail.token', $user->oauth_user_token);

View File

@ -11,8 +11,9 @@ class GmailTransportManager extends TransportManager
protected function createGmailDriver()
{
$token = $this->app['config']->get('services.gmail.token', []);
$mail = new Mail;
return new GmailTransport(Mail $mail, string $token);
return new GmailTransport($mail, string $token);
}
}

View File

@ -280,7 +280,7 @@ class LoginController extends BaseController
/* Handle existing users who attempt to create another account with existing OAuth credentials */
if($user = OAuth::handleAuth($socialite_user, $provider))
{
$user->oauth_user_token = $socialite_user->token;
$user->oauth_user_token = $socialite_user->refreshToken;
$user->save();
Auth::login($user, true);
@ -303,7 +303,7 @@ class LoginController extends BaseController
'password' => '',
'email' => $socialite_user->getEmail(),
'oauth_user_id' => $socialite_user->getId(),
'oauth_user_token' => $socialite_user->token,
'oauth_user_token' => $socialite_user->refreshToken,
'oauth_provider_id' => $provider
];