[英]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: 我正在使用默认的laravel 5.1重置密码功能,它成功向我发送电子邮件,我遇到的唯一问题是,当我尝试访问链接并重置密码时,它给了我验证错误:
"Passwords must be at least six characters and match the confirmation." “密码必须至少包含六个字符,并且与确认字符匹配。”
This is the default laravel controller: 这是默认的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';
}
} }
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 我已经遵循了laravel文档中的所有内容,但是我似乎无法弄清楚我可能是一个非常基本的错误,我只是从laravel开始
问题是密码不匹配并确认密码值或ypu试图输入少于6个字符的密码
如果您要更改规则,请结束编辑此行'password'=>'required | confirmed | min:6',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.