ForgotPasswordController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
  5. use Illuminate\Support\Facades\Password;
  6. use Illuminate\Http\Request;
  7. use App\User;
  8. class ForgotPasswordController extends Controller
  9. {
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Password Reset Controller
  13. |--------------------------------------------------------------------------
  14. |
  15. | This controller is responsible for handling password reset emails and
  16. | includes a trait which assists in sending these notifications from
  17. | your application to your users. Feel free to explore this trait.
  18. |
  19. */
  20. use SendsPasswordResetEmails;
  21. public function __construct()
  22. {
  23. $this->middleware('guest');
  24. }
  25. public function showLinkRequestForm()
  26. {
  27. return view('auth.passwords.email');
  28. }
  29. public function broker()
  30. {
  31. return Password::broker('users');
  32. }
  33. public function sendResetLinkEmail(Request $request){
  34. $request->validate([
  35. 'email'=>'required|email|exists:users'
  36. ]);
  37. $applicant= User::where('email', $request->email)->first();
  38. if (empty($applicant)) {
  39. return back()->with('error','Unknown Email address!');
  40. }
  41. if($applicant->email_verification == 0){
  42. return back()->with('error', 'Your e-mail is not verified!. Please check your email');
  43. }else{
  44. \Mail::to(
  45. $request->email
  46. )->send(
  47. new \App\Mail\ApplicantPasswordResetLink($applicant)
  48. );
  49. return back()->with('success', 'Your password reset link sent to registered emails inbox.');
  50. }
  51. }
  52. }