Completed
Push — master ( 77edab...304033 )
by Chris
11s
created

ResetPasswordController::__construct()   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\Response;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Routing\Controller;
8
use Illuminate\Support\Facades\Password;
9
use Illuminate\Foundation\Auth\ResetsPasswords;
10
use Yab\FlightDeck\Http\Requests\ResetPasswordRequest;
11
12
class ResetPasswordController extends Controller
13
{
14
    /*
15
    |--------------------------------------------------------------------------
16
    | Password Reset Controller
17
    |--------------------------------------------------------------------------
18
    |
19
    | This controller is responsible for handling password reset requests
20
    | and uses a simple trait to include this behavior. You're free to
21
    | explore this trait and override any methods you wish to tweak.
22
    |
23
    */
24
25
    use ResetsPasswords;
26
27
    /**
28
     * Create a new controller instance.
29
     *
30
     * @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...
31
     */
32
    public function __construct()
33
    {
34
        $this->middleware('guest');
35
    }
36
37
    /**
38
     * Reset the given user's password.
39
     *
40
     * @param  Yab\FlightDeck\Http\Requests\ResetPasswordRequest  $request
41
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
42
     */
43
    public function reset(ResetPasswordRequest $request)
44
    {
45
        $response = $this->broker()->reset(
46
            $this->credentials($request), function ($user, $password) {
47
                $this->resetPassword($user, $password);
48
            }
49
        );
50
51
        return $response == Password::PASSWORD_RESET
52
            ? $this->sendResetResponse($request, $response)
53
            : $this->sendResetFailedResponse($request, $response);
54
    }
55
56
    /**
57
     * Get the response for a successful password reset.
58
     *
59
     * @param  Yab\FlightDeck\Http\Requests\ResetPasswordRequest   $request
60
     * @param  string  $response
61
     * @return \Illuminate\Http\JsonResponse
62
     */
63
    protected function sendResetResponse(ResetPasswordRequest $request, $response)
64
    {
65
        return new JsonResponse([
66
            'success' => true,
67
            'message' => '',
68
        ], Response::HTTP_OK);
69
    }
70
71
    /**
72
     * Get the response for a failed password reset.
73
     *
74
     * @param  Yab\FlightDeck\Http\Requests\ResetPasswordRequest   $request
75
     * @param  string  $response
76
     * @return \Illuminate\Http\JsonResponse
77
     */
78
    protected function sendResetFailedResponse(ResetPasswordRequest $request, $response)
79
    {
80
        return new JsonResponse([
81
            'success' => false,
82
            'message' => 'An error occurred while trying to reset the password',
83
        ], Response::HTTP_INTERNAL_SERVER_ERROR);
84
    }
85
}
86