Lumen 6x重设密码

问题描述 投票:0回答:1

我正在Lumen 6x中实现重置密码。

1)我安装了这些软件包:

撰写者需要说明/邮件

撰写者需要说明/通知

composer require ramsey / uuid

2)我复制了这些laravel文件:

config / auth.php

config / mail.php

3)我在bootstrap / app.php中添加了>

$app->configure('auth');
$app->configure('mail');

$app->register(Illuminate\Notifications\NotificationServiceProvider::class);
$app->register(\Illuminate\Mail\MailServiceProvider::class);
$app->alias('mailer',\Illuminate\Contracts\Mail\Mailer::class);

4)我创建了password_resets表(与laravel相同)

5)我的AuthController.php

/**
 * Send reset password email
 */
public function generateResetToken(Request $request)
{
    // Check email address is valid
    $this->validate($request, [
        'usuario' => 'required|string|email'
    ]);

    // Send password reset to the user with this email address
    $response = $this->broker()->sendResetLink(
        array('usuario' => $request->usuario)
    );

    return $response == Password::RESET_LINK_SENT
        ? response()->json(true)
        : response()->json(false);
}

/**
 * Reset Password
 */
public function resetPassword(Request $request, $token, $usuario, $password)
{
    // Check input is valid
    $rules = [
        'token'    => 'required',
        'usuario' => 'required|string',
        'password' => 'required|string',
    ];
    $this->validate($request, $rules);

    // Reset the password
    $response = $this->broker()->reset(
    $this->credentials($request),
        function ($user, $password) {
            $user->password = app('hash')->make($password);
            $user->save();
        }
    );

    return $response == Password::PASSWORD_RESET
        ? response()->json(true)
        : response()->json(false);
}

6)我的用户模型:

<?php
 namespace App;
 use Illuminate\Auth\Authenticatable;
 use Illuminate\Contracts\Auth\Access    \Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
  use Illuminate\Database\Eloquent\Model;
  use Laravel\Lumen\Auth\Authorizable;
  use Tymon\JWTAuth\Contracts\JWTSubject;
  use Illuminate\Auth\Passwords\CanResetPassword as CanResetPasswordTrait;
  use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordInterface;
  use Illuminate\Notifications\Notifiable;

 class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject, CanResetPasswordInterface
{
 use Authenticatable, Authorizable, CanResetPasswordTrait, Notifiable;

protected $table = 'usuarios';

public $timestamps = false;
/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'usuario', 'clave',
];

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = [
    'clave',
];

/**
 * Get the password for the user.
 *
 * @return string
 */
public function getAuthPassword()
{
    return $this->clave;
}

public function routeNotificationForMail($notification)
{
    return $this->usuario;
}

public function getEmailForPasswordReset() {
    return $this->usuario;
}

/**
 * Get the identifier that will be stored in the subject claim of the JWT.
 *
 * @return mixed
 */
public function getJWTIdentifier()
{
    return $this->getKey();
}

/**
 * Return a key value array, containing any custom claims to be added to the JWT.
 *
 * @return array
 */
public function getJWTCustomClaims()
{
    return [];
}
}

7)我的路线/web.php

$router->group(['prefix' => 'api'], function () use ($router) {
$router->post('login', 'AuthController@login');
$router->post('user', 'AuthController@user');
$router->post('logout', 'AuthController@logout');
$router->post('refresh', 'AuthController@refresh');

$router->get('resetpassword',[
    'as' => 'password.reset', 'uses'=>'AuthController@generateResetToken']);
$router->put('resetpassword/{token}/{usuario}/{password}', ['as' => 'password.reset', 'uses' => 'AuthController@resetPassword']);
});

问题:1)我收到带有重置链接的电子邮件,但链接错误:

[http://localhosthttp://localhost:8000/api/ resetpassword?token = 8441282d750cba5b80af24e07593d5d094c392084f611b13e0f283cb6918e4de&email = testmail%40gmail.com]

2)我修复了链接,并尝试与邮递员进行查询,但收到此错误:

(1/1)RoutesRequests.php行231中的MethodNotAllowedHttpException

我正在Lumen 6x中实现重置密码。 1)我安装了以下软件包:作曲家需要照亮/邮件作曲家需要照亮/通知作曲家需要ramsey / uuid 2)...

laravel lumen
1个回答
0
投票

第一个问题是因为您的链接未正确安装,请在安装位置显示代码,以帮助我,

© www.soinside.com 2019 - 2024. All rights reserved.