2

I am trying to use the Laravel inbuilt password reset in my app where Laravel 5.1 acts as the backend api and Angular 1.3 for all front-end views. I have set-up the Password reset as per the docs where I have done the following:

1) Create the table

php artisan migrate

2) Added this to the route:

  Route::post('password/email', 'Auth/PasswordController@postEmail');
  Route::post('password/reset', 'Auth/PasswordController@postReset');

Since I will be using Angular to display frontend forms, I did not add the views for GET. I havent done any changes to the Auth/PasswordController.php and right now its just like the way it came. But when I test the above URL from Postman POST request, I am getting the error:

View [emails.password] not found.

How can I let Angular Handle the views and not have Laravel worry about the view? Do I have to have Laravel View for the inbuilt password reset to work? How do I approach this?

Neel
  • 9,352
  • 23
  • 87
  • 128

4 Answers4

3

Override the postEmail and postReset methods so that they return a JSON response (don't let it redirect). Subsequently post to /password/email and /password/reset from Angular via xhr.

Harmen
  • 22,092
  • 4
  • 54
  • 76
  • Thank you Harmen. Can you tell me where I can find the default `postEmail` and `postReset` methods so I can extend it? I can only see the `__construct` method inside the default `PasswordController.php`. Also, with the `View [emails.password] not found` error I was getting, I was wondering if the laravel is saying it cant find the form view page or the view to send the reminder email template? – Neel Aug 03 '15 at 10:17
  • 1
    Hi Neel, it is actually a trait (see https://github.com/laravel/framework/blob/5.0/src/Illuminate/Foundation/Auth/ResetsPasswords.php) so the methods are presumably not in the PasswordController. However, you can simply add them and they will override the trait methods. So copy the methods from the trait to the controller and change the redirects to responses – Harmen Aug 03 '15 at 10:21
  • look into app/Http/Controllers/Auth/PasswordController.php – Emeka Mbah Aug 03 '15 at 10:22
  • 1
    And `emails.password` refers to the email view indeed ;) it should be there in a vanilla laravel install – Harmen Aug 03 '15 at 10:24
  • aha... I understand now. I see the the `PasswordController` using `use Illuminate\Foundation\Auth\ResetsPasswords` trait. Thanks for that. I will now copy the method from the Trait and edit it further. Also thanks for confirming the `emails.password` error as well that it is referring to the email view. I will be setting the email view last. Since I have changed the default view path, perhaps laravel is unable to find the email view included in the vanilla laravel. I appreciate your help. I think I get the idea on how to go ahead. :) – Neel Aug 03 '15 at 10:29
3

Open app/Http/Controllers/Auth/PasswordController.php

<?php namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;

class PasswordController extends Controller
{

use ResetsPasswords;


//add and modify this methods as you wish:


 /**
 * Send a reset link to the given user.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function postEmail(Request $request)
{
    $this->validate($request, ['email' => 'required|email']);

    $response = Password::sendResetLink($request->only('email'), function (Message $message) {
        $message->subject($this->getEmailSubject());
    });

    switch ($response) {
        case Password::RESET_LINK_SENT:
            return redirect()->back()->with('status', trans($response));

        case Password::INVALID_USER:
            return redirect()->back()->withErrors(['email' => trans($response)]);
    }
}



 /**
 * Reset the given user's password.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function postReset(Request $request)
{
    $this->validate($request, [
        'token' => 'required',
        'email' => 'required|email',
        'password' => 'required|confirmed',
    ]);

    $credentials = $request->only(
        'email', 'password', 'password_confirmation', 'token'
    );

    $response = Password::reset($credentials, function ($user, $password) {
        $this->resetPassword($user, $password);
    });

    switch ($response) {
        case Password::PASSWORD_RESET:
            return redirect($this->redirectPath());

        default:
            return redirect()->back()
                        ->withInput($request->only('email'))
                        ->withErrors(['email' => trans($response)]);
    }
}

}
Emeka Mbah
  • 16,745
  • 10
  • 77
  • 96
0

Ceckout your path to views folder in app\bootstrap\cache\config.php at section "view"

'view' => 
  array (
    'paths' => 
    array (
      0 => '/home/vagrant/Code/app/resources/views',
    ),
    'compiled' => '/home/vagrant/Code/app/storage/framework/views',
  ),

this path MUST be at SERVER! not at you local mashine like "D:\WebServers\home\Laravel\app\bootstrap\cache", if you use the homestead. And You must use command like: "php artisan config:clear | cache" at SERVER!

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
0

I had the same problem than you. You could manage to change the view in config/auth.php if you have another one not in resources/views/emails/password.blade.php.

Because this view isn't created by default, that's why you got the error.

fxhereng
  • 11
  • 5