我是laravel的新手。我已经使用 auth 命令创建了登录和注册表单。
我已经激活了用于登录的电子邮件验证。此外,我还使用基于以下链接的社交名流为 Gmail、Fb 等创建了社交登录。
https://www.tutsmake.com/laravel-6-google-login-tutorial-with-socialite-demo-example/
现在,我不需要对那些通过社交登录但手动注册的用户进行电子邮件验证。
我的家庭控制器
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(['auth', 'verified']);
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('frontend.index');
}
public function seedr()
{
$users=DB::table('users')->get();
return view('backend.seedr',['users'=>$users]);
}
}
我的社交控制器
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator,Redirect,Response,File;
use Socialite;
use App\User;
class SocialController extends Controller
{
public function redirect($provider)
{
//echo $provider;die;
return Socialite::driver($provider)->redirect();
}
public function callback($provider)
{
$getInfo = Socialite::driver($provider)->user();
$user = $this->createUser($getInfo,$provider);
auth()->login($user);
return redirect()->to('/home');
}
function createUser($getInfo,$provider){
$user = User::where('provider_id', $getInfo->id)->first();
if (!$user) {
//$mytime = Carbon::now();
$currenttime=date("Y-m-d h:i:s a", time());
$user = User::create([
'name' => $getInfo->name,
'email' => $getInfo->email,
'provider' => $provider,
'provider_id' => $getInfo->id,
]);
//die;
}
return $user;
}
}
偶然的你
Cats萌萌
精慕HU