Passed
Push — master ( 3e77af...7c612c )
by Brian
02:49
created

PasswordResetLinkController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A store() 0 20 2
1
<?php
2
3
namespace App\Modules\Admins\Http\Controllers\Auth;
4
5
use App\Modules\Admins\Http\Controllers\Controller;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Password;
9
use Illuminate\Validation\ValidationException;
10
11
class PasswordResetLinkController extends Controller
12
{
13
    /**
14
     * Handle an incoming password reset link request.
15
     *
16
     * @throws \Illuminate\Validation\ValidationException
17
     */
18
    public function store(Request $request): JsonResponse
19
    {
20
        $request->validate([
21
            'email' => ['required', 'email'],
22
        ]);
23
24
        // We will send the password reset link to this user. Once we have attempted
25
        // to send the link, we will examine the response then see the message we
26
        // need to show to the user. Finally, we'll send out a proper response.
27
        $status = Password::broker('admins')->sendResetLink(
28
            $request->only('email')
29
        );
30
31
        if ($status != Password::RESET_LINK_SENT) {
32
            throw ValidationException::withMessages([
33
                'email' => [__($status)],
34
            ]);
35
        }
36
37
        return response()->json(['status' => __($status)]);
38
    }
39
}
40