]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/Auth/NewPasswordController.php
add discord auth
[alttp.git] / app / Http / Controllers / Auth / NewPasswordController.php
1 <?php
2
3 namespace App\Http\Controllers\Auth;
4
5 use App\Http\Controllers\Controller;
6 use Illuminate\Auth\Events\PasswordReset;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\Hash;
9 use Illuminate\Support\Facades\Password;
10 use Illuminate\Support\Str;
11 use Illuminate\Validation\Rules;
12
13 class NewPasswordController extends Controller
14 {
15     /**
16      * Display the password reset view.
17      *
18      * @param  \Illuminate\Http\Request  $request
19      * @return \Illuminate\View\View
20      */
21     public function create(Request $request)
22     {
23         return view('auth.reset-password', ['request' => $request]);
24     }
25
26     /**
27      * Handle an incoming new password request.
28      *
29      * @param  \Illuminate\Http\Request  $request
30      * @return \Illuminate\Http\RedirectResponse
31      *
32      * @throws \Illuminate\Validation\ValidationException
33      */
34     public function store(Request $request)
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) 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 }