我正在使用form validation
与sentry
进行laravel4
。当我使用下面显示的代码时,错误被捕获,但Session
数据似乎没有被发送回View
以在登录时通知用户该问题。是否有我正在做的事情错误?我一直在通过我的应用程序在我的观点之间传递Session
数据。
这是我的Controller Action
:
public function handleLogin() {
try{
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
);
$user = Sentry::authenticate($credentials, false);
if($user){
if($user->hasAccess('admin')){//Admin Base Controller - Dashboard Display welcome
return Redirect::action('BookController@index')->with('message', $user->first_name . " " . $user->last_name);
}else{//User Base Controller - Dashboard Display
return Redirect::to('user/dashboard/')->with('message', 'Welcome User');
}
}
//Error with logging in redirect to login page and display error
}catch(Cartalyst\Sentry\Users\LoginRequiredException $e){
return View::make('home.login')->with('message', 'Login field is required.');
}catch(Cartalyst\Sentry\Users\PasswordRequiredException $e){
return View::make('home.login')->with('message', 'Password field is required. ');
}catch(Cartalyst\Sentry\Users\WrongPasswordException $e){
return View::make('home.login')->with('message', 'Wrong password, try again.');
}catch (Cartalyst\Sentry\Users\UserNotFoundException $e){
return View::make('home.login')->with('message', 'User was not found.');
}catch (Cartalyst\Sentry\Users\UserNotActivatedException $e){
return View::make('home.login')->with('message', 'User is not activated.');
}
}
这是我的View
:
@if(Session::has('message'))
<div class="alert alert-success alert-dissmissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<strong>Goodbye: </strong>{{ Session::get('message') }}
</div>
@endif
@if(Session::has('success'))
<div class="alert alert-success alert-dissmissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<strong>Success: </strong>{{ Session::get('success') }}
</div>
@endif
<div class="page-header">
<h1>Login</h1>
</div>
<!-- Login Form -->
<form action="{{action('HomeController@handleLogin')}}" method="post">
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" name="email"/>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password"/>
</div>
<input type="submit" value="Login" class="btn btn-primary"/>
</form>
@stop
答案 0 :(得分:0)
View::make()->with('foo', 'Error')
将$foo
作为变量传递而不是设置会话变量。
也许你可以试试:
@if(isset($message))
<div class="alert alert-success alert-dissmissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<strong>Goodbye: </strong>{{ $message }}
</div>
@endif