Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
anonaddy/app/Http/Controllers/Auth/VerificationController.php /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
89 lines (75 sloc)
2.64 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers\Auth; | |
| use App\Http\Controllers\Controller; | |
| use App\Models\Recipient; | |
| use App\Models\User; | |
| use Illuminate\Auth\Access\AuthorizationException; | |
| use Illuminate\Auth\Events\Verified; | |
| use Illuminate\Foundation\Auth\VerifiesEmails; | |
| use Illuminate\Http\Request; | |
| class VerificationController extends Controller | |
| { | |
| /* | |
| |-------------------------------------------------------------------------- | |
| | Email Verification Controller | |
| |-------------------------------------------------------------------------- | |
| | | |
| | This controller is responsible for handling email verification for any | |
| | user that recently registered with the application. Emails may also | |
| | be re-sent if the user didn't receive the original email message. | |
| | | |
| */ | |
| use VerifiesEmails; | |
| /** | |
| * Where to redirect users after verification. | |
| * | |
| * @var string | |
| */ | |
| protected $redirectTo = '/'; | |
| /** | |
| * Create a new controller instance. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| $this->middleware('auth')->except('verify'); | |
| $this->middleware('signed')->only('verify'); | |
| $this->middleware('throttle:1,1')->only('resend'); | |
| $this->middleware('throttle:6,1')->only('verify'); | |
| } | |
| /** | |
| * Mark the authenticated user's email address as verified. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| * @throws \Illuminate\Auth\Access\AuthorizationException | |
| */ | |
| public function verify(Request $request) | |
| { | |
| $verifiable = User::find($request->route('id')) ?? Recipient::find($request->route('id')); | |
| if (is_null($verifiable)) { | |
| throw new AuthorizationException; | |
| } | |
| if (! hash_equals((string) $request->route('id'), (string) $verifiable->getKey())) { | |
| throw new AuthorizationException; | |
| } | |
| if (! hash_equals((string) $request->route('hash'), sha1($verifiable->getEmailForVerification()))) { | |
| throw new AuthorizationException; | |
| } | |
| if ($verifiable->hasVerifiedEmail()) { | |
| return redirect($this->redirectPath()); | |
| } | |
| if ($verifiable->markEmailAsVerified() && $verifiable instanceof User) { | |
| event(new Verified($verifiable)); | |
| } | |
| if ($request->user() !== null) { | |
| $redirect = $verifiable instanceof User ? $this->redirectPath() : route('recipients.index'); | |
| } else { | |
| $redirect = 'login'; | |
| } | |
| return redirect($redirect) | |
| ->with('verified', true) | |
| ->with(['status' => 'Email Address Verified Successfully']); | |
| } | |
| } |