MINI Sh3ll
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Facades\Notification;
use App\Notifications\ResetPasswordMail;
use Illuminate\Auth\Events\PasswordReset;
use App\Models\PasswordResets;
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');
}
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
// We will send the password reset link to this 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.
/*$response = $this->broker()->sendResetLink(
$request->only('email')
);*/
$response = $this->sendResetLink(
$request->only('email')
);
if(!$response) {
return redirect()->back()->with('error', 'Incorrect email Address');
}
return redirect()->route('login')->with('success', 'Password reset link sent to your mail.');
//return 'true';
/*return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($request, $response)
: $this->sendResetLinkFailedResponse($request, $response);*/
}
/**
* Send a password reset link to a user.
*
* @param array $credentials
* @return string
*/
public function sendResetLink(array $credentials)
{
$return = false;
try{
// First we will check to see if we found a user at the given credentials and
// if we did not we will redirect back to this current URI with a piece of
// "flash" data in the session to indicate to the developers the errors.
$user = User::where('email', $credentials['email'])->first();
if(isset($user) && !empty($user)){
$return = true;
$user->notify(new ResetPasswordMail($user));
$verify = PasswordResets::where('email', $credentials['email'])->first();
if (!empty($verify)) {
$verify->email = $credentials['email'];
$verify->token = generateRandomString('20');
$verify->save();
}else{
PasswordResets::Create([
'email' => $credentials['email'],
'token' => generateRandomString('20')
]);
}
}
} catch(Exception $e) {
$return = false;
}
return $return;
// return view('auth.passwords.email');
}
}
OHA YOOOO