javascript - How to send verification email with laravel's built in verification system with Gmail
785
With regular sign ups the user will receive a verification email. But gmail users they do not receive the email unless they click the resend button.
How do I make gmail users to receive the verification email without having to click the resend button when they register?
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
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();
Auth::loginUsingId($user->id);
}
return redirect()->to('/home');
} catch (Exception $e) {
return 'error';
}
}
}[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/gt4tM.png
Answer
Solution:
But 2 flags in DB, verified and is_email_sent. When user logs in check for verified if he is not, send email if is_email_sent false, otherwise log in user