Tuesday, March 21, 2017

login error message when user is inactive

i have laravel code that of login auth page, the problem is that when i login the inactive user, i shlud get error message that your user is not activated.

my code

public function postLogin(Request $request) {

    $credentials = $request->only(['username', 'password']);

    $validator = Validator::make($credentials, [
        'username' => 'required', 'password' => 'required',
    ]);

    //if the user is activeted then value will be 1 and not activted user will 0
     /// <--- THIS LINE

  if(!$credentials['active'] = 1)
    {
        return Redirect::back()->withInput()->withErrors($validator);
        return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
    }

    if ($validator->fails()) {
        return Redirect::back()->withInput()->withErrors($validator);
    }

    if (Auth::guard('admin')->attempt($credentials)) {
        admin_toastr(trans('admin::lang.login_successful'));

        return redirect()->intended(config('admin.prefix'));
    }


    return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);


}



via kinzang

Advertisement