简体   繁体   中英

Can reset password in laravel 5.1

I am using the default laravel 5.1 reset password functionality, its sending me email successfully the only problem I am having is that when I try to visit the link and reset my password it gives me validation error:

"Passwords must be at least six characters and match the confirmation."

This is the default laravel controller:

<?php

namespace Illuminate\Foundation\Auth;

use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Password;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

trait ResetsPasswords
{
    /**
     * Display the form to request a password reset link.
     *
     * @return \Illuminate\Http\Response
     */

    public function getEmail()
    {
    return view('auth.password');
}

/**
 * Send a reset link to the given user.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function postEmail(Request $request)
{
    $this->validate($request, ['email' => 'required|email']);

    $response = Password::sendResetLink($request->only('email'), function (Message $message) {
        $message->subject($this->getEmailSubject());
    });

    switch ($response) {
        case Password::RESET_LINK_SENT:
            return redirect()->back()->with('status', trans($response));

        case Password::INVALID_USER:
            return redirect()->back()->withErrors(['email' => trans($response)]);
    }
}

/**
 * Get the e-mail subject line to be used for the reset link email.
 *
 * @return string
 */
protected function getEmailSubject()
{
    return isset($this->subject) ? $this->subject : 'Your Password Reset Link';
}

/**
 * Display the password reset view for the given token.
 *
 * @param  string  $token
 * @return \Illuminate\Http\Response
 */
public function getReset($token = null)
{
    if (is_null($token)) {
        throw new NotFoundHttpException;
    }

    return view('auth.reset')->with('token', $token);
}

/**
 * Reset the given user's password.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function postReset(Request $request)
{
    $this->validate($request, [
        'token' => 'required',
        'email' => 'required|email',
        'password' => 'required|confirmed|min:6',
    ]);

    $credentials = $request->only(
        'email', 'password', 'password_confirmation', 'token'
    );

    $response = Password::reset($credentials, function ($user, $password) {
        $this->resetPassword($user, $password);
    });

    switch ($response) {
        case Password::PASSWORD_RESET:
            return redirect($this->redirectPath());

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

/**
 * Reset the given user's password.
 *
 * @param  \Illuminate\Contracts\Auth\CanResetPassword  $user
 * @param  string  $password
 * @return void
 */
protected function resetPassword($user, $password)
{
    $user->password = bcrypt($password);

    $user->save();

    Auth::login($user);
}

/**
 * Get the post register / login redirect path.
 *
 * @return string
 */
public function redirectPath()
{
    if (property_exists($this, 'redirectPath')) {
        return $this->redirectPath;
    }

    return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}

}

And this is the front end of the reset password form:

<!-- resources/views/auth/reset.blade.php -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- ================================================= -->
    <!-- PLACE YOUR PAGE TITLE BELOW -->
    <!-- ================================================= -->
    <title>Intl Counselling</title>

    <!-- ================================================= -->
    <!-- LINK TO BOOTSTRAP AND CUSTOM CSS -->
    <!-- ================================================= -->
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="{{ asset('libs/owl.carousel.css') }}">
    <link rel="stylesheet" href="{{ asset('libs/owl.theme.css') }}">
    <link rel="stylesheet" href="{{ asset('libs/owl.transitions.css') }}">
    <link rel="stylesheet" href="{{ asset('styles/styles.css') }}">
    <link rel="stylesheet" href="{{ asset('styles/faq.css') }}">
    <link rel="stylesheet" type="text/css" href="{{asset('css/style.css')}}">
    <script src="{{asset('js/prefixfree.min.js')}}"></script>
</head>
<body>

<form method="POST" action="/password/reset">
    {!! csrf_field() !!}
    <input type="hidden" name="token" value="{{ $token }}">
       <div class="body"></div>
    <div class="grad"></div>
    <div class="header" style="margin-left: -50px;">
        <div>Intl<span>Counselling</span></div>
    </div>
    <br>
    <div class="login">
            <input type="email" name="email" placeholder="email" value="{{ old('email') }}">
             <input type="password" placeholder="password" name="password" id="password">
            <input type="password" placeholder="password" name="password_confirmation'">
            <input type="submit" value="Reset Password">

             @if (count($errors) > 0)
                       <ul>
                           @foreach ($errors->all() as $error)
                               <li>{{ $error }}</li>
                           @endforeach
                       </ul>
                   @endif
    </div>

   {{----}}
       {{--{!! csrf_field() !!}--}}
       {{--<input type="hidden" name="token" value="{{ $token }}">--}}
   {{----}}
       {{--@if (count($errors) > 0)--}}
           {{--<ul>--}}
               {{--@foreach ($errors->all() as $error)--}}
                   {{--<li>{{ $error }}</li>--}}
               {{--@endforeach--}}
           {{--</ul>--}}
       {{--@endif--}}
   {{----}}
       {{--<div>--}}
           {{--Email--}}
           {{--<input type="email" name="email" value="{{ old('email') }}">--}}
       {{--</div>--}}
   {{----}}
       {{--<div>--}}
           {{--Password--}}
           {{--<input type="password" name="password">--}}
       {{--</div>--}}
   {{----}}
       {{--<div>--}}
           {{--Confirm Password--}}
           {{--<input type="password" name="password_confirmation">--}}
       {{--</div>--}}
   {{----}}
       {{--<div>--}}
           {{--<button type="submit">--}}
               {{--Reset Password--}}
           {{--</button>--}}
       {{--</div>--}}
   {{--</form>--}}
</form>



<!-- ================================================= -->
<!-- LINK TO BOOTSTRAP JQUERY AND CUSTOM JAVASCRIPT FILE -->
<!-- ================================================= -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="{{ asset('libs/owl.carousel.min.js') }}"></script>
@yield('additionalFooter')
<script type="text/javascript" src="{{ asset('scripts/scripts.js') }}"></script>

</body>
</html>



















{{--=====================================================================================--}}

在此处输入图片说明

I have followed everything from the laravel documentation but I cant seem to figure this out I may be a very basic mistake I am just starting with laravel

问题是密码不匹配并确认密码值或ypu试图输入少于6个字符的密码

如果您要更改规则,请结束编辑此行'password'=>'required | confirmed | min:6',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM