我正在尝试向使用其gmail登录的gmail用户发送验证电子邮件。我的问题是,定期注册会发送验证电子邮件,但使用gmail注册不会,除非您单击发送验证电子邮件。 / p>
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Iluminate\Auth\Notifications\MustVerifyEmail;
use App\User;
use Socialite;
use Auth;
use Exception;
class GoogleAuth extends Controller
{
public function redirectToProvider()
{
return Socialite::driver('google')->redirect();
}
public function handleProviderCallback()
{
try {
$googleUser = Socialite::driver('google')->user();
$existUser = User::where('email', $googleUser->email)->first();
if ($existUser) {
Auth::loginUsingId($existUser->id);
} else {
$user = new User;
$user->name = $googleUser->name;
$user->email = $googleUser->email;
$user->google_id = $googleUser->id;
$user->password = md5(rand(1, 10000));
$user->save();
$user->notify(new Notifications\VerifyEmail);
Auth::loginUsingId($user->id);
}
return redirect()->to('/home');
} catch (Exception $e) {
return redirect('/register?tryagain');
}
}
}