URL Shortener 1.0
A Laravel-based URL shortener application
Chargement...
Recherche...
Aucune correspondance
NewPasswordController.php
Aller à la documentation de ce fichier.
1<?php
2
4
7use Illuminate\Auth\Events\PasswordReset;
8use Illuminate\Http\RedirectResponse;
9use Illuminate\Http\Request;
10use Illuminate\Support\Facades\Hash;
11use Illuminate\Support\Facades\Password;
12use Illuminate\Support\Str;
13use Illuminate\Validation\Rules;
14use Illuminate\View\View;
15
17{
21 public function create(Request $request): View
22 {
23 return view('auth.reset-password', [
24 'token' => $request->route('token'),
25 'email' => $request->email
26 ]);
27 }
28
34 public function store(Request $request): RedirectResponse
35 {
36 $request->validate([
37 'token' => ['required'],
38 'email' => ['required', 'email'],
39 'password' => ['required', 'confirmed', Rules\Password::defaults()],
40 ]);
41
42 // Here we will attempt to reset the user's password. If it is successful we
43 // will update the password on an actual user model and persist it to the
44 // database. Otherwise we will parse the error and return the response.
45 $status = Password::reset(
46 $request->only('email', 'password', 'password_confirmation', 'token'),
47 function (User $user) use ($request) {
48 $user->forceFill([
49 'password' => Hash::make($request->password),
50 'remember_token' => Str::random(60),
51 ])->save();
52
53 event(new PasswordReset($user));
54 }
55 );
56
57 // If the password was successfully reset, we will redirect the user back to
58 // the application's home authenticated view. If there is an error we can
59 // redirect them back to where they came from with their error message.
60 return $status == Password::PASSWORD_RESET
61 ? redirect()->route('login')->with('status', __($status))
62 : back()->withInput($request->only('email'))
63 ->withErrors(['email' => __($status)]);
64 }
65}
create(Request $request)
Display the password reset view.
store(Request $request)
Handle an incoming new password request.