/**
  * Boot the Twig Global Functions
  *
  * @param Silex\Application $app
  */
 public function boot(Application $app)
 {
     $app->extend('twig', function (\Twig_Environment $twig, Application $app) {
         $twig->addGlobal('app', null);
         $twig->addGlobal('forum_name', Config::get('forum_name', 'Boardy Forums'));
         $twig->addGlobal('current_user', Auth::user());
         $twig->addGlobal('request_uri', $app['request']->getRequestUri());
         $twig->addGlobal('request_route', $app['request']->get('_route'));
         if (isset($app['flashbag'])) {
             $twig->addGlobal('flashbag', $app['flashbag']);
         }
         return $twig;
     });
 }
示例#2
0
 public function register(Request $request, Application $app)
 {
     if (Auth::user()) {
         return $app->redirect($app->path('site.index'));
     }
     $vars = array();
     $form = Form::create('registration_form')->add('name', Type\TextType::class)->add('username', Type\TextType::class, ['constraints' => [new Assert\Regex(['pattern' => '/^[A-Za-z0-9_]+$/', 'match' => true, 'message' => 'Username must only contain alphanumeric characters and underscores.']), new CustomAssert\UniqueRecord(['model' => User::class, 'row' => 'username', 'message' => 'Username already in use.'])]])->add('email', Type\TextType::class, ['constraints' => [new Assert\Email(), new CustomAssert\UniqueRecord(['model' => User::class, 'row' => 'email', 'message' => 'Email already in use.'])]])->add('password', Type\RepeatedType::class, ['type' => Type\PasswordType::class, 'first_options' => ['label' => 'Password'], 'second_options' => ['label' => 'Repeat Password'], 'invalid_message' => 'Password fields did not match.', 'constraints' => [new Assert\Length(['min' => 8, 'minMessage' => 'Password must be at least 8 characters.'])]]);
     $form = $form->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $user = User::create($data);
         Auth::login($user);
         return $app->redirect($app->path('site.index'));
     }
     $vars['registration_form'] = $form->createView();
     return Theme::view('auth/register', $vars);
 }