Laravel 5密码重置与角度视图

时间:2015-08-03 10:04:36

标签: angularjs laravel laravel-5 laravel-routing

我正在尝试在我的应用程序中使用Laravel内置密码重置,其中Laravel 5.1用作所有前端视图的后端api和Angular 1.3。我已根据docs设置密码重置,我已完成以下操作:

1)创建表

php artisan migrate

2)将此添加到路线:

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

由于我将使用Angular来显示前端表单,因此我没有为GET添加视图。我没有对Auth/PasswordController.php进行任何更改,现在就像它的方式一样。但是当我从Postman POST请求测试上述URL时,我收到错误:

View [emails.password] not found.

如何让Angular处理视图而不让Laravel担心视图?我是否必须使用Laravel View才能使内置密码重置工作?我该如何处理?

4 个答案:

答案 0 :(得分:3)

覆盖postEmailpostReset方法,以便它们返回JSON响应(不要让它重定向)。随后通过xhr从Angular发布到/password/email/password/reset

答案 1 :(得分:3)

打开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)]);
    }
}

}

答案 2 :(得分:0)

在app \ bootstrap \ cache \ config.php的“查看”部分中查看您的视图文件夹路径

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

这条路径必须在SERVER!不是你当地的mashine喜欢 “D:\ WebServers \ home \ Laravel \ app \ bootstrap \ cache”,如果你使用宅基地。 你必须在SERVER上使用如下命令:“php artisan config:clear | cache”。

答案 3 :(得分:0)

我遇到了和你相同的问题。如果您有另一个不在资源/ views / emails / password.blade.php中的视图,您可以设法更改config/auth.php中的视图。

因为默认情况下不会创建此视图,这就是您收到错误的原因。