如何解决Laravel 5.8 with Socialite用于Google登录成功注册或登录系统后,网站不会更改为登录状态
(Laravel 5.8 with Socialite用于Google登录)成功注册或登录系统后,网站不会更改为登录状态,如何检查出什么问题?
因此,设置已完成,这是我的登录控制器,希望User表有新数据,但没有数据,选择登录哪个gmail帐户的弹出窗口正确显示,如何检查出什么问题?显示弹出窗口后,如何选择Gmail帐户后实际登录?
<?PHP
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Socialite;
use App\User;
use Auth;
use Illuminate\Http\Request;
use Hash;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
public function redirectToProvider()
{
return Socialite::driver('google')->redirect();
}
public function handleProviderCallback()
{
try
{
$user = Socialite::driver('google')->user();
}
catch (\Exception $e)
{
return redirect('login');
}
$existingUser = User::where('email',$user->email)->first();
if($existingUser)
{
// log them in
auth()->login($existingUser,true);
}
else
{
// create a new user
$newUser = new User;
$newUser->name = $user->name;
$newUser->email = $user->email;
$newUser->google_id = $user->id;
$newUser->avatar = $user->avatar;
$newUser->avatar_original = $user->avatar_original;
$newUser->save();
auth()->login($newUser,true);
}
return redirect()->to('/');
}
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function login(Request $request)
{
$input = $request->all();
$this->validate($request,[
'email' => 'required|email','password' => 'required',]);
$user = User::where('email','=',$input['email'])->first();
if(auth()->attempt(array('email' => $input['email'],'password' => Hash::check($input['password'],$user->password))))
{
// dd('here 1');
if (auth()->user()->is_partner == 1) {
return redirect()->route('partner.home');
}else{
return redirect()->route('home');
}
}
else
{
// dd($input['password']);
return redirect()->route('login')->with('error','email-address And Password Are Wrong.');
}
}
}
解决方法
见我的:
plugins {
id 'org.springframework.boot' version '2.2.9.RELEASE'
}
ext {
springKafkaVersion = '2.4.8.RELEASE'
kafkaVersion = '2.4.1'
}
dependencies {
implementation "org.springframework.kafka:spring-kafka:$springKafkaVersion"
implementation "org.apache.kafka:kafka-clients:$kafkaVersion"
implementation "org.apache.kafka:kafka-streams:$kafkaVersion"
testImplementation "org.springframework.kafka:spring-kafka-test:$springKafkaVersion"
testImplementation "org.apache.kafka:kafka-clients:$kafkaVersion:test"
}
,
由env参数解决。.callback网址
GOOGLE_REDIRECT=https://yourdomain.com/login/google/callback
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。