[英]routing url rewrite with laravel 4
I'm using laravel framework since a few weeks now and i'm building a litle website with it. 从几周以来,我一直在使用laravel框架,并且正在使用它构建一个litle网站。
For now, I have: 现在,我有:
Here is my problem. 这是我的问题。 My authentication works well, but when I'm redirecting the user to the patient list page, the url become "index/auth". 我的身份验证效果很好,但是当我将用户重定向到患者列表页面时,URL变为“ index / auth”。
My route file looks like : 我的路线文件如下所示:
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'));
My WUsersController looks like : 我的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');
}
this is the "wusers.index" view with the form : 这是“ 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 @停
and this is my PatientsController : 这是我的PatientController:
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())
);
}
It's been 2 weeks I'm on that problem now, I cannot continue to work on my website till this problem is solved. 我现在已经有2周的时间解决此问题,在解决此问题之前,我无法继续在我的网站上工作。
If you have any question, don't hesitate, and thanks for your help. 如有任何疑问,请不要犹豫,感谢您的帮助。
I suspect the postAuth method is your issue for the following reasons: 我怀疑postAuth方法是您的问题,原因如下:
Instead what you should be doing is getting out a unique user object via the email address and checking if its password matches the one provided and redirecting accordingly 相反,您应该做的是通过电子邮件地址找到一个唯一的用户对象,并检查其密码是否与提供的密码匹配,并相应地重定向
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');
}
As a side point Laravel has Authentication built in so you could just use that. 另外,Laravel内置了身份验证,因此您可以使用它。 And you probably want to be using something stronger than MD5 for passwords. 您可能希望使用比MD5更强大的密码。
As I was testing things to find out what was my mistake, I realized that, on my index page which display the form, I have two links to "includes" jquery and jquery-mobile. 当我测试事物以找出我的错误时,我意识到,在显示表单的索引页面上,我有两个链接到“ includes” jquery和jquery-mobile。
it looks like: 看起来像:
@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
So, when I remove one of those two .js links, I lose the graphical aspect of my form, but the url is rewrite properly... 因此,当我删除这两个.js链接之一时,我失去了表单的图形外观,但是url被正确重写了...
I don't get it, but the problem seems to come from those .js file. 我不明白,但是问题似乎来自那些.js文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.