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); }
/** * Wrapper for Form::getForm() * Get form from collection * * @param string $identifier Form identifier * * @return Symfony\Component\Form\FormBuilder */ public function getForm($identifier) { return Form::getForm($identifier); }