2015-08-03 45 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中的視圖。

因爲這個視圖不是默認創建的,所以你得到這個錯誤。