<commit_before><?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Form\FormError;
use Symfony\Component\Validator\Constraints as Assert;

$app['security.firewalls'] = [
  'unsecured' => [
    'anonymous' => true,
    'pattern' => '^/admin',
  ],
  'admin' => [
    'pattern' => '^/admin',
    'http' => true,
    'users' => [
      'admin' => ['ROLE_ADMIN', $app['config']['adminPassword']],
    ],
  ],
];
$app['security.access_rules'] = [
  ['^/admin', 'ROLE_ADMIN'],
  ['^.*$', 'ROLE_USER'],
];

$sharedAuthentication = function (Request $request, Silex\Application $app) {
  if ($app['session']->get('isSharedAuthenticated') !== true) {
    return new RedirectResponse('/');
  }
};

$app->get('/', function () use ($app) {
  return $app['twig']->render('index.twig');
})
->bind('home');

$app->post('/', function (Request $request) use ($app) {
  if ($request->get('password') === $app['config']['sharedPassword']) {
    $app['session']->set('isSharedAuthenticated', true);
  }
  return $app->redirect('/apply');
});

// match will accept GET or POST requests
$app->match('/apply', function (Request $request) use ($app) {
  $form = $app['form.factory']->createBuilder('form')
    ->add('name', 'text', [
      'label' => 'Real Name *',
      'attr' => [ 'placeholder' => '<NAME>' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('nickname', 'text', [
      'label' => 'Nickname *',
      'attr' => [ 'placeholder' => 'jsmithy' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('contact_email', 'email', [
      'label' => 'Contact Email address *',
      'attr' => [ 'placeholder' => '<EMAIL>' ],
      'constraints' => [ new Assert\NotBlank(), new Assert\Email() ],
    ])
    ->add('list_email', 'email', [
      'label' => 'Mailing List Email address *',
      'attr' => [ 'placeholder' => '<EMAIL>' ],
      'constraints' => [ new Assert\NotBlank(), new Assert\Email() ],
    ])
    ->add('bio_reason', 'textarea', [
      'label' => 'Why do you want to join Hacklab? *',
      'attr' => [ 'placeholder' => 'Enter a few sentences about yourself and why you want to join Hacklab.TO' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('face_url', 'url', [
      'label' => 'Bio Picture (URL)',
      'attr' => [ 'placeholder' => 'http://www.example.com/my-face.jpg' ],
      'constraints' => [],
    ])
    ->add('face_file', 'file', [
      'label' => 'Bio Picture (Upload)',
      'constraints' => [],
    ])
    ->add('sponsor', 'text', [
      'label' => 'Name of sponsoring member *',
      'attr' => [ 'placeholder' => 'Ada Lovelace' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('second_sponsor', 'text', [
      'label' => 'Seconding member? *',
      'attr' => [ 'placeholder' => '<NAME>' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('twitter', 'text', [
      'label' => 'Twitter',
      'attr' => [ 'placeholder' => '@username' ],
      'constraints' => [],
    ])
    ->add('facebook', 'url', [
      'label' => 'Facebook',
      'attr' => [ 'placeholder' => 'http://www.facebook.com/your.name' ],
      'constraints' => [],
    ])
    ->add('heard_from', 'textarea', [
      'label' => 'How\'d you hear about us?',
      'attr' => [ 'placeholder' => 'Some bloke just down the street' ],
      'constraints' => [],
    ])
    ->getForm();

  $form->handleRequest($request);

  if ($form->isValid()) {
    $data = $form->getData();
    $data['profile_hash'] = sha1($data['nickname']);

    if ($data['face_file'] && $data['face_file']->isValid()) {
      $extension = $data['face_file']->guessExtension();
      if (is_null($extension)) {
        $extension = $data['face_file']->getExtension();
      }
      $data['picture'] = $data['nickname'] . '.' . $extension;
      $data['face_file']->move(
        __DIR__ . '/../profiles/',
        $data['picture']
      );
    }

    try {
      $app['db']->executeUpdate(
        'INSERT INTO applicants (
          name, nickname, contact_email, list_email, bio_reason, sponsor,
          second_sponsor, picture, twitter, facebook, heard_from, profile_hash
        )
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
        [
          $data['name'],
          $data['nickname'],
          $data['contact_email'],
          $data['list_email'],
          $data['bio_reason'],
          $data['sponsor'],
          $data['second_sponsor'],
          $data['picture'],
          $data['twitter'],
          $data['facebook'],
          $data['heard_from'],
          $data['profile_hash'],
        ]
      );
    } catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $exception) {
      $form->addError(new FormError('Nickname is already in use'));
      return $app['twig']->render('apply.twig', [
        'form' => $form->createView()
      ]);
    }

    if (!mail(
      implode(', ', $app['config']['emails']) ,
      "{$data['name']} ({$data['nickname']}) has applied!",
      $app['twig']->render('email.twig', $data)
    )) {
      throw new Exception("Error Sending Email", 1);
    }

    // Reset for the next user
    $app['session']->set('isSharedAuthenticated', false);
    return $app->redirect('payment');
  }

  return $app['twig']->render('apply.twig', [
    'form' => $form->createView()
  ]);
})
->method('GET|POST')
->before($sharedAuthentication)
->bind('apply');<commit_msg>Make email maybe go to spam less<commit_after><?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Form\FormError;
use Symfony\Component\Validator\Constraints as Assert;

$app['security.firewalls'] = [
  'unsecured' => [
    'anonymous' => true,
    'pattern' => '^/admin',
  ],
  'admin' => [
    'pattern' => '^/admin',
    'http' => true,
    'users' => [
      'admin' => ['ROLE_ADMIN', $app['config']['adminPassword']],
    ],
  ],
];
$app['security.access_rules'] = [
  ['^/admin', 'ROLE_ADMIN'],
  ['^.*$', 'ROLE_USER'],
];

$sharedAuthentication = function (Request $request, Silex\Application $app) {
  if ($app['session']->get('isSharedAuthenticated') !== true) {
    return new RedirectResponse('/');
  }
};

$app->get('/', function () use ($app) {
  return $app['twig']->render('index.twig');
})
->bind('home');

$app->post('/', function (Request $request) use ($app) {
  if ($request->get('password') === $app['config']['sharedPassword']) {
    $app['session']->set('isSharedAuthenticated', true);
  }
  return $app->redirect('/apply');
});

// match will accept GET or POST requests
$app->match('/apply', function (Request $request) use ($app) {
  $form = $app['form.factory']->createBuilder('form')
    ->add('name', 'text', [
      'label' => 'Real Name *',
      'attr' => [ 'placeholder' => '<NAME>' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('nickname', 'text', [
      'label' => 'Nickname *',
      'attr' => [ 'placeholder' => 'jsmithy' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('contact_email', 'email', [
      'label' => 'Contact Email address *',
      'attr' => [ 'placeholder' => '<EMAIL>' ],
      'constraints' => [ new Assert\NotBlank(), new Assert\Email() ],
    ])
    ->add('list_email', 'email', [
      'label' => 'Mailing List Email address *',
      'attr' => [ 'placeholder' => '<EMAIL>' ],
      'constraints' => [ new Assert\NotBlank(), new Assert\Email() ],
    ])
    ->add('bio_reason', 'textarea', [
      'label' => 'Why do you want to join Hacklab? *',
      'attr' => [ 'placeholder' => 'Enter a few sentences about yourself and why you want to join Hacklab.TO' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('face_url', 'url', [
      'label' => 'Bio Picture (URL)',
      'attr' => [ 'placeholder' => 'http://www.example.com/my-face.jpg' ],
      'constraints' => [],
    ])
    ->add('face_file', 'file', [
      'label' => 'Bio Picture (Upload)',
      'constraints' => [],
    ])
    ->add('sponsor', 'text', [
      'label' => 'Name of sponsoring member *',
      'attr' => [ 'placeholder' => 'Ada Lovelace' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('second_sponsor', 'text', [
      'label' => 'Seconding member? *',
      'attr' => [ 'placeholder' => '<NAME>' ],
      'constraints' => [ new Assert\NotBlank() ],
    ])
    ->add('twitter', 'text', [
      'label' => 'Twitter',
      'attr' => [ 'placeholder' => '@username' ],
      'constraints' => [],
    ])
    ->add('facebook', 'url', [
      'label' => 'Facebook',
      'attr' => [ 'placeholder' => 'http://www.facebook.com/your.name' ],
      'constraints' => [],
    ])
    ->add('heard_from', 'textarea', [
      'label' => 'How\'d you hear about us?',
      'attr' => [ 'placeholder' => 'Some bloke just down the street' ],
      'constraints' => [],
    ])
    ->getForm();

  $form->handleRequest($request);

  if ($form->isValid()) {
    $data = $form->getData();
    $data['profile_hash'] = sha1($data['nickname']);

    if ($data['face_file'] && $data['face_file']->isValid()) {
      $extension = $data['face_file']->guessExtension();
      if (is_null($extension)) {
        $extension = $data['face_file']->getExtension();
      }
      $data['picture'] = $data['nickname'] . '.' . $extension;
      $data['face_file']->move(
        __DIR__ . '/../profiles/',
        $data['picture']
      );
    }

    try {
      $app['db']->executeUpdate(
        'INSERT INTO applicants (
          name, nickname, contact_email, list_email, bio_reason, sponsor,
          second_sponsor, picture, twitter, facebook, heard_from, profile_hash
        )
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
        [
          $data['name'],
          $data['nickname'],
          $data['contact_email'],
          $data['list_email'],
          $data['bio_reason'],
          $data['sponsor'],
          $data['second_sponsor'],
          $data['picture'],
          $data['twitter'],
          $data['facebook'],
          $data['heard_from'],
          $data['profile_hash'],
        ]
      );
    } catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $exception) {
      $form->addError(new FormError('Nickname is already in use'));
      return $app['twig']->render('apply.twig', [
        'form' => $form->createView()
      ]);
    }

    $headers = 'From: Applications <<EMAIL>>' . "\r\n" .
      'Reply-To: <EMAIL>' . "\r\n" .
      'X-Mailer: PHP/' . phpversion();

    if (!mail(
      implode(', ', $app['config']['emails']) ,
      "{$data['name']} ({$data['nickname']}) has applied!",
      wordwrap($app['twig']->render('email.twig', $data), 70, "\r\n"),
      $headers
    )) {
      throw new Exception("Error Sending Email", 1);
    }

    // Reset for the next user
    $app['session']->set('isSharedAuthenticated', false);
    return $app->redirect('payment');
  }

  return $app['twig']->render('apply.twig', [
    'form' => $form->createView()
  ]);
})
->method('GET|POST')
->before($sharedAuthentication)
->bind('apply');
{'fraction_non_alphanumeric': 0.23047191011235954, 'fraction_numerical': 0.0005393258426966292, 'mean_word_length': 2.8820655966503836, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 210, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2182520', 'n_tokens_mistral': 3687, 'n_tokens_neox': 3616, 'n_words': 677}