简体   繁体   English

Laravel 5.1中的密码重置

[英]Password reset in Laravel 5.1

Kindly tell me how to implement the password reset functionality in my Laravel 5.1 application. 请告诉我如何在Laravel 5.1应用程序中实现密码重置功能。 I am using the JWT to give a user access to the system. 我正在使用JWT授予用户访问系统的权限。 Please, tell me how to implement 'forgot passsword' functionality. 请告诉我如何实现“忘记密码”功能。 My web API is consumed by a mobile device and the user will follow the steps given below when a user understands that he has forgotten the password 我的Web API被移动设备占用,当用户了解他忘记了密码时,用户将按照以下步骤操作

1) In the login screen user will click 'Forgot password' 1)在登录屏幕中,用户将单击“忘记密码”

2) In the next step, the user will enter the email address and submits. 2)在下一步中,用户将输入电子邮件地址并提交。

3) Server-side code compares the email with all the email registered within the system. 3)服务器端代码将电子邮件与系统中注册的所有电子邮件进行比较。 If a match is found a link(self-destructing) to reset password is sent to the email address. 如果找到匹配项,则将重置密码的链接(自毁)发送到该电子邮件地址。

4) The user checks his email account to find the link and use it to reset a password. 4)用户检查他的电子邮件帐户以找到链接并使用它来重置密码。

Right now the code I have in user table is given down below. 现在,下面在用户表中提供的代码如下。

<?php

namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];


    public function events()
    {
        return $this->hasMany(Event::class);
    }


    public function request()
    {
        return $this->hasOne(Request::class);
    }
}

www.laravel.com/docs/5.1/authentication#resetting-passwords www.laravel.com/docs/5.1/authentication#resetting-passwords

Refer there for detailed methods. 有关详细方法,请参见此处。

Assuming you havent made any modification to the laravel installation. 假设您尚未对laravel安装进行任何修改。 it would be easy to make it. 这很容易做到。

User Model Editing 用户模型编辑

implement "Illuminate\\Contracts\\Auth\\CanResetPassword" on App\\User Model. 在应用程序\\用户模型上实施“ Illuminate \\ Contracts \\ Auth \\ CanResetPassword”。

Database Table Migration 数据库表迁移

run "php artisan migrate" command on console. 在控制台上运行“ php artisan migration”命令。

Routes 路线

add these routes to routes.php file. 将这些路由添加到routes.php文件。

// Password reset link request routes...
Route::get('password/email', 'Auth\PasswordController@getEmail');
Route::post('password/email', 'Auth\PasswordController@postEmail');

// Password reset routes...
Route::get('password/reset/{token}', 'Auth\PasswordController@getReset');
Route::post('password/reset', 'Auth\PasswordController@postReset');

View Files 查看文件

Go to Resources/views/auth and make two new files called 转到参考资料/视图/身份验证并创建两个名为

password.blade.php and reset.blade.php password.blade.php和reset.blade.php

password.blade.php content => " http://pastebin.com/RkcFU130 " password.blade.php content =>“ http://pastebin.com/RkcFU130

reset.blade.php content => " http://pastebin.com/6E5Kjqc4 " reset.blade.php content =>“ http://pastebin.com/6E5Kjqc4

Email View 电邮检视

now make a new file called password.blade.php at resources/views/emails/password.blade.php. 现在在resources / views / emails / password.blade.php上创建一个名为password.blade.php的新文件。

paste this inside it. 将此粘贴到里面。

Click here to reset your password: {{ url('password/reset/'.$token) }}

Post Reset Redirection 重置后重定向

if you want to redirect user to a specific url. 如果要将用户重定向到特定的URL。 you can paste this code to Passwordcontroller.php. 您可以将此代码粘贴到Passwordcontroller.php。 replace "dashboard" with the link you need to redirect to. 将“仪表盘”替换为您需要重定向到的链接。

protected $redirectTo = '/dashboard';

thats all :) 就这样 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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