【问题标题】:How to Disable Verification using Laravel Socialite如何使用 Laravel Socialite 禁用验证
【发布时间】:2020-01-21 05:21:47
【问题描述】:

我在我的 Laravel 应用程序上使用了两个注册,默认的 Laravel 注册和 Laravel Socialite。两者都工作正常。当用户使用默认 Laravel 注册注册时,它会发送验证电子邮件,但它也会向 Laravel Socialite 发送验证电子邮件,我想禁用使用社交名流发送验证电子邮件但我不知道该怎么做。

这是我的Login Controller 中处理Socialite 的代码

public function redirectToGoogle()
        {
            return Socialite::driver('google')->redirect();
        }

        public function handleGoogleCallback()
        {
            try {

                $user = Socialite::driver('google')->user();

                $finduser = User::where('google_id', $user->id)->first();

                if($finduser){

                    Auth::login($finduser);

                    return redirect('/home');

                }else{
                    $newUser = User::create([
                        'name' => $user->name,
                        'email' => $user->email,
                        'google_id'=> $user->id
                    ]);

                    Auth::login($newUser);

                    return redirect()->back();
                }

            } catch (Exception $e) {
                return redirect('auth/google');
            }
}

【问题讨论】:

  • 我添加了'email_verified_at' => date('Y-m-d H:i:s') 来选择时间,但它不起作用
  • 您需要在数据库表中将 'email_verified_at' 设置为 CURRENT_TIMESTAMP,而不是从这里传递。

标签: laravel


【解决方案1】:

使用这个

$user=User::create([
                'name'=>$googleUser->name,
                'email'=>$googleUser->email,
                'google_id'=>$googleUser->id,
                'password'=>md5(rand(1,10000)),
            ]);
            $user->markEmailAsVerified();

【讨论】:

    【解决方案2】:

    尝试使用now() 辅助函数,例如:

    $newUser = User::create([
        'name' => $user->name,
        'email' => $user->email,
        'google_id'=> $user->id,
        'email_verified_at' => now(),
    ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-09
      • 2015-08-15
      • 2020-10-24
      相关资源
      最近更新 更多