Returns a form for a Two-Factor Auth login page.

@param UserConfig $user
@param AreaContract $area
@param Provider $provider
@param String $secretKey
@return \Antares\Contracts\Html\Builder
326643
public function verify(UserConfig $user, AreaContract $area, Provider $provider, $secretKey = null)
    {
        return $this->formFactory->of('antares.two_factor_auth.provider.auth.verify', function (FormGrid $form) use ($user, $area, $provider, $secretKey) {
                    $form->simple(handles('two_factor_auth.post.verify', compact('area')));
                    $form->name('Two-Factor Authentication User Verification Form');
                    $form->layout('antares/two_factor_auth::admin.auth.partials._form');

                    $form->hidden('provider_id', function ($field) use ($provider) {
                        $field->value = $provider->getId();
                    });
                    $form->hidden('user_id', function ($field) use ($user) {
                        $field->value = $user->getId();
                    });
                    $form->hidden('secret_key', function ($field) use ($secretKey) {
                        $field->value = $secretKey;
                    });

                    $title = trans('antares/two_factor_auth::auth.verify');

                    $form->fieldset($title, function (Fieldset $fieldset) use ($user, $provider) {
                        $provider->getProviderGateway()->setupVerifyFormFieldset($fieldset, $user);

                        $fieldset->control('button', 'button')
                                ->attributes(['type' => 'submit', 'class' => 'btn btn-primary'])
                                ->value(trans('Submit & Save'));
                        if (!$user->configured) {
                            $fieldset->control('button', 'cancel')
                                    ->field(function() {
                                        return app('html')->link(handles('two_factor_auth.get.configuration', ['area' => area()]), trans('Go Back'), ['class' => 'btn btn--md btn--default mdl-button mdl-js-button']);
                                    });
                        }
                    });
                });
    }
374857
function findByUserAndProvider(UserInterface $user, $providerName) {
		return SocialProfile::where('provider', '=', $providerName)->whereUserId($user->getAuthIdentifier())->first();
	}
12191
public function configure(UserConfigurationListener $listener, AreaContract $area)
    {
        $provider   = $this->twoFactorProvidersService->getEnabledInArea($area);
        $userConfig = $this->userConfigService->saveConfig($provider);


        $form = $this->presenter->configure($userConfig, $area, $provider);

        $this->dispatcher->fire('antares.form: two_factor_auth', [$provider, $form]);

        return $listener->showConfiguration($provider, $form);
    }
377010
protected function linkProvider($user_id, $provider, $provider_id, $access_token)
	{
		$user_provider = new Provider;
		$user_provider->user_id = $user_id;
		$user_provider->provider = strtolower($provider);
		$user_provider->provider_id = $provider_id;
		$user_provider->access_token = $access_token;
		$user_provider->save();
		
		return $user_provider;
	}
101550
public function createAuthenticatedToken(UserInterface $user, $providerKey)
    {
        $preAuthToken = $this->preAuthenticationTokenStorage->getToken();

        if (null === $preAuthToken) {
            throw new \RuntimeException('Unable to return an authenticated token since there is no pre authentication token.');
        }

        $authToken = new JWTUserToken($user->getRoles(), $user, $preAuthToken->getCredentials(), $providerKey);

        if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
            $this->dispatcher->dispatch(new JWTAuthenticatedEvent($preAuthToken->getPayload(), $authToken), Events::JWT_AUTHENTICATED);
        } else {
            $this->dispatcher->dispatch(Events::JWT_AUTHENTICATED, new JWTAuthenticatedEvent($preAuthToken->getPayload(), $authToken));
        }

        $this->preAuthenticationTokenStorage->setToken(null);

        return $authToken;
    }
459635
public function createUser(User $user, $password)
    {
        $request = $user->toJson();
        $request['password'] = $password;
        $response = $this->client->post('/v2/user', $request);

        return $response['id'];
    }
610291
public function createUserProvider($provider)
    {
        $config = $this->app['config']["auth.providers.{$provider}"];

        // Retrieve the driver from configuration.
        $driver = $config['driver'];

        if (isset($this->customProviderCreators[$driver])) {
            $callback = $this->customProviderCreators[$driver];

            return call_user_func($callback, $this->app, $config);
        }

        switch ($driver) {
            case 'database':
                return $this->createDatabaseProvider($config);

            case 'extended':
                return $this->createExtendedProvider($config);

            default:
                break;
        }

        throw new InvalidArgumentException("Authentication user provider [{$driver}] is not defined.");
    }
24492
public function disable(UserConfigurationListener $listener, User $user, AreaContract $area)
    {
        try {
            $userConfig = $this->getUserConfig($user, $area);

            $this->userConfigRepository->markAsDisabledById($userConfig->id);

            $msg = trans('antares/two_factor_auth::configuration.responses.disable.success', ['area' => $area->getLabel()]);

            return $listener->disableSuccess($msg);
        } catch (Exception $e) {
            Log::emergency($e);

            $msg = trans('antares/two_factor_auth::configuration.responses.disable.fail', ['area' => $area->getLabel()]);

            return $listener->disableFailed($msg);
        }
    }
