可以在laravel 5.1中重置密码

时间:2015-10-16 11:05:55

标签: php validation laravel-5.1

我正在使用默认的laravel 5.1重置密码功能,它成功向我发送电子邮件我遇到的唯一问题是,当我尝试访问该链接并重置我的密码时,它会给我验证错误:

“密码必须至少为六个字符并与确认匹配。”

这是默认的laravel控制器:

<?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';
}

}

这是重置密码表单的前端:

<!-- 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>



















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

enter image description here

我已经完成了laravel文档中的所有内容,但我似乎无法解决这个问题我可能是一个非常基本的错误,我刚开始使用laravel

2 个答案:

答案 0 :(得分:0)

问题是密码不匹配和确认密码值,或者ypu正在尝试输入少于6个字符的密码

答案 1 :(得分:0)

如果您想要更改规则,请找到结束编辑此行 'password'=&gt; '所需|确认|分钟:6',