paradox
paradox

Reputation: 113

laravel 5.2 auth Conditions for email verify

i want to edit auth and add Additional Conditions

for check user for active or ...

where can edit authcontroller code?

Upvotes: 0

Views: 1461

Answers (2)

Wiliam Decosta
Wiliam Decosta

Reputation: 21

In Auth\AuthController.php, add this function ( I assume the column name for user status is "is_active" ):

public function authenticated($request, $user) {
        if ($user->is_active != 'Y') {
            Auth::logout();
            return redirect('login')->withErrors([
                $this->loginUsername() => 'Your '.$this->loginUsername().' is not active. Please contact Administrators'
            ]);
        }else {
            return redirect()->intended($this->redirectPath());
        }
    }

Upvotes: 1

smartrahat
smartrahat

Reputation: 5609

First you need a status column in users table to mark the user as active or inactive.

To check the user status during login you need to modify this file:

project_folder\vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php

You can change validateLogin() method. I assume, for active user the status code is 1 and 0 for inactive user. Your code should look like this:

protected function validateLogin(Request $request)
{
    $this->validate($request, [
        $this->loginUsername() => 'required', 'password' => 'required', 'status' => 1,
    ]);
}

Upvotes: 1

Related Questions