Guest User

Untitled

a guest
Dec 1st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public function callback()
  2. {
  3. try {
  4.  
  5.  
  6. $googleUser = Socialite::driver('google')->user();
  7. $existUser = User::where('email',$googleUser->email)->first();
  8.  
  9.  
  10. if($existUser) {
  11. Auth::loginUsingId($existUser->id);
  12. }
  13. else {
  14. $user = new User;
  15. $user->name = $googleUser->name;
  16. $user->email = $googleUser->email;
  17. $user->password = md5(rand(1,10000));
  18. $user->save();
  19. Auth::loginUsingId($user->id);
  20. }
  21. return redirect()->to('/home');
  22. }
  23. catch (Exception $e) {
  24. return 'error';
  25. }
  26. }
Add Comment
Please, Sign In to add comment