TransWikia.com

Cómo hacer el Password Reset Con un campo diferente a email Laravel 5.2

Stack Overflow en español Asked by yeyoguzmancito on February 8, 2021

Tengo en mi tabla users dos campos de emails, por lo que a uno lo llamo company_email y el otro personal_email, el login ya lo tengo con el campo company_email. Sin embargo quiero ahora que se pueda restablecer la contraseña introduciendo dicho campo para que envíe el token a ese email.

One Answer

Tendrás que hacer un override de lo siguiente:

app/Http/Controllers/Auth/PasswordController.php

Todos ellos son métodos de IlluminateFoundationAuthResetsPasswords

Revisalos por si me dejo algunos, hay que cambiar el valor email por company_email.

Tambén debes retocar las vistas cambiando email por company_email

/resources/views/auth/emails/password.blade.php /resources/views/auth/passwords/email.blade.php /resources/views/auth/passwords/reset.blade.php

Te pongo las funciones a agregar en app/Http/Controllers/Auth/PasswordController.php:

protected function validateSendResetLinkEmail(Request $request)
{
    $this->validate($request, ['company_email' => 'required|email']);
}

protected function getSendResetLinkEmailCredentials(Request $request)
{
    return $request->only('company_email');
}

protected function getSendResetLinkEmailFailureResponse($response)
{
    return redirect()->back()->withErrors(['company_email' => trans($response)]);
}

public function showResetForm(Request $request, $token = null)
{
    if (is_null($token)) {
        return $this->getEmail();
    }

    $email = $request->input('company_email');

    if (property_exists($this, 'resetView')) {
        return view($this->resetView)->with(compact('token', 'company_email'));
    }

    if (view()->exists('auth.passwords.reset')) {
        return view('auth.passwords.reset')->with(compact('token', 'company_email'));
    }

    return view('auth.reset')->with(compact('token', 'company_email'));
}

protected function getResetValidationRules()
{
    return [
        'token' => 'required',
        'company_email' => 'required|email',
        'password' => 'required|confirmed|min:6',
    ];
}

protected function getResetCredentials(Request $request)
{
    return $request->only(
        'company_email', 'password', 'password_confirmation', 'token'
    );
}

protected function getResetFailureResponse(Request $request, $response)
{
    return redirect()->back()
        ->withInput($request->only('company_email'))
        ->withErrors(['company_email' => trans($response)]);
}

Answered by Miguel Pérez on February 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP