|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use App\Activation; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use App\Models\User; |
|
8
|
|
|
use App\Providers\RouteServiceProvider; |
|
9
|
|
|
use Illuminate\Foundation\Auth\VerifiesEmails; |
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
use Illuminate\Support\Facades\Validator; |
|
12
|
|
|
use LaravelEnso\Core\Http\Controllers\Auth\LoginController; |
|
|
|
|
|
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response as Response; |
|
14
|
|
|
|
|
15
|
|
|
class VerificationController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
// use VerifiesEmails; |
|
18
|
|
|
|
|
19
|
|
|
protected $redirectTo = RouteServiceProvider::HOME; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct() |
|
22
|
|
|
{ |
|
23
|
|
|
// $this->middleware('auth'); |
|
24
|
|
|
// $this->middleware('signed')->only('verify'); |
|
25
|
|
|
// $this->middleware('throttle:6,1')->only('verify', 'resend'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
protected function validator(array $data) |
|
29
|
|
|
{ |
|
30
|
|
|
return Validator::make($data, [ |
|
31
|
|
|
'token' => ['required', 'string', 'max:255'], |
|
32
|
|
|
]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* verify user token. |
|
37
|
|
|
*/ |
|
38
|
|
|
public function verify_user(Request $request) |
|
39
|
|
|
{ |
|
40
|
|
|
$data = $request->all(); |
|
41
|
|
|
$this->validator($data)->validate(); |
|
42
|
|
|
try { |
|
43
|
|
|
$token = $request->get('token'); |
|
44
|
|
|
$activation = Activation::where('token', $token)->first(); |
|
45
|
|
|
if ($activation === null) { |
|
46
|
|
|
return response()->json( |
|
47
|
|
|
[ |
|
48
|
|
|
'error' => [ |
|
49
|
|
|
'code' => 300, |
|
50
|
|
|
'message' => 'Send activation code again.', |
|
51
|
|
|
], |
|
52
|
|
|
], |
|
53
|
|
|
Response::HTTP_UNPROCESSABLE_ENTITY); |
|
54
|
|
|
} |
|
55
|
|
|
$user_id = $activation->user_id; |
|
56
|
|
|
$user = User::find($user_id); |
|
57
|
|
|
if ($user === null) { |
|
58
|
|
|
return response()->json( |
|
59
|
|
|
[ |
|
60
|
|
|
'error' => [ |
|
61
|
|
|
'code' => 301, |
|
62
|
|
|
'message' => 'There is not such user.', |
|
63
|
|
|
], |
|
64
|
|
|
], |
|
65
|
|
|
Response::HTTP_UNPROCESSABLE_ENTITY); |
|
66
|
|
|
} |
|
67
|
|
|
$user->is_active = 1; |
|
68
|
|
|
$user->email_verified_at = date('Y-m-d H:i:s'); |
|
69
|
|
|
$user->save(); |
|
70
|
|
|
Activation::where('user_id', $user_id)->delete(); |
|
71
|
|
|
|
|
72
|
|
|
return response()->json([ |
|
73
|
|
|
'csrfToken' => csrf_token(), |
|
74
|
|
|
]); |
|
75
|
|
|
} catch (\Exception $e) { |
|
76
|
|
|
throw $e; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: