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

namespace IlluminateFoundationAuth;

use 
IlluminateHttpJsonResponse;
use 
IlluminateHttpRequest;
use 
IlluminateSupportFacadesAuth;
use 
IlluminateValidationValidationException;

trait 
AuthenticatesUsers
{
    use 
RedirectsUsersThrottlesLogins;

    
/**
     * Show the application's login form.
     *
     * @return IlluminateViewView
     */
    
public function showLoginForm()
    {
        return 
view('auth.login');
    }

    
/**
     * Handle a login request to the application.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpRedirectResponse|IlluminateHttpResponse|IlluminateHttpJsonResponse
     *
     * @throws IlluminateValidationValidationException
     */
    
public function login(Request $request)
    {
        
$this->validateLogin($request);

        
// If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        
if (method_exists($this'hasTooManyLoginAttempts') &&
            
$this->hasTooManyLoginAttempts($request)) {
            
$this->fireLockoutEvent($request);

            return 
$this->sendLockoutResponse($request);
        }

        if (
$this->attemptLogin($request)) {
            if (
$request->hasSession()) {
                
$request->session()->put('auth.password_confirmed_at'time());
            }

            return 
$this->sendLoginResponse($request);
        }

        
// If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        
$this->incrementLoginAttempts($request);

        return 
$this->sendFailedLoginResponse($request);
    }

    
/**
     * Validate the user login request.
     *
     * @param  IlluminateHttpRequest  $request
     * @return void
     *
     * @throws IlluminateValidationValidationException
     */
    
protected function validateLogin(Request $request)
    {
        
$request->validate([
            
$this->username() => 'required|string',
            
'password' => 'required|string',
        ]);
    }

    
/**
     * Attempt to log the user into the application.
     *
     * @param  IlluminateHttpRequest  $request
     * @return bool
     */
    
protected function attemptLogin(Request $request)
    {
        return 
$this->guard()->attempt(
            
$this->credentials($request), $request->boolean('remember')
        );
    }

    
/**
     * Get the needed authorization credentials from the request.
     *
     * @param  IlluminateHttpRequest  $request
     * @return array
     */
    
protected function credentials(Request $request)
    {
        return 
$request->only($this->username(), 'password');
    }

    
/**
     * Send the response after the user was authenticated.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpRedirectResponse|IlluminateHttpJsonResponse
     */
    
protected function sendLoginResponse(Request $request)
    {
        
$request->session()->regenerate();

        
$this->clearLoginAttempts($request);

        if (
$response $this->authenticated($request$this->guard()->user())) {
            return 
$response;
        }

        return 
$request->wantsJson()
                    ? new 
JsonResponse([], 204)
                    : 
redirect()->intended($this->redirectPath());
    }

    
/**
     * The user has been authenticated.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  mixed  $user
     * @return mixed
     */
    
protected function authenticated(Request $request$user)
    {
        
//
    
}

    
/**
     * Get the failed login response instance.
     *
     * @param  IlluminateHttpRequest  $request
     * @return SymfonyComponentHttpFoundationResponse
     *
     * @throws IlluminateValidationValidationException
     */
    
protected function sendFailedLoginResponse(Request $request)
    {
        throw 
ValidationException::withMessages([
            
$this->username() => [trans('auth.failed')],
        ]);
    }

    
/**
     * Get the login username to be used by the controller.
     *
     * @return string
     */
    
public function username()
    {
        return 
'email';
    }

    
/**
     * Log the user out of the application.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpRedirectResponse|IlluminateHttpJsonResponse
     */
    
public function logout(Request $request)
    {
        
$this->guard()->logout();

        
$request->session()->invalidate();

        
$request->session()->regenerateToken();

        if (
$response $this->loggedOut($request)) {
            return 
$response;
        }

        return 
$request->wantsJson()
            ? new 
JsonResponse([], 204)
            : 
redirect('/');
    }

    
/**
     * The user has logged out of the application.
     *
     * @param  IlluminateHttpRequest  $request
     * @return mixed
     */
    
protected function loggedOut(Request $request)
    {
        
//
    
}

    
/**
     * Get the guard to be used during authentication.
     *
     * @return IlluminateContractsAuthStatefulGuard
     */
    
protected function guard()
    {
        return 
Auth::guard();
    }
}
Онлайн: 1
Реклама