2015-08-03 48 views
2

我尝试在我的应用程序中使用Laravel内置密码重置,其中Laravel 5.1充当后端api和Angular 1.3用于所有前端视图。我已经设置了密码重置为每docs,我也做了以下内容:Laravel 5带有角度视图的密码重置

1)创建表

php artisan migrate 

2)添加到了路线:

Route::post('password/email', 'Auth/[email protected]'); 
    Route::post('password/reset', 'Auth/[email protected]'); 

由于我将使用Angular来显示前端表单,因此我没有为GET添加视图。我没有对Auth/PasswordController.php进行任何更改,现在它就像它来了。但是,当我从邮递员测试上面的URL POST要求,我正在错误:

View [emails.password] not found.

我怎样才能让角处理的意见,并没有关于视图Laravel烦恼吗?我必须使用Laravel View才能使内置密码重置起作用吗?我如何解决这个问题?

回答

3

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

+0

谢谢哈门。你能告诉我在哪里可以找到默认的'postEmail'和'postReset'方法,所以我可以扩展它吗?我只能在默认的'PasswordController.php'中看到'__construct'方法。此外,与'查看[emails.password]找不到'错误我越来越,我想知道如果laravel是说它不能找到窗体视图页面或视图发送提醒电子邮件模板? – Neel

+1

嗨尼尔,它实际上是一个特质(见https://github.com/laravel/framework/blob/5.0/src/Illuminate/Foundation/Auth/ResetsPasswords.php),所以这些方法大概不在PasswordController中。但是,您可以简单地添加它们,它们将覆盖特征方法。因此,将方法从特征复制到控制器并将重定向更改为响应 – Harmen

+0

查看app/Http/Controllers/Auth/PasswordController.php – Digitlimit

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

} 
0

Ceckout你的路径视图的应用程序\引导\缓存\文件夹中的config.php在部分 “视图”

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

此路径必须是在服务器!如果你使用宅基地,那么你的本地mashine不会像 “D:\ WebServers \ home \ Laravel \ app \ bootstrap \ cache”。 并且您必须在服务器上使用如下命令:“php artisan config:clear | cache”!

0

我有和你一样的问题。如果您有另一个不在resources/views/emails/password.blade.php中,则可以设法更改config/auth.php中的视图。

因为这个视图不是默认创建的,所以你得到这个错误。