我有一个login.blade.php,所以当用户访问“project.test / login”时,他有一个电子邮件和密码字段来登录 .
我还有一个header.blade.php,它有主菜单,在这个主菜单中有一个链接“Create congress” . 如果用户未经过身份验证并单击“创建 Session ”,则他不应该访问该页面,他应该被重定向到登录页面 . 登录成功后,他应该被重定向到“创建大会”页面 .
这工作正常 .
Doubt:
但是当用户访问“http://project.test/congress/1/congresstest/registration”时,我也有"registration.blade.php" . 当用户访问此页面时,如果未经过身份验证,则会显示以下消息:
@if(!\Auth::check())
<div class="alert alert-info" role="alert">
<span>
Already have an account?
<a data-toggle="modal"
data-target=".bd-example-modal-lg"
class="font-weight-bold" href="">Login.</a>
</span>
</div>
@endif
如果用户在登录时单击,则会显示模式,因此用户可以插入电子邮件和密码,如果成功登录,模式应该关闭,应该将其重定向到同一个注册页面 .
问题是,如果用户在此页面中成功登录“http://project.test/congress/1/congresstest/registration " with the form in the modal he is redirected to the "创建大会”页面而不是停留在注册页面中 . 你知道如何纠正这个问题吗?
Relevant code for the question:
Login.blade.php:
<form class="clearfix" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group col-12 px-0">
<label for="inputEmail4">Email</label>
<input type="email" class="form-control" value="{{ old('email') }}" name="email" required autofocus>
</div>
<div class="form-group col-12 px-0">
<label for="inputEmail4">Password</label>
<input type="password" class="form-control" name="password" required>
</div>
<button type="submit">Login</button>
</form>
LoginController:
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function authenticated(Request $request, $user)
{
return redirect()->intended($this->redirectTo);
}
}
header.blade.php 主菜单中有一个创建新 Session 的链接:
<li>
<a href="{!! route('congress.create') !!}"> Create Congress </a>
</li>
Modal with the login form:
<div class="modal fade bd-example-modal-lg" id="modal2" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Login</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
<form class="clearfix" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group col-12 px-0">
<label for="inputEmail4">Email</label>
<input type="email" class="form-control" value="{{ old('email') }}" name="email" required autofocus>
</div>
<div class="form-group col-12 px-0">
<label for="inputEmail4"
class="text-heading font-weight-semi-bold">Password
<a href="{{ route('password.request') }}" class="text-gray ml-1" style="text-decoration: underline">
<small>Recover Password</small></a> </label>
<input type="password" class="form-control" name="password" required>
</div>
<button type="submit" class="btn btn-primary btn d-block w-100">Login</button>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
路线:
Route::get('/', [
'uses' => 'FrontController@index',
'as' =>'index'
]);
// Auth routes
Auth::routes();
Route::get('auth/{provider}/callback', [
'uses' => 'OauthController@handleProviderCallback',
]);
// route to the registration page
Route::post('/congress/{id}/{slug?}/registration', [
'uses' => 'RegistrationController@storeQuantity',
'as' =>'congresses.registration'
]);
Route::group(['prefix' => '', 'middleware' => 'auth'], function(){
// route to the create congress page
Route::get('/congress/create', [
'uses' => 'CongressController@create',
'as' => 'congress.create'
]);
}
CongressController:
class CongressController extends Controller
{
public function create()
{
return view('congresses.create')->with('categories', Category::all());
}
}
1 回答
你需要使用session,在你的congresstest创建中添加以下内容
然后成功登录: