Skip to content

Instantly share code, notes, and snippets.

@ianfagg
Created August 8, 2017 14:19
Show Gist options
  • Save ianfagg/9a3e7973ea0235263a5f294ced436c8b to your computer and use it in GitHub Desktop.
Save ianfagg/9a3e7973ea0235263a5f294ced436c8b to your computer and use it in GitHub Desktop.
Spark user verification
<?php
namespace App\Http\Controllers\Auth;
use Laravel\Spark\Spark;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Laravel\Spark\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Password;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Support\Arr;
use App\User;
class PasswordController extends Controller
{
use SendsPasswordResetEmails, ResetsPasswords {
SendsPasswordResetEmails::broker insteadof ResetsPasswords;
}
/**
* Create a new password controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
$this->middleware('throttle:3,1')->only('sendResetLinkEmail', 'reset');
$this->redirectTo = Spark::afterLoginRedirect();
}
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function sendResetLinkEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$request->request->add(['verified' => 1]);
$array = $request->only(['email','verified']);
$user = User::where($array)->first();
if ($user) {
// 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')
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($response)
: $this->sendResetLinkFailedResponse($request, $response);
} else {
$response = 'You need to verify your account before you can change your password. Please follow the instructions sent to your email address! If you cannot find it please check your \'Junk\' folder.';
return $response = $this->sendResetLinkFailedResponse($request, $response);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment