Files
firefly-iii/app/Http/Controllers/Auth/ForgotPasswordController.php

73 lines
2.2 KiB
PHP
Raw Normal View History

2016-09-16 06:19:40 +02:00
<?php
/**
* ForgotPasswordController.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
2016-09-16 06:19:40 +02:00
namespace FireflyIII\Http\Controllers\Auth;
use FireflyIII\Http\Controllers\Controller;
2017-03-25 13:41:17 +01:00
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
2016-09-16 06:19:40 +02:00
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Http\Request;
2017-01-04 09:15:41 +01:00
use Password;
2016-09-16 06:19:40 +02:00
/**
* Class ForgotPasswordController
*
* @package FireflyIII\Http\Controllers\Auth
*/
2016-09-16 06:19:40 +02:00
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
*/
public function __construct()
{
2016-09-17 09:50:40 +02:00
parent::__construct();
2016-09-16 06:19:40 +02:00
$this->middleware('guest');
}
/**
* Send a reset link to the given user.
*
2017-04-09 07:56:46 +02:00
* @param Request $request
*
* @param UserRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse
*/
2017-03-25 13:41:17 +01:00
public function sendResetLinkEmail(Request $request, UserRepositoryInterface $repository)
{
$this->validate($request, ['email' => 'required|email']);
// verify if the user is not a demo user. If so, we give him back an error.
$user = User::where('email', $request->get('email'))->first();
2017-03-25 13:41:17 +01:00
if (!is_null($user) && $repository->hasRole($user, 'demo')) {
return back()->withErrors(['email' => trans('firefly.cannot_reset_demo_user')]);
}
2017-03-25 13:41:17 +01:00
$response = $this->broker()->sendResetLink($request->only('email'));
if ($response === Password::RESET_LINK_SENT) {
return back()->with('status', trans($response));
}
// If an error was returned by the password broker, we will get this message
// translated so we can notify a user of the problem. We'll redirect back
// to where the users came from so they can attempt this process again.
2017-03-25 13:41:17 +01:00
return back()->withErrors(['email' => trans($response)]); // @codeCoverageIgnore
}
2016-09-16 06:19:40 +02:00
}