protected function handleLogin(array $credentials = [], $remember = false)
    {
        $loginAttribute = strtolower(config('df.login_attribute', 'email'));
        if ($loginAttribute === 'username') {
            $username = array_get($credentials, 'username');
            if (empty($username)) {
                throw new BadRequestException('Login request is missing required username.');
            }
            unset($credentials['email']);
        } else {
            $email = array_get($credentials, 'email');
            if (empty($email)) {
                throw new BadRequestException('Login request is missing required email.');
            }
            unset($credentials['username']);
        }

        $password = array_get($credentials, 'password');
        if (empty($password)) {
            throw new BadRequestException('Login request is missing required password.');
        }

        $credentials['is_active'] = 1;

        // if user management not available then only system admins can login.
        if (!class_exists('\DreamFactory\Core\User\Resources\System\User')) {
            $credentials['is_sys_admin'] = 1;
        }

        if (Session::authenticate($credentials, $remember, true, $this->getAppId())) {
            return Session::getPublicInfo();
        } else {
            throw new UnauthorizedException('Invalid credentials supplied.');
        }
    }