1 | <?php |
||
2 | |||
3 | namespace App\Http\Controllers; |
||
4 | |||
5 | use App\Models\User; |
||
6 | use Illuminate\Auth\Access\AuthorizationException; |
||
7 | use Illuminate\Auth\Events\Verified; |
||
8 | use Illuminate\Http\Request; |
||
9 | use PhpParser\Builder\Param; |
||
10 | |||
11 | class VerificationController extends Controller |
||
12 | { |
||
13 | public function verify(Request $request) |
||
14 | { |
||
15 | $user = User::findOrFail($request->id); |
||
16 | |||
17 | // do this check ,only if you allow verified user to login |
||
18 | // if(! hash_equals((string) $request->id,(string) $user->getKey())){ |
||
19 | // throw new AuthorizationException; |
||
20 | // } |
||
21 | |||
22 | if (! hash_equals((string) $request->hash, sha1($user->getEmailForVerification()))) { |
||
23 | return response()->json([ |
||
24 | 'message' => 'Unauthorized', |
||
25 | 'success' => false, |
||
26 | ]); |
||
27 | } |
||
28 | |||
29 | if ($user->hasVerifiedEmail()) { |
||
30 | return response()->json([ |
||
31 | 'message' => 'User Allready Verified!', |
||
32 | 'success' => false, |
||
33 | ]); |
||
34 | } |
||
35 | |||
36 | if ($user->markEmailAsVerified()) { |
||
37 | event(new Verified($user)); |
||
38 | } |
||
39 | |||
40 | return response()->json([ |
||
41 | 'message' => 'Email verified successfully!', |
||
42 | 'success' => true, |
||
43 | ]); |
||
44 | } |
||
45 | |||
46 | public function resendVerificatonEmail(Request $request) |
||
47 | { |
||
48 | $user = User::where('email', $request->email)->firstOrFail(); |
||
49 | if (! $user) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
50 | return response()->json([ |
||
51 | 'message' => 'Failed to send!', |
||
52 | 'success' => false, |
||
53 | ]); |
||
54 | } |
||
55 | $user->sendEmailVerificationNotification(); |
||
56 | |||
57 | return response()->json([ |
||
58 | 'message' => 'Check your email', |
||
59 | 'success' => true, |
||
60 | ]); |
||
61 | } |
||
62 | } |
||
63 |