-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented email verification during registration
- Loading branch information
1 parent
1db5d61
commit daff000
Showing
13 changed files
with
915 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Models\User; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Hash; | ||
use App\Http\Requests\RegisterRequest; | ||
use Illuminate\Auth\Events\Registered; | ||
|
||
|
||
class RegisterController extends Controller | ||
{ | ||
public function register(RegisterRequest $request) | ||
{ | ||
try { | ||
$user = User::create([ | ||
'first_name' => $request->input('first_name'), | ||
'last_name' => $request->input('last_name'), | ||
'email' => $request->input('email'), | ||
'password' => Hash::make($request->input('password')), | ||
]); | ||
|
||
event(new Registered($user)); | ||
|
||
return response()->json($user); | ||
} catch (\Exception $e) { | ||
return response([ | ||
'message' => 'Internal error, please try again later.' //$e->getMessage() | ||
], 400); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use Illuminate\Auth\Events\Verified; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Routing\Controller; | ||
use App\Models\User; | ||
|
||
|
||
class VerifyController extends Controller | ||
{ | ||
public function verify($userId, Request $request) | ||
{ | ||
if (!$request->hasValidSignature()) { | ||
return redirect('/login?verification_status=error'); | ||
} | ||
|
||
$user = User::findOrFail($userId); | ||
|
||
if (!$user->hasVerifiedEmail()) { | ||
$user->markEmailAsVerified(); | ||
} | ||
|
||
return redirect('/login?verification_status=success'); | ||
} | ||
|
||
public function resend(User $user) | ||
{ | ||
if (!$user) { | ||
return response()->json(["msg" => "Invalid user."], 400); | ||
} elseif ($user->hasVerifiedEmail()) { | ||
return response()->json(["msg" => "Email already verified."], 400); | ||
} | ||
|
||
$user->sendEmailVerificationNotification(); | ||
|
||
return response()->json(["msg" => "Email verification link sent on your email."]); | ||
} | ||
} |
Oops, something went wrong.