1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\Users\Http\Controllers; |
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
|
|
|
/** |
12
|
|
|
* Class APIForgotPasswordController. |
13
|
|
|
* |
14
|
|
|
* @package Acacha\Users\Http\Controllers |
15
|
|
|
*/ |
16
|
|
|
class APIForgotPasswordController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Send a reset link to the given user. |
20
|
|
|
* |
21
|
|
|
* @param Request $request |
22
|
|
|
* @return JsonResponse |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function sendResetLinkEmail(Request $request) |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$this->validate($request, ['email' => 'required|email']); |
27
|
|
|
|
28
|
|
|
$response = Password::broker()->sendResetLink( |
29
|
|
|
$request->only('email') |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
if (Password::RESET_LINK_SENT) { |
33
|
|
|
return new JsonResponse(['status' => trans($response) ], 200); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return new JsonResponse(['email' => trans($response) ], 422); |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Send a reset link to the given users. |
42
|
|
|
* |
43
|
|
|
* @param Request $request |
44
|
|
|
* @return JsonResponse |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function massiveSendResetLinkEmail(Request $request) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$this->validate($request, ['ids' => 'required']); |
49
|
|
|
|
50
|
|
|
$errors = []; |
51
|
|
|
foreach ($request->input('ids') as $id) { |
|
|
|
|
52
|
|
|
$user = User::find($id); |
53
|
|
|
$response = Password::broker()->sendResetLink([ 'email' => $user->email ]); |
54
|
|
|
if (! Password::RESET_LINK_SENT) { |
55
|
|
|
dd('ERROR!'); |
56
|
|
|
$errors[] = $response; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ( count($errors) > 0 ) return new JsonResponse(['status' => 'Error', 'errors' => $errors ], 422); |
61
|
|
|
|
62
|
|
|
return new JsonResponse(['status' => 'Done' ], 200); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: