如何在laravel中重置密码

时间:2017-08-18 10:15:51

标签: php laravel

这是我在下面的案例中找到的布局页面:

resetpassword.blade.php

@extends('layouts.default')
@section('content')
<div id="profileTeacher" type="view" class="demo-section k-header">
@include('layouts.common.flash-message')

   {!! Form::open(['url' => 'updatepassword',  'method' => 'post'])  !!} 
<form id="profileTeacherForm" method="post" action="" >
    <ul id="fieldlist" >
            <li>
            <label style="color:Green;font-size:15px">Update Password</label>
            </li> 
            <li>
             <table id="lessonPlanTable">

                 <tr>
                  <td><label> Current Password  </label> </td>
                  <td><input type="password" id="curr_password" name="curr_password"  class="k-textbox"/></td>
                  </tr>
                  <tr>
                  <td><label> New Password </label> </td>
                  <td><input  type="password" id="new_password" name="new_password" class="k-textbox"/></td>
                  </tr>

                 <!--tr>
                  <td><label> Confirm Password </label> </td>
                  <td><input type="password" id="confm_password" name="confm_password"  class="k-textbox"/  ></td>
                  </tr-->
                  </table>
                </li>
        <li><br>
            <button id="updateTeacherProfile" class="k-button k-primary" 
type="submit">Update</button>&nbsp;&nbsp;
              </li>
        <br><br>

    </ul>
 </form>

 </div>
 @stop

StudentController.php

 public function UpdatePassword(Request $request)
{
    $curr_password = $request->curr_password;
    $new_password  = $request->new_password;


if(!Hash::check($curr_password,Auth::user()->password)){
echo 'The specified password does not match';
}
else{
    $request->user()->fill(['password' => Hash::make($new_password)])->save;
    echo 'Updated Successfully';

 } 

Route.php

Route::get('/studentresetpassword', function () {
return view('layouts.student.resetpassword');
});


Route::post('/updatepassword ', 'Student\StudentController@UpdatePassword');

此文件中没有此类错误。所有的过程都完成没有得到任何错误。当我把当前密码错误时,它也给回显消息好,当我输入当前和新密码时也给出一条回应消息“已成功更新”。但是在表级别更新不能做完了..请给我一个解决方案。

2 个答案:

答案 0 :(得分:4)

您的StudentController.php应如下:

public function UpdatePassword(Request $request)
{
    $curr_password = $request->curr_password;
    $new_password  = $request->new_password;


if(!Hash::check($curr_password,Auth::user()->password)){
echo 'The specified password does not match';
}
else{
    $request->user()->fill(['password' => Hash::make($new_password)])->save();
    echo 'Updated Successfully';

 }

答案 1 :(得分:0)

public function resetPassword(Request $request)
{

    if (!Hash::check(Input::get('currentPassword'), \Auth::user()->password)) {
        return Redirect::back()->withErrors(['currentPassword' => 'Incorrect password']);
    }

    $this->validate($request, [
        //'currentPassword' => 'required|min:6',
        'password' => 'required|min:6|confirmed',
    ]);

    $input = \Input::all();

    $user = \Auth::user();
    $user->password = bcrypt($input['password']);
    $user->save();        

    Session::flash('flash_suceess_message', 'Your password reset successfully!');
    return redirect('/home');
}