<commit_before><?php namespace Orchestra\Foundation\Http\Presenters;

use Orchestra\Contracts\Html\Form\Fieldset;
use Illuminate\Contracts\Encryption\Encrypter;
use Orchestra\Contracts\Html\Form\Grid as FormGrid;
use Orchestra\Contracts\Html\Form\Factory as FormFactory;

class Setting extends Presenter
{
    /**
     * The encrypter implementation.
     *
     * @var \Illuminate\Contracts\Encryption\Encrypter
     */
    protected $encrypter;

    /**
     * Construct a new User presenter.
     *
     * @param  \Orchestra\Contracts\Html\Form\Factory  $form
     * @param  \Illuminate\Contracts\Encryption\Encrypter  $encrypter
     */
    public function __construct(FormFactory $form, Encrypter $encrypter)
    {
        $this->form = $form;
        $this->encrypter = $encrypter;
    }

    /**
     * Form View Generator for Setting Page.
     *
     * @param  \Illuminate\Support\Fluent  $model
     *
     * @return \Orchestra\Contracts\Html\Form\Builder
     */
    public function form($model)
    {
        return $this->form->of('orchestra.settings', function (FormGrid $form) use ($model) {
            $form->setup($this, 'orchestra::settings', $model);

            $this->application($form);
            $this->mailer($form, $model);
        });
    }

    /**
     * Form view generator for application configuration.
     *
     * @param  \Orchestra\Contracts\Html\Form\Grid  $form
     *
     * @return void
     */
    protected function application(FormGrid $form)
    {
        $form->fieldset(trans('orchestra/foundation::label.settings.application'), function (Fieldset $fieldset) {
            $fieldset->control('input:text', 'site_name')
                ->label(trans('orchestra/foundation::label.name'));

            $fieldset->control('textarea', 'site_description')
                ->label(trans('orchestra/foundation::label.description'))
                ->attributes(['rows' => 3]);

            $fieldset->control('select', 'site_registrable')
                ->label(trans('orchestra/foundation::label.settings.user-registration'))
                ->attributes(['role' => 'agreement'])
                ->options([
                    'yes' => 'Yes',
                    'no'  => 'No',
                ]);
        });
    }

    /**
     * Form view generator for email configuration.
     *
     * @param  \Orchestra\Contracts\Html\Form\Grid  $form
     * @param  \Illuminate\Support\Fluent  $model
     *
     * @return void
     */
    protected function mailer(FormGrid $form, $model)
    {
        $encrypter = $this->encrypter;

        $form->fieldset(trans('orchestra/foundation::label.settings.mail'), function (Fieldset $fieldset) use ($encrypter, $model) {
            $fieldset->control('select', 'email_driver')
                ->label(trans('orchestra/foundation::label.email.driver'))
                ->options([
                    'mail'     => 'Mail',
                    'smtp'     => 'SMTP',
                    'sendmail' => 'Sendmail',
                    'ses'      => 'Amazon SES',
                    'mailgun'  => 'Mailgun',
                    'mandrill' => 'Mandrill',
                ]);

            $fieldset->control('input:text', 'email_host')
                ->label(trans('orchestra/foundation::label.email.host'));

            $fieldset->control('input:text', 'email_port')
                ->label(trans('orchestra/foundation::label.email.port'));

            $fieldset->control('input:text', 'email_address')
                ->label(trans('orchestra/foundation::label.email.from'));

            $fieldset->control('input:text', 'email_username')
                ->label(trans('orchestra/foundation::label.email.username'));

            $fieldset->control('input:password', 'email_password')
                ->label(trans('orchestra/foundation::label.email.password'))
                ->help(view('orchestra/foundation::settings._hidden', [
                    'model'  => $model,
                    'action' => 'change_password',
                    'field'  => 'email_password',
                ]));

            $fieldset->control('input:text', 'email_encryption')
                ->label(trans('orchestra/foundation::label.email.encryption'));

            $fieldset->control('input:text', 'email_key')
                ->label(trans('orchestra/foundation::label.email.key'))
                ->value(function ($row) use ($encrypter) {
                    return $encrypter->decrypt($row->email_key);
                });

            $fieldset->control('input:password', 'email_secret')
                ->label(trans('orchestra/foundation::label.email.secret'))
                ->value(function ($row) use ($encrypter) {
                    return $encrypter->decrypt($row->email_secret);
                })
                ->help(view('orchestra/foundation::settings._hidden', [
                    'model'  => $model,
                    'action' => 'change_secret',
                    'field'  => 'email_secret',
                ]));

            $fieldset->control('input:text', 'email_domain')
                ->label(trans('orchestra/foundation::label.email.domain'));

            $fieldset->control('select', 'email_region')
                ->label(trans('orchestra/foundation::label.email.region'))
                ->options([
                    'us-east-1' => 'us-east-1',
                    'us-west-2' => 'us-west-2',
                    'eu-west-1' => 'eu-west-1',
                ]);

            $fieldset->control('input:text', 'email_sendmail')
                ->label(trans('orchestra/foundation::label.email.command'));

            $fieldset->control('select', 'email_queue')
                ->label(trans('orchestra/foundation::label.email.queue'))
                ->attributes(['role' => 'agreement'])
                ->options([
                    'yes' => 'Yes',
                    'no'  => 'No',
                ]);
        });
    }
}<commit_msg>Return original value if decryption failed.<commit_after><?php namespace Orchestra\Foundation\Http\Presenters;

