mardi 28 août 2018

Laravel User registration after unsuccessful authorization

In Laravel 5.6 you need to do the following.

There is an authorization form - processes the LoginController, in my case I changed the email to name, and the password remained.

If such a user is with such a password, then I authorize it, and if the user does not have such a name and password, then it is necessary to register with the data that was entered.

Here is the class LoginController

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;


class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/';
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    protected function redirectTo()
    {
        return '/';
    }

    public function username() {
        return 'name';
    }

    /**
     * Handle a failed authorization attempt.
     *
     * @return void
     *
     * @throws \Illuminate\Auth\Access\AuthorizationException
     */


    protected function sendFailedLoginResponse(Request $request)
    {
        // What you need to do to register a user

    }
}

I thought to override sendFailedLoginResponse to register the user at that moment. Run as a RegisterController and transfer data from the POST request.

Tell me how to implement this idea?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire