1
votes

I am using Laravel 5.2 and trying to make a password change form with its controller. I have added the following routes:

Route::get('changepassword', array('as' => 'reset.password', 'uses' => 'PasswordController@edit'));
Route::post('resetpasswordcomplete', array('as' => 'reset.password.complete', 'uses' => 'PasswordController@update'));

The Http\Controllers\Auth\PasswordController has the following methods:

public function edit() {
    return View::make('auth/passwords/change');
}

public function update() {
   $hasher = Sentinel::getHasher();

   $oldPassword = Input::get('old_password');
   $password = Input::get('password');
   $passwordConf = Input::get('password_confirmation');

   $user = Sentinel::getUser();

   if (!$hasher->check($oldPassword, $user->password) || $password != $passwordConf) {
       Session::flash('error', 'Check input is correct.');
       return View::make('auth/passwords/change');
   }

   Sentinel::update($user, array('password' => $password));

   return Redirect::to('/');
}

The view is as such:

@if (Session::get('error'))
    <div class="alert alert-error">
        {{ Session::get('error') }}
    </div>
@endif

{{ Form::open(array('route' => array('reset.password.complete'))) }}
{{ Form::password('old_password', array('placeholder'=>'current password', 'required'=>'required')) }}
{{ Form::password('password', array('placeholder'=>'new password', 'required'=>'required')) }}
{{ Form::password('password_confirmation', array('placeholder'=>'new password confirmation', 'required'=>'required')) }}
{{ Form::submit('Reset Password', array('class' => 'btn')) }}
{{ Form::close() }}

I get the ReflectionException error because I think the PasswordController is inside of the Auth folder and thus is only accessible to guests who want to reset their forgotten password using the auth scaffold. I would like to know how I could allow a logged in user to access this controller so that they could change their passwords if they wished?

EDIT: I tried doing the following after Alexy's solution: public function __construct()

{
    $this->middleware('guest', ['except' => ['resetpasswordcomplete', 'changepassword']]);
}

It still brings me back to home page.

1

1 Answers

1
votes

Change controller path in routes.php to:

Route::get('changepassword', array('as' => 'reset.password', 'uses' => 'Auth\PasswordController@edit'));
Route::post('resetpasswordcomplete', array('as' => 'reset.password.complete', 'uses' => 'Auth\PasswordController@update'));