mardi 23 octobre 2018

first time user login redirect to edit.blade, laravel

I'm just starting out on Laravel and building an application with Laravel 5.4. I wish to implement a functionality that detects when a user first log in into my application. This is because i want to redirect the user to the edit.blade page when he/she logs in for the first time. Can someone help me with that.

This is the code I have now in my controller:

 public function login(\Illuminate\Http\Request $request) {
    $this->validateLogin($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);
    }

    // This section is the only change
    if ($this->guard()->validate($this->credentials($request))) {
        $user = $this->guard()->getLastAttempted();

        // Make sure the user is active
        if ($user->verified && $this->attemptLogin($request)) {

            $first_time_login = true;
            if (Auth::user()->first_time_login) {
                $first_time_login = false;
                Auth::user()->first_time_login = 1; // Flip the flag to true
                Auth::user()->save(); // By that you tell it to save the new flag value into the users table
            }

            // Now send the variable $first_time_login to your view
            return view('edit.yourviewname', ['first_time_login' => $first_time_login]);


            $this->redirectTo = '/users/edit';
            // Send the normal successful login response
            return $this->sendLoginResponse($request);
        } else {
            // Increment the failed login attempts and redirect back to the
            // login form with an error message.
            $this->incrementLoginAttempts($request);
            session()->flash('dangerrr', 'Uh oh... You have not activated your account yet. 
            Please check your inbox for the jah activation link, or resend the link by clicking');
            throw ValidationException::withMessages([]);
        }
    }

    // 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);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire