[英]Laravel reset password link does not route to forgotten password form
Please I am new to laravel;请我是 laravel 的新手; I have a Reset password link in my
login.blade.php
file but every other link works very well except the forgotten password link.我的
login.blade.php
文件中有一个重置密码链接,但除忘记密码链接外,其他所有链接都运行良好。 Whenever it's clicked it seems like the page want to refresh and return to the same page.每当它被点击时,页面似乎想要刷新并返回到同一页面。 I get 404 on validate.js as error on chrome.
我在 validate.js 上收到 404 作为 chrome 错误。
I have tried to use Laravel documentation to rewrite the route in web.php
.我尝试使用 Laravel 文档重写
web.php
中的路由。 Tried to use this but it did not work so i commented it out:试图使用它,但它没有用,所以我将其注释掉:
//Route::get('/forgot-password', function () { return view('auth.forget-password'); })-\>middleware('guest')-\>name('password.request');
Part of my login.blade.php
file:我的
login.blade.php
文件的一部分:
<div class="form-group">
<button class="mt-4 btn btn-primary" type="submit">Login</button>
</div>
<div class="mb-3 text-center">
<small class="mb-2 text-center ">Forget your Password <a href="{{ route('password.request') }}" class="ml-1 link">Reset.</a> </small>
<small class="text-center ">Dont have an Account yet? <a href="{{route('register')}}" class="ml-1 link">Sign up.</a> </small>
</div>
<div class="text-center">
<hr>
<small class="text-center ">© Copyright {{date('Y')}} {{$settings->site_name}} All Rights Reserved.</small>
</div>
</form>
This is my web.php, which has the route:这是我的 web.php,它有以下路线:
Route::get('/forgot-password', 'App\Http\Controllers\UsersController@forgotpassword')->name('password.request');
Tried to use this but it did not work so I commented it out:尝试使用它,但它没有用,所以我将其注释掉:
//Route::get('/forgot-password', function () { return view('auth.forget-password'); })->middleware('guest')->name('password.request');
This is my forgot-password.blade.php
:这是我的
forgot-password.blade.php
:
@include('home.assetss')
<body class="d-flex flex-column h-100 auth-page">
<!-- ======= Loginup Section ======= -->
<section class="auth">
<div class="container">
<div class="row justify-content-center user-auth">
<div class="col-12 col-md-6 col-lg-6 col-sm-10 col-xl-6 ">
<div class="text-center">
@if(Session::has('message'))
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{{ Session::get('message') }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
@endif
@if (session('status'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
{{ session('status') }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
@endif
</div>
<div class="card ">
<h1 class="mt-3 text-center">Password Reset</h1>
<form method="POST" action="{{ route('password.email') }}" class="mt-5 card__form">
{{csrf_field()}}
<div class="form-group ">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
<small>Forgot your password? No problem. Just let us know your email address and we will email you a password reset link that will allow you to choose a new one.</small> <br>
<input type="email" class="form-control {{ $errors->has('email') ? ' has-error' : '' }}" name ="email" value="{{ old('email') }}" id="email" placeholder="name@example.com" required>
</div>
<div class="form-group">
<button class="mt-4 btn btn-primary" type="submit" >Email Password Reset Link</button>
</div>
<div class="mb-3 text-center">
<small class="mb-2 text-center "> <a href="{{route('login')}}">Repeat Login.</a> </small>
</div>
<div class="text-center">
<hr>
<small class="text-center ">© Copyright {{date('Y')}} {{$settings->site_name}} <br> All Rights Reserved.</small>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
Tried to use this but it did not work so I commented it out:尝试使用它,但它没有用,所以我将其注释掉:
//Route::get('/forgot-password', function () { return view('auth.forget-password'); })->middleware('guest')->name('password.request');
I also tried making some changes on fortifyServiceProvider.php by adding requestPasswordResetLinkView but it did not work我还尝试通过添加 requestPasswordResetLinkView 对 fortifyServiceProvider.php 进行一些更改,但它没有用
<?php
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Fortify;
use App\Models\Settings;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
RateLimiter::for('login', function (Request $request) {
return Limit::perMinute(5)->by($request->email.$request->ip());
});
RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
Fortify::requestPasswordResetLinkView(function(){
return view(view: 'auth.forgot-password');
});
Fortify::twoFactorChallengeView(function () {
return view('auth.two-factor-challenge', [
'title' => 'Two Factor Authentication',
'settings' => Settings::where('id','1')->first(),
]);
});
Fortify::confirmPasswordView(function () {
return view('auth.confirm-password', [
'title' => 'Password Confirmation',
'settings' => Settings::where('id','1')->first(),
]);
});
}
}
this is my fortify.php这是我的 fortify.php
<?php
use App\Providers\RouteServiceProvider;
use Laravel\Fortify\Features;
return [
/*
|--------------------------------------------------------------------------
| Fortify Guard
|--------------------------------------------------------------------------
|
| Here you may specify which authentication guard Fortify will use while
| authenticating users. This value should correspond with one of your
| guards that is already present in your "auth" configuration file.
|
*/
'guard' => 'web',
/*
|--------------------------------------------------------------------------
| Fortify Password Broker
|--------------------------------------------------------------------------
|
| Here you may specify which password broker Fortify can use when a user
| is resetting their password. This configured value should match one
| of your password brokers setup in your "auth" configuration file.
|
*/
'passwords' => 'users',
/*
|--------------------------------------------------------------------------
| Username / Email
|--------------------------------------------------------------------------
|
| This value defines which model attribute should be considered as your
| application's "username" field. Typically, this might be the email
| address of the users but you are free to change this value here.
|
| Out of the box, Fortify expects forgot password and reset password
| requests to have a field named 'email'. If the application uses
| another name for the field you may define it below as needed.
|
*/
'username' => 'email',
'email' => 'email',
/*
|--------------------------------------------------------------------------
| Home Path
|--------------------------------------------------------------------------
|
| Here you may configure the path where users will get redirected during
| authentication or password reset when the operations are successful
| and the user is authenticated. You are free to change this value.
|
*/
'home' => RouteServiceProvider::HOME,
/*
|--------------------------------------------------------------------------
| Fortify Routes Prefix / Subdomain
|--------------------------------------------------------------------------
|
| Here you may specify which prefix Fortify will assign to all the routes
| that it registers with the application. If necessary, you may change
| subdomain under which all of the Fortify routes will be available.
|
*/
'prefix' => '',
'domain' => null,
/*
|--------------------------------------------------------------------------
| Fortify Routes Middleware
|--------------------------------------------------------------------------
|
| Here you may specify which middleware Fortify will assign to the routes
| that it registers with the application. If necessary, you may change
| these middleware but typically this provided default is preferred.
|
*/
'middleware' => ['web'],
/*
|--------------------------------------------------------------------------
| Rate Limiting
|--------------------------------------------------------------------------
|
| By default, Fortify will throttle logins to five requests per minute for
| every email and IP address combination. However, if you would like to
| specify a custom rate limiter to call then you may specify it here.
|
*/
'limiters' => [
'login' => 'login',
'two-factor' => 'two-factor',
],
/*
|--------------------------------------------------------------------------
| Register View Routes
|--------------------------------------------------------------------------
|
| Here you may specify if the routes returning views should be disabled as
| you may not need them when building your own application. This may be
| especially true if you're writing a custom single-page application.
|
*/
'views' => true,
/*
|--------------------------------------------------------------------------
| Features
|--------------------------------------------------------------------------
|
| Some of the Fortify features are optional. You may disable the features
| by removing them from this array. You're free to only remove some of
| these features or you can even remove all of these if you need to.
|
*/
'features' => [
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication([
'confirmPassword' => true,
]),
],
];
lavarel "forgot password" defaults to this value "password.request" put that in the href of your html: lavarel“忘记密码”默认为这个值“password.request”把它放在你的 html 的 href 中:
{{ route('password.request') }} {{ 路线('password.request')}}
that should work.那应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.