Test Setup Failed
Push — master ( ef125c...60f940 )
by he
08:55
created

ForgotPasswordController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\Request;
7
use App\Repositories\UserRepository;
8
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
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
    const PASSWORD_EMAIL = 'passwords.email';
27
28
    /**
29
     * Create a new controller instance.
30
     *
31
     * @return void
32
     */
33
    public function __construct()
34
    {
35
        $this->middleware('guest');
36
    }
37
38
    /**
39
     * Send a reset link to the given user.
40
     *
41
     * @param Request $request
42
     *
43
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
44
     */
45
    public function sendResetLinkEmail(Request $request)
46
    {
47
        $this->validateEmail($request);
48
49
        if ($this->hasManyUser($request->input('email')) > 1) {
50
            return $this->sendResetLinkFailedResponse($request, static::PASSWORD_EMAIL);
51
        }
52
53
        // We will send the password reset link to this user. Once we have attempted
54
        // to send the link, we will examine the response then see the message we
55
        // need to show to the user. Finally, we'll send out a proper response.
56
        $response = $this->broker()->sendResetLink(
57
            $request->only('email')
58
        );
59
60
        return $response === Password::RESET_LINK_SENT
61
            ? $this->sendResetLinkResponse($request, $response)
62
            : $this->sendResetLinkFailedResponse($request, $response);
63
    }
64
65
    private function hasManyUser($email)
66
    {
67
        return app(UserRepository::class)->findWhere(['email' => $email])->count();
68
    }
69
70
    public function showLinkRequestForm()
71
    {
72
        return view('web.auth.passwords.email');
73
    }
74
}
75