Вход Регистрация
Файл: vendor/laravel/ui/auth-backend/ThrottlesLogins.php
Строк: 119
<?php

namespace IlluminateFoundationAuth;

use 
IlluminateAuthEventsLockout;
use 
IlluminateCacheRateLimiter;
use 
IlluminateHttpRequest;
use 
IlluminateHttpResponse;
use 
IlluminateSupportStr;
use 
IlluminateValidationValidationException;

trait 
ThrottlesLogins
{
    
/**
     * Determine if the user has too many failed login attempts.
     *
     * @param  IlluminateHttpRequest  $request
     * @return bool
     */
    
protected function hasTooManyLoginAttempts(Request $request)
    {
        return 
$this->limiter()->tooManyAttempts(
            
$this->throttleKey($request), $this->maxAttempts()
        );
    }

    
/**
     * Increment the login attempts for the user.
     *
     * @param  IlluminateHttpRequest  $request
     * @return void
     */
    
protected function incrementLoginAttempts(Request $request)
    {
        
$this->limiter()->hit(
            
$this->throttleKey($request), $this->decayMinutes() * 60
        
);
    }

    
/**
     * Redirect the user after determining they are locked out.
     *
     * @param  IlluminateHttpRequest  $request
     * @return SymfonyComponentHttpFoundationResponse
     *
     * @throws IlluminateValidationValidationException
     */
    
protected function sendLockoutResponse(Request $request)
    {
        
$seconds $this->limiter()->availableIn(
            
$this->throttleKey($request)
        );

        throw 
ValidationException::withMessages([
            
$this->username() => [trans('auth.throttle', [
                
'seconds' => $seconds,
                
'minutes' => ceil($seconds 60),
            ])],
        ])->
status(Response::HTTP_TOO_MANY_REQUESTS);
    }

    
/**
     * Clear the login locks for the given user credentials.
     *
     * @param  IlluminateHttpRequest  $request
     * @return void
     */
    
protected function clearLoginAttempts(Request $request)
    {
        
$this->limiter()->clear($this->throttleKey($request));
    }

    
/**
     * Fire an event when a lockout occurs.
     *
     * @param  IlluminateHttpRequest  $request
     * @return void
     */
    
protected function fireLockoutEvent(Request $request)
    {
        
event(new Lockout($request));
    }

    
/**
     * Get the throttle key for the given request.
     *
     * @param  IlluminateHttpRequest  $request
     * @return string
     */
    
protected function throttleKey(Request $request)
    {
        return 
Str::transliterate(Str::lower($request->input($this->username())).'|'.$request->ip());
    }

    
/**
     * Get the rate limiter instance.
     *
     * @return IlluminateCacheRateLimiter
     */
    
protected function limiter()
    {
        return 
app(RateLimiter::class);
    }

    
/**
     * Get the maximum number of attempts to allow.
     *
     * @return int
     */
    
public function maxAttempts()
    {
        return 
property_exists($this'maxAttempts') ? $this->maxAttempts 5;
    }

    
/**
     * Get the number of minutes to throttle for.
     *
     * @return int
     */
    
public function decayMinutes()
    {
        return 
property_exists($this'decayMinutes') ? $this->decayMinutes 1;
    }
}
Онлайн: 1
Реклама