本文整理汇总了PHP中Pimple\Container::namedForm方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::namedForm方法的具体用法?PHP Container::namedForm怎么用?PHP Container::namedForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimple\Container
的用法示例。
在下文中一共展示了Container::namedForm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
//.........这里部分代码省略.........
}
if ($token->getConsumed()) {
throw new TokenException("Token already used", TokenException::ALREADY_USED);
}
switch ($token->getType()) {
case 'email_verification':
$token->getUser()->setEmailVerified(true);
$token->setConsumed(true);
$token->setConsumedAt(new \DateTime());
$app['orm.em']->flush();
return true;
case 'require_email_verification':
$token->getUser()->setEmailVerified(true);
$token->getUser()->setEnabled(true);
$token->setConsumed(true);
$token->setConsumedAt(new \DateTime());
$app['orm.em']->flush();
return true;
case 'recover_password':
if ($data) {
// submit
$token->setConsumed(true);
$token->setConsumedAt(new \DateTime());
}
$token->getUser()->setEmailVerified(true);
$app['orm.em']->flush();
return true;
}
});
// build the user_register form
$app[$dns . 'register_form_builder'] = $app->protect(function ($request) use($app, $dns) {
$data = $request->getSession()->get($dns . 'register_form', []);
$name = $request->get('_firewall');
$builder = $app->namedForm('user_register', $data);
if (!$app[$dns . 'firewalls'][$name]['use_email_as_username']) {
$builder->add('username', TextType::class, ['label' => $dns . 'register.labels.username']);
}
/** @var \Symfony\Component\Form\FormBuilder $builder */
$builder->add('email', EmailType::class, ['label' => $dns . 'register.labels.email'])->add('password', PasswordType::class, ['always_empty' => !$app[$dns . 'firewalls'][$name]['render_password_value'], 'label' => $dns . 'register.labels.password', 'attr' => ['autocomplete' => 'off']])->add('confirm_password', PasswordType::class, ['always_empty' => !$app[$dns . 'firewalls'][$name]['render_password_value'], 'label' => $dns . 'register.labels.confirm_password', 'attr' => ['autocomplete' => 'off']])->add('submit', SubmitType::class, ['label' => $dns . 'register.labels.submit']);
if ($request->get('_login_route')) {
$builder->add('cancel', SubmitType::class, ['label' => $dns . 'register.labels.cancel']);
}
return $builder;
});
// build the validators constraints for the registration user data
$app[$dns . 'register_constraints_builder'] = $app->protect(function ($request, $data) use($app, $dns) {
$name = $request->get('_firewall');
$constraints = [];
$constraints['email'] = new Constraints\Email();
if (!$app[$dns . 'firewalls'][$name]['use_email_as_username']) {
$constraints['username'] = [new Constraints\Length(['min' => 8, 'minMessage' => $dns . 'register.validators.username.length.min', 'max' => 16, 'maxMessage' => $dns . 'register.validators.username.length.max']), new Constraints\Regex(['pattern' => '/^[a-z][a-z0-9]*$/i', 'message' => $dns . 'register.validators.username.regex.username'])];
}
$constraints['password'] = new Constraints\Length(['min' => 8, 'minMessage' => $dns . 'register.validators.password.length.min', 'max' => 16, 'maxMessage' => $dns . 'register.validators.password.length.max']);
$constraints['confirm_password'] = new Constraints\EqualTo(['value' => $data['password'], 'message' => $dns . 'register.validators.confirm_password.equal_to.password']);
return $constraints;
});
$app[$dns . 'password_recoverer'] = $app->protect(function ($request, $email) use($app, $dns) {
$app[$dns . 'init_options']();
$name = $request->get('_firewall');
/** @var \Quazardous\Silex\UserPack\Entity\UserInterface $dbUser */
$dbUser = $app['orm.em']->getRepository($app[$dns . 'user_entity_class'])->findOneBy([$app[$dns . 'user_entity_email_field'] => $email]);
if ($dbUser) {
$dbToken = $app[$dns . 'secure_token_factory']($dbUser, 'recover_password');
$app['orm.em']->flush();
$data = ['user' => $dbUser, 'token' => $dbToken->getToken(), 'login_route' => $request->get('_login_route'), 'register_route' => $request->get('_register_route'), 'recover_password_confirm_route' => $request->get('_recover_password_confirm_route'), 'from' => $app[$dns . 'firewalls'][$name]['mailer_from']];
$app[$dns . 'mailer']('recover_password', $data);