Lina Lina - 5 months ago 61
PHP Question

How can i use idUser in a password_resets (laravel 5.2)

I want to use the table password_resets that I obtained with the comand php artisan make:auth, but this table use the "email" and this is not right because if my users change their email in their profile then is a problem to identify them, i want to use the "idUser" in the table "password_resets" instead of "email".

Where can i change this in the code????

Answer

thanks for your answer, finally I solved doing this:

Dirección: ...vendor/laravel/....DatabaseTokenRepository.php

/**
 * Create a new token record.
 *
 * @param  \Illuminate\Contracts\Auth\CanResetPassword  $user
 * @return string
 */
public function create(CanResetPasswordContract $user)
{
    $email = $user->getEmailForPasswordReset();
    $idUser = $user->idUser; //Aquí he añadido el idUser

    $this->deleteExisting($user);

    // We will create a new, random token for the user so that we can e-mail them
    // a safe link to the password reset form. Then we will insert a record in
    // the database so that we can verify the token within the actual reset.
    $token = $this->createNewToken();

    $this->getTable()->insert($this->getPayload($idUser, $email, $token)); //Aquí he añadido el idUser

    return $token;
}

/**
 * Delete all existing reset tokens from the database.
 *
 * @param  \Illuminate\Contracts\Auth\CanResetPassword  $user
 * @return int
 */
protected function deleteExisting(CanResetPasswordContract $user)
{
    return $this->getTable()->where('idUser', $user->idUser)->delete(); 
}