Моя функция входа в систему не работает (Вход в систему для собственного пользователя) Всякий раз, когда я нажимаю на кнопку входа в систему, выдается сообщение о том, что сервер перенаправляет запрос на этот адрес способом, который никогда не завершится.
страница перенаправлена неправильно
Изображение ошибки - https://i.stack.imgur.com/4OT1U.png
My Login Controller
namespace App\Http\Controllers\auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use Socialite;
use App\SocialRevolutionary;
use Validator;
use DB;
class SocialRevolutionaryLoginController extends Controller
{
protected $redirectTo = '/SocialRevolutionaries/Dashboard';
public function __construct()
{
$this->middleware('guest:social_revolutionary');
}
public function showLoginForm()
{
return view('auth.socialrevolutionarieslogin');
}
public function login(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
if(Auth::guard('social_revolutionary')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
return redirect()->intended(route('SocialRevolutionaries.Dashboard'));
}
return redirect()->back()->withInput($request->only('email', 'remember'));
}
public function redirectToProvider()
{
return Socialite::driver('google')->redirect();
}
/**
* Obtain the user information from GitHub.
*
* @return \Illuminate\Http\Response
*/
public function handleProviderCallback()
{
try {
$user = Socialite::driver('google')->stateless()->user();
} catch (Exception $e) {
return redirect()->route('SocialRevolutionaries/login/google');
}
$authUser = $this->createUser($user);
Auth::login($authUser, true);
return redirect()->route('SocialRevolutionaries.Dashboard');
}
public function createUser($user)
{
$authUser = SocialRevolutionary::where('google_id', $user->id)->first();
if ($authUser){
return $authUser;
}
return SocialRevolutionary::create([
'name' => $user->name,
'email' => $user->email,
'remember_token' => $user->token,
'google_id' => $user->id,
]);
}
// Facebook Login Starts
public function redirectToProviderf()
{
return Socialite::driver('facebook')->redirect();
}
/**
* Obtain the user information from GitHub.
*
* @return \Illuminate\Http\Response
*/
public function handleProviderCallbackf()
{
try {
$user = Socialite::driver('facebook')->stateless()->user();
} catch (Exception $e) {
return redirect()->route('SocialRevolutionaries/login/facebook');
}
$authUser = $this->createUser1($user);
Auth::login($authUser, true);
return redirect()->route('SocialRevolutionaries.Dashboard');
}
// return $user->name;
public function createUser1($user)
{
$authUser = SocialRevolutionary::where('facebook_id', $user->id)->first();
if ($authUser){
return $authUser;
}
return SocialRevolutionary::create([
'name' => $user->name,
'email' => $user->email,
'remember_token' => $user->token,
'facebook_id' => $user->id,
]);
}
}
My web. php
Route::prefix('SocialRevolutionaries')->group(function() {
Route::get('/login', 'auth\SocialRevolutionaryLoginController@showLoginForm')->name('socialrevolutionaries.login');
Route::post('/login', 'auth\SocialRevolutionaryLoginController@login')->name('socialrevolutionaries.login.submit');
Route::get('/', 'SocialRevolutionaryController@index')->name('SocialRevolutionaries.Dashboard');
});
My RedirectedIfAuthenticated. php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
switch ($guard) {
case 'admin':
if (Auth::guard($guard)->check()) {
return redirect()->route('admin.Dashboard');
}
break;
case 'social_revolutionary':
if (Auth::guard($guard)->check()) {
return redirect()->route('SocialRevolutionaries.Dashboard');
}
break;
case 'social_member':
if (Auth::guard($guard)->check()) {
return redirect()->route('SocialMember.Dashboard');
}
break;
default:
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
break;
}
return $next($request);
}
}
Модель SocialRevolutionary. php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Auth;
use Socialite;
class SocialRevolutionary extends Authenticatable
{
use Notifiable;
protected $guard = 'social_revolutionary';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'google_id', 'facebook_id'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}