mirror of
				https://github.com/BookStackApp/BookStack.git
				synced 2025-11-03 02:13:16 +03:00 
			
		
		
		
	Also added links to sign-in/register. Fixed links in emails sent out. Fixes #210 and #218.
		
			
				
	
	
		
			77 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace BookStack\Http\Controllers\Auth;
 | 
						|
 | 
						|
use BookStack\Http\Controllers\Controller;
 | 
						|
use Illuminate\Foundation\Auth\ResetsPasswords;
 | 
						|
use Illuminate\Http\Request;
 | 
						|
use Password;
 | 
						|
 | 
						|
class PasswordController extends Controller
 | 
						|
{
 | 
						|
    /*
 | 
						|
    |--------------------------------------------------------------------------
 | 
						|
    | Password Reset Controller
 | 
						|
    |--------------------------------------------------------------------------
 | 
						|
    |
 | 
						|
    | This controller is responsible for handling password reset requests
 | 
						|
    | and uses a simple trait to include this behavior. You're free to
 | 
						|
    | explore this trait and override any methods you wish to tweak.
 | 
						|
    |
 | 
						|
    */
 | 
						|
 | 
						|
    use ResetsPasswords;
 | 
						|
 | 
						|
    protected $redirectTo = '/';
 | 
						|
 | 
						|
    /**
 | 
						|
     * Create a new password controller instance.
 | 
						|
     */
 | 
						|
    public function __construct()
 | 
						|
    {
 | 
						|
        $this->middleware('guest');
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * Send a reset link to the given user.
 | 
						|
     *
 | 
						|
     * @param  \Illuminate\Http\Request  $request
 | 
						|
     * @return \Illuminate\Http\Response
 | 
						|
     */
 | 
						|
    public function sendResetLinkEmail(Request $request)
 | 
						|
    {
 | 
						|
        $this->validate($request, ['email' => 'required|email']);
 | 
						|
 | 
						|
        $broker = $this->getBroker();
 | 
						|
 | 
						|
        $response = Password::broker($broker)->sendResetLink(
 | 
						|
            $request->only('email'), $this->resetEmailBuilder()
 | 
						|
        );
 | 
						|
 | 
						|
        switch ($response) {
 | 
						|
            case Password::RESET_LINK_SENT:
 | 
						|
                $message = 'A password reset link has been sent to ' . $request->get('email') . '.';
 | 
						|
                session()->flash('success', $message);
 | 
						|
                return $this->getSendResetLinkEmailSuccessResponse($response);
 | 
						|
 | 
						|
            case Password::INVALID_USER:
 | 
						|
            default:
 | 
						|
                return $this->getSendResetLinkEmailFailureResponse($response);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Get the response for after a successful password reset.
 | 
						|
     *
 | 
						|
     * @param  string  $response
 | 
						|
     * @return \Symfony\Component\HttpFoundation\Response
 | 
						|
     */
 | 
						|
    protected function getResetSuccessResponse($response)
 | 
						|
    {
 | 
						|
        $message = 'Your password has been successfully reset.';
 | 
						|
        session()->flash('success', $message);
 | 
						|
        return redirect($this->redirectPath())->with('status', trans($response));
 | 
						|
    }
 | 
						|
}
 |