laravel 5.0 中的自定义重置密码路由
Custom reset password routes in laravel 5.0
我想为密码重置创建一些自定义路由,这是我目前所做的:
首先,我创建了自己的路线
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
Route::get('/olvide-mi-contrasena', [
'as' => 'clubOlvide',
'uses' => 'Auth\PasswordController@getEmail'
]);
Route::post('/olvide-mi-contrasena', [
'as' => 'clubPostOlvide',
'uses' => 'Auth\PasswordController@postEmail'
]);
Route::get('/restablecer-contrasena/{token}', [
'as' => 'clubRestablecer',
'uses' => 'Auth\PasswordController@getReset'
]);
Route::post('/restablecer-contrasena/{token}', [
'as' => 'clubPostRestablecer',
'uses' => 'Auth\PasswordController@postReset'
]);
其次,我覆盖了 PasswordController 的 ResetsPasswords 特征
private $redirectTo = '/ingresar';
public function getEmail()
{
return view('Club.auth.password');
}
public function getReset($token = null)
{
if (is_null($token))
{
throw new NotFoundHttpException;
}
return view('Club.auth.reset')->with('token', $token);
}
三、改变视图处的动作
<form class="form-horizontal" role="form" method="POST" action="{{ route('clubPostRestablecer',['token' => $token]) }}">
第四,我编辑了邮件配置
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => 'soporte@domain.tld', 'name' => 'Support'],
'encryption' => 'tls',
'username' => 'googlemail@gmail.com',
'password' => 'googlePassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
我测试了它...它发送了重置 link,并且 link 有效,它重置了密码,但它使用的是默认路由,我希望它发送自定义路线,这就是我要说的:
收到电子邮件(我将在 link 中用单词标记替换真实标记以使 post 更具可读性):
Click here to reset your password:
我想要它是什么:
Click here to reset your password:
如果我复制发送到 password/reset/token
的令牌并粘贴它 restablecer-contrasena/token
它有效,所以我想知道如何更改发送到电子邮件的 link?
知道了!密码重置邮件使用模板,配置在config/auth。php见:
When a user submits a request to reset their password, they will
receive an e-mail with a link that points to the getReset method
(typically routed at /password/reset) of the PasswordController. You
will need to create a view for this e-mail at
resources/views/emails/password.blade.php. The view will receive the
$token variable which contains the password reset token to match the
user to the password reset request. Here is an example e-mail view to
get you started:
<!-- resources/views/emails/password.blade.php -->
Click here to reset your password: {{ route('clubPostRestablecer',['token' => $token]) }}
我想为密码重置创建一些自定义路由,这是我目前所做的:
首先,我创建了自己的路线
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
Route::get('/olvide-mi-contrasena', [
'as' => 'clubOlvide',
'uses' => 'Auth\PasswordController@getEmail'
]);
Route::post('/olvide-mi-contrasena', [
'as' => 'clubPostOlvide',
'uses' => 'Auth\PasswordController@postEmail'
]);
Route::get('/restablecer-contrasena/{token}', [
'as' => 'clubRestablecer',
'uses' => 'Auth\PasswordController@getReset'
]);
Route::post('/restablecer-contrasena/{token}', [
'as' => 'clubPostRestablecer',
'uses' => 'Auth\PasswordController@postReset'
]);
其次,我覆盖了 PasswordController 的 ResetsPasswords 特征
private $redirectTo = '/ingresar';
public function getEmail()
{
return view('Club.auth.password');
}
public function getReset($token = null)
{
if (is_null($token))
{
throw new NotFoundHttpException;
}
return view('Club.auth.reset')->with('token', $token);
}
三、改变视图处的动作
<form class="form-horizontal" role="form" method="POST" action="{{ route('clubPostRestablecer',['token' => $token]) }}">
第四,我编辑了邮件配置
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => 'soporte@domain.tld', 'name' => 'Support'],
'encryption' => 'tls',
'username' => 'googlemail@gmail.com',
'password' => 'googlePassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
我测试了它...它发送了重置 link,并且 link 有效,它重置了密码,但它使用的是默认路由,我希望它发送自定义路线,这就是我要说的:
收到电子邮件(我将在 link 中用单词标记替换真实标记以使 post 更具可读性):
Click here to reset your password:
我想要它是什么:
Click here to reset your password:
如果我复制发送到 password/reset/token
的令牌并粘贴它 restablecer-contrasena/token
它有效,所以我想知道如何更改发送到电子邮件的 link?
知道了!密码重置邮件使用模板,配置在config/auth。php见:
When a user submits a request to reset their password, they will receive an e-mail with a link that points to the getReset method (typically routed at /password/reset) of the PasswordController. You will need to create a view for this e-mail at resources/views/emails/password.blade.php. The view will receive the $token variable which contains the password reset token to match the user to the password reset request. Here is an example e-mail view to get you started:
<!-- resources/views/emails/password.blade.php -->
Click here to reset your password: {{ route('clubPostRestablecer',['token' => $token]) }}