VerificationController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Auth\Access\AuthorizationException;
  5. use Illuminate\Auth\Events\Verified;
  6. use Illuminate\Foundation\Auth\VerifiesEmails;
  7. use Illuminate\Http\Request;
  8. class VerificationController extends Controller
  9. {
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Email Verification Controller
  13. |--------------------------------------------------------------------------
  14. |
  15. | This controller is responsible for handling email verification for any
  16. | user that recently registered with the application. Emails may also
  17. | be re-sent if the user didn't receive the original email message.
  18. |
  19. */
  20. use VerifiesEmails;
  21. /**
  22. * Where to redirect users after verification.
  23. *
  24. * @var string
  25. */
  26. protected $redirectTo = '/';
  27. /**
  28. * Create a new controller instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. $this->middleware('auth');
  35. $this->middleware('signed')->only('verify');
  36. $this->middleware('throttle:1,300')->only('verify', 'resend');
  37. }
  38. /**
  39. * Mark the authenticated user's email address as verified.
  40. *
  41. * @param \Illuminate\Http\Request $request
  42. * @return \Illuminate\Http\Response
  43. * @throws \Illuminate\Auth\Access\AuthorizationException
  44. */
  45. public function verify(Request $request)
  46. {
  47. if ($recipient = $request->user()->recipients()->find($request->route('id'))) {
  48. if ($recipient->hasVerifiedEmail()) {
  49. return redirect($this->redirectPath());
  50. }
  51. $recipient->markEmailAsVerified();
  52. return redirect(route('recipients.index'))->with('verified', true);
  53. } else {
  54. if ($request->route('id') != $request->user()->getKey()) {
  55. throw new AuthorizationException;
  56. }
  57. if ($request->user()->hasVerifiedEmail()) {
  58. return redirect($this->redirectPath());
  59. }
  60. if ($request->user()->markEmailAsVerified()) {
  61. event(new Verified($request->user()));
  62. }
  63. return redirect($this->redirectPath())->with('verified', true);
  64. }
  65. }
  66. }