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

namespace IlluminateFoundationAuth;

use 
IlluminateAuthEventsPasswordReset;
use 
IlluminateHttpJsonResponse;
use 
IlluminateHttpRequest;
use 
IlluminateSupportFacadesAuth;
use 
IlluminateSupportFacadesHash;
use 
IlluminateSupportFacadesPassword;
use 
IlluminateSupportStr;
use 
IlluminateValidationRules;
use 
IlluminateValidationValidationException;

trait 
ResetsPasswords
{
    use 
RedirectsUsers;

    
/**
     * Display the password reset view for the given token.
     *
     * If no token is present, display the link request form.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateContractsViewFactory|IlluminateViewView
     */
    
public function showResetForm(Request $request)
    {
        
$token $request->route()->parameter('token');

        return 
view('auth.passwords.reset')->with(
            [
'token' => $token'email' => $request->email]
        );
    }

    
/**
     * Reset the given user's password.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpRedirectResponse|IlluminateHttpJsonResponse
     */
    
public function reset(Request $request)
    {
        
$request->validate($this->rules(), $this->validationErrorMessages());

        
// Here we will attempt to reset the user's password. If it is successful we
        // will update the password on an actual user model and persist it to the
        // database. Otherwise we will parse the error and return the response.
        
$response $this->broker()->reset(
            
$this->credentials($request), function ($user$password) {
                
$this->resetPassword($user$password);
            }
        );

        
// If the password was successfully reset, we will redirect the user back to
        // the application's home authenticated view. If there is an error we can
        // redirect them back to where they came from with their error message.
        
return $response == Password::PASSWORD_RESET
                    
$this->sendResetResponse($request$response)
                    : 
$this->sendResetFailedResponse($request$response);
    }

    
/**
     * Get the password reset validation rules.
     *
     * @return array
     */
    
protected function rules()
    {
        return [
            
'token' => 'required',
            
'email' => 'required|email',
            
'password' => ['required''confirmed'RulesPassword::defaults()],
        ];
    }

    
/**
     * Get the password reset validation error messages.
     *
     * @return array
     */
    
protected function validationErrorMessages()
    {
        return [];
    }

    
/**
     * Get the password reset credentials from the request.
     *
     * @param  IlluminateHttpRequest  $request
     * @return array
     */
    
protected function credentials(Request $request)
    {
        return 
$request->only(
            
'email''password''password_confirmation''token'
        
);
    }

    
/**
     * Reset the given user's password.
     *
     * @param  IlluminateContractsAuthCanResetPassword  $user
     * @param  string  $password
     * @return void
     */
    
protected function resetPassword($user$password)
    {
        
$this->setUserPassword($user$password);

        
$user->setRememberToken(Str::random(60));

        
$user->save();

        
event(new PasswordReset($user));

        
$this->guard()->login($user);
    }

    
/**
     * Set the user's password.
     *
     * @param  IlluminateContractsAuthCanResetPassword  $user
     * @param  string  $password
     * @return void
     */
    
protected function setUserPassword($user$password)
    {
        
$user->password Hash::make($password);
    }

    
/**
     * Get the response for a successful password reset.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  string  $response
     * @return IlluminateHttpRedirectResponse|IlluminateHttpJsonResponse
     */
    
protected function sendResetResponse(Request $request$response)
    {
        if (
$request->wantsJson()) {
            return new 
JsonResponse(['message' => trans($response)], 200);
        }

        return 
redirect($this->redirectPath())
                            ->
with('status'trans($response));
    }

    
/**
     * Get the response for a failed password reset.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  string  $response
     * @return IlluminateHttpRedirectResponse|IlluminateHttpJsonResponse
     */
    
protected function sendResetFailedResponse(Request $request$response)
    {
        if (
$request->wantsJson()) {
            throw 
ValidationException::withMessages([
                
'email' => [trans($response)],
            ]);
        }

        return 
redirect()->back()
                    ->
withInput($request->only('email'))
                    ->
withErrors(['email' => trans($response)]);
    }

    
/**
     * Get the broker to be used during password reset.
     *
     * @return IlluminateContractsAuthPasswordBroker
     */
    
public function broker()
    {
        return 
Password::broker();
    }

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