Completed
Push — master ( 54d586...5aa3ec )
by Chris
14s queued 12s
created

ForgotPasswordController::broker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Yab\FlightDeck\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Response;
7
use Illuminate\Http\JsonResponse;
8
use Illuminate\Routing\Controller;
9
use Illuminate\Support\Facades\Password;
10
use Yab\FlightDeck\Http\Requests\ForgotPasswordRequest;
11
12
class ForgotPasswordController extends Controller
13
{
14
    /*
15
    |--------------------------------------------------------------------------
16
    | Password Reset Controller
17
    |--------------------------------------------------------------------------
18
    |
19
    | This controller is responsible for handling password reset emails and
20
    | includes a trait which assists in sending these notifications from
21
    | your application to your users. Feel free to explore this trait.
22
    |
23
    */
24
25
    /**
26
     * Create a new controller instance.
27
     *
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30
    public function __construct()
31
    {
32
        $this->middleware('guest');
33
    }
34
35
    /**
36
     * Send a reset link to the given user.
37
     *
38
     * @param  Yab\FlightDeck\Http\Requests\ForgotPasswordRequest $request
39
     * @return \Illuminate\Http\JsonResponse
40
     */
41
    public function sendResetEmail(ForgotPasswordRequest $request)
42
    {
43
        $response = $this->broker()->sendResetLink(
44
            $request->only('email')
45
        );
46
47
        return $response == Password::RESET_LINK_SENT
48
            ? $this->sendResetLinkResponse($request, $response)
49
            : $this->sendResetLinkFailedResponse($request, $response);
50
    }
51
    
52
    /**
53
     * Get the response for a successful password reset link.
54
     *
55
     * @param  \Illuminate\Http\Request  $request
56
     * @param  string  $response
57
     * @return \Illuminate\Http\JsonResponse
58
     */
59
    protected function sendResetLinkResponse(Request $request, $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
        return new JsonResponse([
62
            'success' => true,
63
            'message' => '',
64
        ], Response::HTTP_OK);
65
    }
66
67
    /**
68
     * Get the response for a failed password reset link.
69
     *
70
     * @param  \Illuminate\Http\Request  $request
71
     * @param  string  $response
72
     * @return \Illuminate\Http\JsonResponse
73
     */
74
    protected function sendResetLinkFailedResponse(Request $request, $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        return new JsonResponse([
77
            'success' => false,
78
            'message' => 'The email address provided could not be found',
79
        ], Response::HTTP_UNPROCESSABLE_ENTITY);
80
    }
81
82
    /**
83
     * Get the broker to be used during password reset.
84
     *
85
     * @return \Illuminate\Contracts\Auth\PasswordBroker
86
     */
87
    public function broker()
88
    {
89
        return Password::broker();
90
    }
91
}
92