ForgotPasswordController.php
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
63
64
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
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.
|
*/
//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', 'Ссылка для восстановления пароля отправлена на почту!');
}
}