DONE: replace email verification by link instead of otp

This commit is contained in:
ISMAIL MASSERAN
2026-07-12 10:03:31 +08:00
parent 1e50e3d19f
commit 431bbee17c
30 changed files with 263 additions and 593 deletions
@@ -12,7 +12,6 @@ use Laravel\Fortify\Contracts\CreatesNewUsers;
use Modules\Auth\Entities\User;
use Modules\Role\Entities\Role;
use Modules\User\Notifications\UserActivationNotification;
use Modules\Auth\Services\EmailVerificationOtpService;
use Exception;
class CreateNewUser implements CreatesNewUsers
@@ -54,38 +53,6 @@ class CreateNewUser implements CreatesNewUsers
$user->assignRole($role);
}
app(EmailVerificationOtpService::class)->send($user);
// Send notification to admins if user requires activation
if ($user->status === 'pending') {
$this->notifyAdminsForActivation($user);
}
return $user;
}
/**
* Notify admins about new user requiring activation
*/
private function notifyAdminsForActivation(User $newUser): void
{
try {
$adminRoles = ['PENTADBIR', 'PS 2 KJC', 'PS 2 ALAT'];
// Get users with specific roles plus admins (PENTADBIR and DEVELOPER)
$adminUsers = $this->getUsersWithRolesAndAdmins($adminRoles);
$sender = auth()->user() ?? $newUser; // Use current user as sender, or new user if no auth
foreach ($adminUsers as $admin) {
try {
$admin->notify(new UserActivationNotification($newUser, $sender));
} catch (Exception $e) {
Log::error('Failed to send user activation notification: '.$e->getMessage());
}
}
} catch (Exception $e) {
Log::error('Failed to notify admins for user activation: '.$e->getMessage());
}
}
}
@@ -3,39 +3,19 @@
namespace Modules\Auth\Actions\Fortify;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Laravel\Fortify\Contracts\LoginResponse as ContractsLoginResponse;
use Modules\Auth\Services\AuthSessionService;
use Modules\Auth\Services\EmailVerificationOtpService;
class LoginResponse implements ContractsLoginResponse
{
public function __construct(
protected AuthSessionService $authSession,
protected EmailVerificationOtpService $otpService,
) {}
public function toResponse($request): JsonResponse
{
$user = $request->user();
if (! $user->hasVerifiedEmail()) {
$this->otpService->send($user);
Auth::guard(config('fortify.guard'))->logout();
return response()->json([
'success' => true,
'message' => 'Sila semak e-mel anda untuk kod pengesahan 6 digit.',
'data' => [
'email' => $user->email,
'requires_email_verification' => true,
],
]);
}
return $this->authSession->createAuthResponse(
$user,
$request->user(),
'Login successful'
);
}
@@ -3,24 +3,21 @@
namespace Modules\Auth\Actions\Fortify;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;
use Modules\Auth\Services\AuthSessionService;
class RegisterResponse implements RegisterResponseContract
{
public function __construct(
protected AuthSessionService $authSession,
) {}
public function toResponse($request): JsonResponse
{
$email = $request->user()?->email;
Auth::guard(config('fortify.guard'))->logout();
return response()->json([
'success' => true,
'message' => 'Pendaftaran berjaya. Sila semak e-mel anda untuk kod pengesahan 6 digit.',
'data' => [
'email' => $email,
'requires_email_verification' => true,
],
], 201);
return $this->authSession->createAuthResponse(
$request->user(),
'Pendaftaran berjaya. Akaun anda sedang menunggu pengaktifan daripada pentadbir sistem.',
201
);
}
}