848117
public function edit(ConfigurationListener $listener, AreaContract $area, Provider $provider)
    {
        $provider->area    = $area->getId();
        $provider->enabled = true;

        $provider->setProviderGateway($this->twoFactorProvidersService->getProviderGatewayByName($provider->name));

        $form = $this->presenter->form($provider);

        Event::fire("antares.form: two_factor_auth", [$provider, $form]);
        Event::fire("antares.form: foundation.two_factor_auth", [$provider, $form, "foundation.two_factor_auth"]);

        return $listener->showProviderConfiguration($form);
    }
1347041
public static function getUserGuard(Authenticatable $user)
    {
        $provider = self::getUserProvider($user);

        return self::getProviderGuard($provider, $user);
    }
700510
public function validateCredentials(UserContract $user, array $credentials) {
        foreach ($credentials as $columnName => $value) {
            if (is_string($columnName) && !is_numeric($columnName)) {
                if ($columnName === 'password') {
                    if (!\Hash::check($value, $user->getAuthPassword())) {
                        return false;
                    }
                } else if ($user->$columnName !== $value) {
                    return false;
                }
            }
        }

        return true;
    }
1050707
public function validateCredentials(UserContract $user, array $credentials): bool
    {
        $plain = $credentials['password'];
        $hashed = $user->getAuthPassword();

        if (\strlen($hashed) === 0) {
            return false;
        }

        return \password_verify($plain, $hashed) || $this->hasher->check($plain, $hashed);
    }
128470
public function createUserProvider($provider = null)
    {
        if (is_null($config = $this->getProviderConfiguration($provider))) {
            return;
        }

        if (isset($this->customProviderCreators[$driver = ($config['driver'] ?? null)])) {
            return call_user_func(
                $this->customProviderCreators[$driver], $this->app, $config
            );
        }

        switch ($driver) {
            case 'database':
                return $this->createDatabaseProvider($config);
            case 'eloquent':
                return $this->createEloquentProvider($config);
            default:
                throw new InvalidArgumentException(
                    "Authentication user provider [{$driver}] is not defined."
                );
        }
    }
128204
public function index(User $user, Collection $areaProvidersCollection)
    {
        $items = [];

        foreach ($areaProvidersCollection as $areaProviders) {
            /* @var $areaProviders AreaProviders */

            $enabled = $areaProviders->getEnabledModel();

            if (!$enabled instanceof Provider) {
                continue;
            }

            $area = $areaProviders->getArea();

            if ($enabled->isForced()) {
                $items[] = [
                    'area' => $area,
                    'line' => trans('antares/two_factor_auth::configuration.activated'),
                ];
            } elseif ($this->userProviderConfigService->hasEnabledArea($area)) {
                $url   = handles('two_factor_auth.user.configuration.disable', compact('area', 'user'));
                $attrs = [
                    'class'            => 'triggerable confirm',
                    'data-title'       => trans('antares/two_factor_auth::configuration.disable.title'),
                    'data-description' => trans('antares/two_factor_auth::configuration.disable.prompt'),
                    'data-icon'        => 'minus',
                ];

                $items[] = [
                    'area' => $area,
                    'line' => HTML::link($url, trans('antares/two_factor_auth::configuration.disable.label'), $attrs),
                ];
            } else {
                $url   = handles('two_factor_auth.user.configuration.enable', compact('area', 'user'));
                $attrs = [
                    'class'            => 'triggerable confirm',
                    'data-title'       => trans('antares/two_factor_auth::configuration.enable.title'),
                    'data-description' => trans('antares/two_factor_auth::configuration.enable.prompt'),
                    'data-icon'        => 'minus',
                ];

                $items[] = [
                    'area' => $area,
                    'line' => HTML::link($url, trans('antares/two_factor_auth::configuration.enable.label'), $attrs),
                ];
            }
        }

        return $items;
    }
1373972
public function createAuthenticationProvider(\Silex\Application $app,
                                                 UserProviderInterface $userProvider,
                                                 $providerKey)
    {
        return new DaoAuthenticationProvider($userProvider,
            $app['security.user_checker'], $providerKey,
            $this->encoderFactory ? : $app['security.encoder_factory']);
    }
740331
public function verify(AuthListener $listener, AreaContract $area)
    {
        $provider   = $this->service->getEnabledInArea($area);
        $userConfig = $this->userConfigService->getSettingsByArea($area);
        $form       = $this->presenter->verify($userConfig, $area, $provider);

        return $listener->showVerifyForm($provider, $form);
    }
245434
public function enable(UserConfigurationListener $listener, User $user, AreaContract $area)
    {
        try {
            $userConfig = $this->getUserConfig($user, $area);

            $this->userConfigRepository->markAsEnabledById($userConfig->id);

            if ($this->isConfigured($area)) {
                $msg = trans('antares/two_factor_auth::configuration.responses.enable.success', ['area' => $area->getLabel()]);
                return $listener->afterConfiguration($area, $msg);
            }

            return $this->configure($listener, $area);
        } catch (Exception $e) {
            Log::emergency($e);

            $msg = trans('antares/two_factor_auth::configuration.responses.enable.fail', ['area' => $area->getLabel()]);

            return $listener->enableFailed($msg);
        }
    }