我正在使用laravel框架几周以来,我正在建立一个litle网站。
现在,我有:
这是我的问题。我的身份验证效果很好,但是当我将用户重定向到患者列表页面时,该网址变为“index / auth”。
我的路线文件如下:
Route::get('index', array('as'=>'index', 'uses'=>'WUsersController@getIndex'));
Route::post('index/auth', array('uses'=>'WUsersController@postAuth'));
Route::get('patients', array('as'=>'patients', 'uses'=>'PatientsController@getPatientList'));
我的WUsersController看起来像:
public function getIndex() {
return View::make('wusers.index')
->with('title', 'Instant Access');
}
public function postAuth() {
$rules = array(
'email'=>'required|email',
'password'=>'required|alphaNum|min:4'
);
$validator = Validator::make(Input::all(), $rules);
$user = WUserModel::where('WUS_EMAIL', '=', Input::get('email'))->first();
if ($validator->fails()) {
return Redirect::route('index')
->withErrors($validator);
}
if ($user->WUS_PASSWORD == md5(Input::get('password'))) {
Session::put('login', $user->WUS_EMAIL);
return Redirect::route('patients')
->with('title', 'Patient List');
}
return Redirect::route('index')
->with('logError', 'login ou mot de passe incorrect');
}
这是“wusers.index”视图,格式为:
@section('content')
<div id="loginPage" data-role="page">
<div data-role="header">
<h1>InstantAccess</h1>
</div>
<div data-role="content" style="text-align:center">
{{ HTML::image('img/logo_keosys.png') }}
{{ Form::open(array('url'=>'index/auth', 'method'=>'POST', 'id'=>'loginForm')) }}
<p>
{{ $errors->first('email') }}
{{ $errors->first('password') }}
</p>
<div data-role="fieldcontain">
<p>
{{ Form::label('email', 'Email:') }}<br />
{{ Form::text('email') }}
</p>
<p>
{{ Form::label('passorwd', 'Password:') }}<br />
{{ Form::password('password') }}
</p>
</div>
<p>{{ Form::submit('Sign in', array('name'=>'login', 'value'=>'Valider')) }}</p>
@if (Session::has('logError'))
<p style="color: red;">{{ Session::get('logError') }}</p>
@endif
{{ Form::close() }}
</div>
</div>
@stop
这是我的PatientsController:
public function getPatientList() {
return View::make('patients.index', array(
'title'=>'Patients List',
'patients'=>DB::table('patient')
->join('study', 'patient.pat_id', '=', 'study.sty_pat_id')
->select('patient.pat_id', 'patient.pat_name', 'patient.pat_nip', 'patient.pat_birthdate', 'patient.pat_sex', 'study.sty_description', 'study.sty_datetime')
->orderBy('study.sty_datetime', 'desc')->take(10)->get())
);
}
现在已经有2个星期了解我的问题,在这个问题解决之前我无法继续在我的网站上工作。
如果您有任何疑问,请不要犹豫,谢谢您的帮助。
答案 0 :(得分:0)
我怀疑postAuth方法是您的问题,原因如下:
相反,您应该做的是通过电子邮件地址获取一个唯一的用户对象,并检查其密码是否与提供的密码相匹配并相应地重定向
public function postAuth() {
$rules = array(
'email'=>'required|email',
'password'=>'required|alphaNum|min:4'
);
$validator = Validator::make(Input::all(), $rules);
// Early dropout if we have an invalid email
if ($validator->fails()) {
return Redirect::route('index')
->withErrors($validator);
}
$user = WUserModel::where('WUS_EMAIL', '=', Input::get('email'))->first();
if($user->WUS_PASSWORD == md5(Input::get('password'))) {
Session::put('login', $user->WUS_EMAIL);
return Redirect::to('patients')
->with('title', 'Patient List');**
}
return Redirect::route('index')
->with('logError', 'login ou mot de passe incorrect');
}
作为一个侧面点,Laravel内置了身份验证,因此您可以使用它。你可能想要使用比MD5更强的东西来获取密码。
答案 1 :(得分:0)
当我正在测试一些事情以找出我的错误时,我意识到,在我显示表单的索引页面上,我有两个链接指向&#34;包含&#34; jquery和jquery-mobile。
看起来像:
@section('header')
<meta charset="utf-8">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1"/>
{{ HTML::style('css/jquery.mobile-1.3.0.min.css') }}
{{ HTML::script('js/jquery-1.9.1.min.js') }}
{{ HTML::script('js/jquery.mobile-1.3.0.min.js') }}
@stop
所以,当我删除这两个.js链接中的一个时,我丢失了我的表单的图形方面,但是url正确地重写...
我没有得到它,但问题似乎来自那些.js文件。