2016-12-14 05:06:15 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class ForgotPasswordController extends Controller
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Password Reset Controller
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| This controller is responsible for handling password reset emails and
|
|
|
|
| includes a trait which assists in sending these notifications from
|
|
|
|
| your application to your users. Feel free to explore this trait.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
use SendsPasswordResetEmails;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('guest');
|
2021-10-08 15:53:32 -07:00
|
|
|
$this->middleware('throttle:5,1', ['except' => 'showLinkRequestForm']);
|
2016-12-14 05:06:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the e-mail subject line to be used for the reset link email.
|
|
|
|
* Overriding method "getEmailSubject()" from trait "use ResetsPasswords"
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-29 14:02:18 -08:00
|
|
|
public function getEmailSubject()
|
|
|
|
{
|
2016-12-14 05:06:15 -08:00
|
|
|
return property_exists($this, 'subject') ? $this->subject : \Lang::get('mail.reset_link');
|
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:07 -08:00
|
|
|
|
|
|
|
|
2016-12-14 05:06:15 -08:00
|
|
|
/**
|
|
|
|
* Send a reset link to the given user.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function sendResetLinkEmail(Request $request)
|
|
|
|
{
|
|
|
|
|
2020-03-04 22:08:07 -08:00
|
|
|
/**
|
|
|
|
* Let's set a max character count here to prevent potential
|
|
|
|
* buffer overflow issues with attackers sending very large
|
|
|
|
* payloads through.
|
|
|
|
*/
|
2020-04-30 19:10:07 -07:00
|
|
|
|
|
|
|
$request->validate([
|
2020-11-02 23:57:00 -08:00
|
|
|
'username' => ['required', 'max:255'],
|
2020-04-30 19:10:07 -07:00
|
|
|
]);
|
2021-07-29 14:02:45 -07:00
|
|
|
|
2020-04-30 17:45:05 -07:00
|
|
|
|
2020-03-04 22:08:07 -08:00
|
|
|
|
|
|
|
/**
|
2020-03-04 22:19:59 -08:00
|
|
|
* If we find a matching email with an activated user, we will
|
2020-03-04 22:08:07 -08:00
|
|
|
* send the password reset link to the user.
|
|
|
|
*
|
|
|
|
* Once we have attempted to send the link, we will examine the response
|
|
|
|
* then see the message we need to show to the user. Finally, we'll send out a proper response.
|
|
|
|
*/
|
2021-10-08 15:43:32 -07:00
|
|
|
|
2021-07-29 14:02:45 -07:00
|
|
|
$response = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$response = $this->broker()->sendResetLink(
|
|
|
|
array_merge(
|
|
|
|
$request->only('username'),
|
|
|
|
['activated' => '1'],
|
|
|
|
['ldap_import' => '0']
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} catch(\Exception $e) {
|
2021-07-29 14:14:52 -07:00
|
|
|
\Log::info('Password reset attempt: User '.$request->input('username').'failed with exception: '.$e );
|
2021-07-29 14:02:45 -07:00
|
|
|
}
|
|
|
|
|
2016-12-14 05:06:15 -08:00
|
|
|
|
|
|
|
if ($response === \Password::RESET_LINK_SENT) {
|
2020-11-02 23:57:00 -08:00
|
|
|
\Log::info('Password reset attempt: User '.$request->input('username').' WAS found, password reset sent');
|
2018-10-31 18:03:24 -07:00
|
|
|
} else {
|
2020-11-02 23:57:00 -08:00
|
|
|
\Log::info('Password reset attempt: User matching username '.$request->input('username').' NOT FOUND or user is inactive');
|
2016-12-14 05:06:15 -08:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:07 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* HOWEVER, we do not want to translate the message if the user isn't found
|
|
|
|
* or isn't active, since that would allow an attacker to walk through
|
|
|
|
* a dictionary attack and figure out registered user email addresses.
|
|
|
|
*
|
|
|
|
* Instead we tell the user we've sent an email even though we haven't.
|
|
|
|
* It's bad UX, but better security. The compromises we sometimes have to make.
|
|
|
|
*/
|
|
|
|
|
2018-10-31 18:03:24 -07:00
|
|
|
// Regardless of response, we do not want to disclose the status of a user account,
|
|
|
|
// so we give them a generic "If this exists, we're TOTALLY gonna email you" response
|
|
|
|
return redirect()->route('login')->with('success',trans('passwords.sent'));
|
2020-03-04 22:08:07 -08:00
|
|
|
}
|
|
|
|
|
2020-04-30 17:45:05 -07:00
|
|
|
|
2016-12-14 05:06:15 -08:00
|
|
|
}
|