VerificationController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Foundation\Auth\VerifiesEmails;
  5. use App\Models\User;
  6. use Carbon\Carbon;
  7. use Illuminate\Http\Request;
  8. use App\Http\Controllers\OTPVerificationController;
  9. class VerificationController extends Controller
  10. {
  11. /*
  12. |--------------------------------------------------------------------------
  13. | Email Verification Controller
  14. |--------------------------------------------------------------------------
  15. |
  16. | This controller is responsible for handling email verification for any
  17. | user that recently registered with the application. Emails may also
  18. | be re-sent if the user didn't receive the original email message.
  19. |
  20. */
  21. use VerifiesEmails;
  22. /**
  23. * Where to redirect users after verification.
  24. *
  25. * @var string
  26. */
  27. protected $redirectTo = '/';
  28. /**
  29. * Create a new controller instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. //$this->middleware('auth');
  36. $this->middleware('signed')->only('verify');
  37. $this->middleware('throttle:6,1')->only('verify', 'resend');
  38. }
  39. /**
  40. * Show the email verification notice.
  41. *
  42. * @param \Illuminate\Http\Request $request
  43. * @return \Illuminate\Http\Response
  44. */
  45. public function show(Request $request)
  46. {
  47. if ($request->user()->email != null) {
  48. return $request->user()->hasVerifiedEmail()
  49. ? redirect($this->redirectPath())
  50. : view('auth.verify');
  51. }
  52. else {
  53. $otpController = new OTPVerificationController;
  54. $otpController->send_code($request->user());
  55. return redirect()->route('verification');
  56. }
  57. }
  58. /**
  59. * Resend the email verification notification.
  60. *
  61. * @param \Illuminate\Http\Request $request
  62. * @return \Illuminate\Http\Response
  63. */
  64. public function resend(Request $request)
  65. {
  66. if ($request->user()->hasVerifiedEmail()) {
  67. return redirect($this->redirectPath());
  68. }
  69. $request->user()->sendEmailVerificationNotification();
  70. return back()->with('resent', true);
  71. }
  72. public function verification_confirmation($code){
  73. $user = User::where('verification_code', $code)->first();
  74. if($user != null){
  75. $user->email_verified_at = Carbon::now();
  76. $user->save();
  77. auth()->login($user, true);
  78. flash(translate('Your email has been verified successfully'))->success();
  79. }
  80. else {
  81. flash(translate('Sorry, we could not verifiy you. Please try again'))->error();
  82. }
  83. if($user->user_type == 'seller') {
  84. return redirect()->route('seller.dashboard');
  85. }
  86. return redirect()->route('dashboard');
  87. }
  88. }