我希望用户能够更新自己的密码。我在数据库中得到三个输入我有密码字段以及用户名和电子邮件。我真的不知道控制器的流量,希望你能帮助我。
我的控制员:
public function changepass() {
$user = Auth::user();
$rules = array(
'old_password' => 'required|alphaNum|between:4,16',
'password' => 'required|alphaNum|between:4,16|confirmed'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::action('HomeController@getpass', $user->id)->withErrors($validator);
} else {
if (!Hash::check(Input::get('old_password'), $user->password)) {
return Redirect::action('HomeController@getpass', $user->id)->withErrors('Old password does not match!');
} else {
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::action('HomeController@getpass', $user->id)->withMessage("Password has been changed successfully!");
}
}
我的观点:
@extends('master')
@section('content')
<div class="span8 well" style="opacity: 0.9">
<h4>Change password: </h4>
{{ Form::open(array('url' => 'changepass/', 'method'=>'POST')) }}
{{Form::hidden('id',Auth::user()->id)}}
<div class="form-group">
{{ Form::password('old_password', array('class'=>'form-control', 'placeholder'=>'Old Password')) }}<br>
{{ Form::password('new_password', array('class'=>'form-control', 'placeholder'=>'New Password')) }}<br>
{{ Form::password('confirm_new_password', array('class'=>'form-control', 'placeholder'=>'Confirm New Password')) }}
</div>
{{ Form::submit('Update', array('class' => 'btn btn-success')) }}
</div>
@stop
//路线
Route::post('changepass', 'HomeController@changepass');