Blame view

app/Http/Controllers/Auth/ForgotPasswordController.php 1.87 KB
02a1ed535   Андрей Ларионов   Первый коммит Rek...
1
2
3
4
5
6
  <?php
  
  namespace App\Http\Controllers\Auth;
  
  use App\Http\Controllers\Controller;
  use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
6a962b009   Андрей Ларионов   Система авторизац...
7
8
9
10
11
  use Illuminate\Http\Request;
  use Illuminate\Support\Carbon;
  use Illuminate\Support\Facades\DB;
  use Illuminate\Support\Facades\Mail;
  use Illuminate\Support\Str;
02a1ed535   Андрей Ларионов   Первый коммит Rek...
12
13
14
15
16
17
18
19
20
21
22
23
24
  
  class ForgotPasswordController extends Controller
  {
      /*
      |--------------------------------------------------------------------------
      | Password Reset Controller
      |--------------------------------------------------------------------------
      |
      | This controller is responsible for handling password reset emails and
      | includes a trait which assists in sending these notifications from
      | your application to your users. Feel free to explore this trait.
      |
      */
6a962b009   Андрей Ларионов   Система авторизац...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
      //use SendsPasswordResetEmails;
  
      public function __construct(){
          $this->middleware('guest');
      }
  
      public function form() {
          return view('auth.forgot');
      }
  
      public function mail(Request $request) {
          $request->validate([
              'email' => 'required|email|exists:users',
          ]);
  
  
          $token = Str::random(60);
          DB::table('password_resets')->insert(
              ['email' => $request->email,
                  'token' => $token,
                  'created_at' => Carbon::now()]
          );
  
          //ссылка для сброса пароля
          $link = route('auth.reset-form',
              ['token' => $token, 'email' => $request->email]
          );
  
          Mail::send('email.reset-password',
              ['link' => base64_encode($link)],
              function($message) use ($request) {
                  $message->to($request->email);
                  $message->subject('Repair password');
              }
          );
  
          return back()->with('success', 'Ссылка для восстановления пароля отправлена на почту!');
      }
02a1ed535   Андрей Ларионов   Первый коммит Rek...
63
  }