Search code examples
authenticationcustomizationlaravel-5.6

Is there a way to customize laravel auth in order to verify if a user is previally stored in a old table?


I'm refactoring a pure PHP application to Laravel. I've already made Laravel auth. It works. However, I need a way of migrate old users and passwords to the new table. My idea is, at the login POST, verify if the user is stored on old table, if yes, insert that user on new table and procede with laravel auth. Can I override the login's method in LoginController to make these changes? Is It possible?


Solution

  • I had to override the login methods, adding the function migrationUserModelInternet($request).

    protected function login(Request $request) {

        $this->validateLogin($request);
    
        $this->migrationUserModelInternet($request);
    
        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);
    
            return $this->sendLockoutResponse($request);
        }
    
        if ($this->attemptLogin($request)) {
            return $this->sendLoginResponse($request);
        }
    
        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);
    
        return $this->sendFailedLoginResponse($request);
    }