Issues (45)

Http/Controllers/Auth/ForgotPasswordController.php (2 issues)

1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
7
use Illuminate\Http\JsonResponse;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Password;
10
11
class ForgotPasswordController extends Controller
12
{
13
    /*
14
    |--------------------------------------------------------------------------
15
    | Password Reset Controller
16
    |--------------------------------------------------------------------------
17
    |
18
    | This controller is responsible for handling password reset emails and
19
    | includes a trait which assists in sending these notifications from
20
    | your application to your users. Feel free to explore this trait.
21
    |
22
    */
23
24
    use SendsPasswordResetEmails;
25
26
    /**
27
     * Send a reset link to the given user.
28
     *
29
     * @param \Illuminate\Http\Request $request
30
     *
31
     * @return \Illuminate\Http\RedirectResponse
32
     */
33
    public function sendResetLinkEmail(Request $request)
34
    {
35
        $this->validateEmail($request);
36
37
        // We will send the password reset link to this user. Once we have attempted
38
        // to send the link, we will examine the response then see the message we
39
        // need to show to the user. Finally, we'll send out a proper response.
40
        $response = $this->broker()->sendResetLink(
41
            $request->only('email')
42
        );
43
44
        return $response == Password::RESET_LINK_SENT
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response == Illu...se($request, $response) also could return the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\RedirectResponse.
Loading history...
45
            ? $this->sendResetLinkResponse($request, $response)
46
            : $this->sendResetLinkFailedResponse($request, $response);
47
    }
48
49
    /**
50
     * Get the response for a successful password reset link.
51
     *
52
     * @param string $response
53
     *
54
     * @return mixed
55
     */
56
    protected function sendResetLinkResponse(Request $request, $response)
57
    {
58
        if ($request->expectsJson()) {
59
            return response()->json([
60
                'status' => trans($response),
61
            ]);
62
        }
63
64
        return back()->with('status', trans($response));
65
    }
66
67
    /**
68
     * Get the response for a failed password reset link.
69
     *
70
     * @param Request $request
71
     * @param $response
72
     *
73
     * @return mixed
74
     */
75
    protected function sendResetLinkFailedResponse(Request $request, $response)
76
    {
77
        if ($request->expectsJson()) {
78
            return new JsonResponse([
79
                'message' => 'The given data was invalid.',
80
                'errors'  => [
81
                    'email' => trans($response),
82
                ],
83
            ], 422);
84
        }
85
86
        return back()->withErrors(
87
            ['email' => trans($response)]
88
        );
89
    }
90
91
    /**
92
     * Display the form to request a password reset link.
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function showLinkRequestForm()
97
    {
98
        return view('adminlte::auth.passwords.email');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('adminlte::auth.passwords.email') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
99
    }
100
101
    /**
102
     * Create a new controller instance.
103
     *
104
     * @return void
105
     */
106
    public function __construct()
107
    {
108
        $this->middleware('guest');
109
    }
110
}
111