use Orchestra\Contracts\Html\Form\Fieldset;
use Illuminate\Contracts\Encryption\Encrypter;
use Orchestra\Contracts\Html\Form\Grid as FormGrid;
use Illuminate\Contracts\Encryption\DecryptException;
use Orchestra\Contracts\Html\Form\Factory as FormFactory;

class Setting extends Presenter
{
    /**
     * The encrypter implementation.
     *
     * @var \Illuminate\Contracts\Encryption\Encrypter
     */
    protected $encrypter;

    /**
     * Construct a new User presenter.
     *
     * @param  \Orchestra\Contracts\Html\Form\Factory  $form
     * @param  \Illuminate\Contracts\Encryption\Encrypter  $encrypter
     */
    public function __construct(FormFactory $form, Encrypter $encrypter)
    {
        $this->form = $form;
        $this->encrypter = $encrypter;
    }

    /**
     * Form View Generator for Setting Page.
     *
     * @param  \Illuminate\Support\Fluent  $model
     *
     * @return \Orchestra\Contracts\Html\Form\Builder
     */
    public function form($model)
    {
        return $this->form->of('orchestra.settings', function (FormGrid $form) use ($model) {
            $form->setup($this, 'orchestra::settings', $model);

            $this->application($form);
            $this->mailer($form, $model);
        });
    }

    /**
     * Form view generator for application configuration.
     *
     * @param  \Orchestra\Contracts\Html\Form\Grid  $form
     *
     * @return void
     */
    protected function application(FormGrid $form)
    {
        $form->fieldset(trans('orchestra/foundation::label.settings.application'), function (Fieldset $fieldset) {
            $fieldset->control('input:text', 'site_name')
                ->label(trans('orchestra/foundation::label.name'));

            $fieldset->control('textarea', 'site_description')
                ->label(trans('orchestra/foundation::label.description'))
                ->attributes(['rows' => 3]);

            $fieldset->control('select', 'site_registrable')
                ->label(trans('orchestra/foundation::label.settings.user-registration'))
                ->attributes(['role' => 'agreement'])
                ->options([
                    'yes' => 'Yes',
                    'no'  => 'No',
                ]);
        });
    }

    /**
     * Form view generator for email configuration.
     *
     * @param  \Orchestra\Contracts\Html\Form\Grid  $form
     * @param  \Illuminate\Support\Fluent  $model
     *
     * @return void
     */
    protected function mailer(FormGrid $form, $model)
    {
        $form->fieldset(trans('orchestra/foundation::label.settings.mail'), function (Fieldset $fieldset) use ($model) {
            $fieldset->control('select', 'email_driver')
                ->label(trans('orchestra/foundation::label.email.driver'))
                ->options([
                    'mail'     => 'Mail',
                    'smtp'     => 'SMTP',
                    'sendmail' => 'Sendmail',
                    'ses'      => 'Amazon SES',
                    'mailgun'  => 'Mailgun',
                    'mandrill' => 'Mandrill',
                ]);

            $fieldset->control('input:text', 'email_host')
                ->label(trans('orchestra/foundation::label.email.host'));

            $fieldset->control('input:text', 'email_port')
                ->label(trans('orchestra/foundation::label.email.port'));

            $fieldset->control('input:text', 'email_address')
                ->label(trans('orchestra/foundation::label.email.from'));

            $fieldset->control('input:text', 'email_username')
                ->label(trans('orchestra/foundation::label.email.username'));

            $fieldset->control('input:password', 'email_password')
                ->label(trans('orchestra/foundation::label.email.password'))
                ->help(view('orchestra/foundation::settings._hidden', [
                    'model'  => $model,
                    'action' => 'change_password',
                    'field'  => 'email_password',
                ]));

            $fieldset->control('input:text', 'email_encryption')
                ->label(trans('orchestra/foundation::label.email.encryption'));

            $fieldset->control('input:text', 'email_key')
                ->label(trans('orchestra/foundation::label.email.key'))
                ->value(function ($row) {
                    return $this->getDecryptedValue($row->email_key);
                });

            $fieldset->control('input:password', 'email_secret')
                ->label(trans('orchestra/foundation::label.email.secret'))
                ->value(function ($row) {
                    return $this->getDecryptedValue($row->email_secret);
                })
                ->help(view('orchestra/foundation::settings._hidden', [
                    'model'  => $model,
                    'action' => 'change_secret',
                    'field'  => 'email_secret',
                ]));

            $fieldset->control('input:text', 'email_domain')
                ->label(trans('orchestra/foundation::label.email.domain'));

            $fieldset->control('select', 'email_region')
                ->label(trans('orchestra/foundation::label.email.region'))
                ->options([
                    'us-east-1' => 'us-east-1',
                    'us-west-2' => 'us-west-2',
                    'eu-west-1' => 'eu-west-1',
                ]);

            $fieldset->control('input:text', 'email_sendmail')
                ->label(trans('orchestra/foundation::label.email.command'));

            $fieldset->control('select', 'email_queue')
                ->label(trans('orchestra/foundation::label.email.queue'))
                ->attributes(['role' => 'agreement'])
                ->options([
                    'yes' => 'Yes',
                    'no'  => 'No',
                ]);
        });
    }

    /**
     * Get decrypted configuration value.
     *
     * @param  string  $value
     *
     * @return string
     */
    public function getDecryptedValue($value)
    {
        try {
            return $this->encrypter->decrypt($value);
        } catch (DecryptException $e) {
            return $value;
        }
    }
}
{'fraction_non_alphanumeric': 0.15591836734693879, 'fraction_numerical': 0.001142857142857143, 'mean_word_length': 1.8873438604760782, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 162, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246296', 'n_tokens_mistral': 3480, 'n_tokens_neox': 3388, 'n_words': 484}