|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Modules\{{pluralClass}}\Http\Controllers\Auth; |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use App\Modules\{{pluralClass}}\Http\Controllers\Controller; |
|
6
|
|
|
use Illuminate\Auth\Events\PasswordReset; |
|
7
|
|
|
use Illuminate\Http\JsonResponse; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
use Illuminate\Support\Facades\Hash; |
|
10
|
|
|
use Illuminate\Support\Facades\Password; |
|
11
|
|
|
use Illuminate\Support\Str; |
|
12
|
|
|
use Illuminate\Validation\Rules; |
|
13
|
|
|
use Illuminate\Validation\ValidationException; |
|
14
|
|
|
|
|
15
|
|
|
class NewPasswordController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Handle an incoming new password request. |
|
19
|
|
|
* |
|
20
|
|
|
* @throws \Illuminate\Validation\ValidationException |
|
21
|
|
|
*/ |
|
22
|
|
|
public function store(Request $request): JsonResponse |
|
23
|
|
|
{ |
|
24
|
|
|
$request->validate([ |
|
25
|
|
|
'token' => ['required'], |
|
26
|
|
|
'email' => ['required', 'email'], |
|
27
|
|
|
'password' => ['required', 'confirmed', Rules\Password::defaults()], |
|
28
|
|
|
]); |
|
29
|
|
|
|
|
30
|
|
|
// Here we will attempt to reset the user's password. If it is successful we |
|
31
|
|
|
// will update the password on an actual user model and persist it to the |
|
32
|
|
|
// database. Otherwise we will parse the error and return the response. |
|
33
|
|
|
$status = Password::broker('{{pluralSlug}}')->reset( |
|
34
|
|
|
$request->only('email', 'password', 'password_confirmation', 'token'), |
|
35
|
|
|
function (${{singularCamel}}) use ($request) { |
|
36
|
|
|
${{singularCamel}}->forceFill([ |
|
37
|
|
|
'password' => Hash::make($request->password), |
|
38
|
|
|
'remember_token' => Str::random(60), |
|
39
|
|
|
])->save(); |
|
40
|
|
|
|
|
41
|
|
|
event(new PasswordReset(${{singularCamel}})); |
|
42
|
|
|
} |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
if ($status != Password::PASSWORD_RESET) { |
|
46
|
|
|
throw ValidationException::withMessages([ |
|
47
|
|
|
'email' => [__($status)], |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return response()->json(['status' => __($status)]); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|