diff --git a/lang/en/messages.php b/lang/en/messages.php index 6f383a1..f506459 100644 --- a/lang/en/messages.php +++ b/lang/en/messages.php @@ -15,8 +15,7 @@ 'failed' => 'These credentials do not match our records.', 'password' => 'The provided password is incorrect.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', - 'Invalid Token' => 'Invalid Token', - 'Your IP :user_ip is blocked. Please contact support.' => 'Your IP :user_ip is blocked. Please contact support.', //don't translate :user_ip + 'ip_blocked' => 'Your IP :ip is blocked, Please contact support.', 'This user are not login. Please contact support.' => 'This user are not login. Please contact support.', 'Sorry, You entered wrong mobile number or invalid password!' => 'Sorry, You entered wrong mobile number or invalid password!', 'warning' => 'Sorry, You entered wrong credentials! You already attempt :attempt. times out of :threshold', diff --git a/src/Http/Controllers/AuthenticatedSessionController.php b/src/Http/Controllers/AuthenticatedSessionController.php index 7f28604..25b2958 100644 --- a/src/Http/Controllers/AuthenticatedSessionController.php +++ b/src/Http/Controllers/AuthenticatedSessionController.php @@ -62,6 +62,8 @@ public function store(LoginRequest $request): LoginResource|JsonResponse $request->clearRateLimited(); + if ($attemptUser->hasPermission()) + Auth::login($attemptUser); Auth::user()->tokens->each(fn($token) => $token->delete()); diff --git a/src/Http/Middleware/EnsureEmailIsVerified.php b/src/Http/Middleware/EnsureEmailIsVerified.php index 94a1103..3989941 100644 --- a/src/Http/Middleware/EnsureEmailIsVerified.php +++ b/src/Http/Middleware/EnsureEmailIsVerified.php @@ -12,7 +12,9 @@ class EnsureEmailIsVerified /** * Handle an incoming request. * - * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next + * @param Request $request + * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next + * @return Response */ public function handle(Request $request, Closure $next): Response { diff --git a/src/Http/Middleware/IpAddressVerified.php b/src/Http/Middleware/IpAddressVerified.php new file mode 100644 index 0000000..0558180 --- /dev/null +++ b/src/Http/Middleware/IpAddressVerified.php @@ -0,0 +1,31 @@ +banned(__('auth::messages.ip_blocked', ['ip' => $request->ip()])); + } + + return $next($request); + } +} diff --git a/src/Http/Requests/LoginRequest.php b/src/Http/Requests/LoginRequest.php index 63b8f5c..bf51c6c 100644 --- a/src/Http/Requests/LoginRequest.php +++ b/src/Http/Requests/LoginRequest.php @@ -62,7 +62,7 @@ public function ensureIsNotRateLimited(): void $seconds = RateLimiter::availableIn($this->throttleKey()); - abort(Response::HTTP_TOO_MANY_REQUESTS, trans('auth.throttle', [ + abort(Response::HTTP_TOO_MANY_REQUESTS, trans('auth::messages.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ])); diff --git a/src/Models/User.php b/src/Models/User.php index 7b4764c..ef5f53b 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable; use Laravel\Sanctum\HasApiTokens; use OwenIt\Auditing\Contracts\Auditable; +use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable implements Auditable { @@ -14,6 +15,7 @@ class User extends Authenticatable implements Auditable use HasApiTokens; use \OwenIt\Auditing\Auditable; use SoftDeletes; + use HasRoles; /* |-------------------------------------------------------------------------- diff --git a/src/RouteServiceProvider.php b/src/RouteServiceProvider.php index 304d26e..6329bd1 100644 --- a/src/RouteServiceProvider.php +++ b/src/RouteServiceProvider.php @@ -2,6 +2,7 @@ namespace Fintech\Auth; +use Fintech\Auth\Http\Middlewares\IpAddressVerified; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Http\Request; @@ -27,6 +28,8 @@ public function boot() ->middleware('api') ->group(__DIR__.'/../routes/api.php'); }); + + Route::middlewareGroup('ip_verified', [IpAddressVerified::class]); } /**