本文整理汇总了PHP中AppBundle\Entity\User::setIsAdmin方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setIsAdmin方法的具体用法?PHP User::setIsAdmin怎么用?PHP User::setIsAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\User
的用法示例。
在下文中一共展示了User::setIsAdmin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerAction
/**
* @Route("/register", name="registration")
*/
public function registerAction(Request $request)
{
// 1) build the form
$user = new User();
$user->setIsActive(false);
$user->setIsAdmin(false);
$form = $this->createForm(new UserType(), $user);
// 2) handle the submit (will only happen on POST)
$form->handleRequest($request);
if (!$form->isValid()) {
echo $form->getErrorsAsString();
}
if ($form->isValid() && $form->isSubmitted()) {
$user->setPassword($user->getPlainPassword());
$user->setIsActive(false);
// 4) save the User!
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
// ... do any other work - like send them an email, etc
// maybe set a "flash" success message for the user
return new Response("<html>USUARIO REGISTRADO CORRECTAMENTE</html>");
}
return $this->render('registration/register.html.twig', array('form' => $form->createView()));
}
示例2: registerAction
/**
* @Route("/register", name="user_registration")
*/
public function registerAction(Request $request)
{
// 1) build the form
$user = new User();
$user->setIsActive(true);
$user->setIsAdmin(false);
$form = $this->createForm(UserType::class, $user);
// 2) handle the submit (will only happen on POST)
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// 3) Encode the password (you could also do this via Doctrine listener)
$password = $this->get('security.password_encoder')->encodePassword($user, $user->getPlainPassword());
$user->setPassword($password);
// 4) save the User!
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
// ... do any other work - like send them an email, etc
// maybe set a "flash" success message for the user
return $this->redirectToRoute('homepage');
}
return $this->render('security/register.html.twig', array('form' => $form->createView()));
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
$users = $em->getRepository('AppBundle:User')->findAll();
if ($users) {
foreach ($users as $user) {
if ($user->getIsAdmin()) {
throw new \RuntimeException('Admin already exists!');
}
}
}
$name = $input->getArgument('name');
$email = $input->getArgument('email');
$plainPassword = $input->getArgument('password');
$userExists = $em->getRepository('AppBundle:User')->findOneBy(array('username' => $name));
$userWithEmailExists = $em->getRepository('AppBundle:User')->findOneBy(array('email' => $email));
if ($userExists) {
throw new \RuntimeException('User already exists: ' . $name);
}
if ($userWithEmailExists) {
throw new \RuntimeException('User with this email already exists: ' . $email);
}
$admin = new User();
$admin->setIsAdmin(true);
$admin->setUsername($name);
$admin->setEmail($email);
$admin->setPlainPassword($plainPassword);
$password = $this->getContainer()->get('security.password_encoder')->encodePassword($admin, $admin->getPlainPassword());
$admin->setPassword($password);
$em->persist($admin);
$em->flush();
$output->writeln('Admin created!');
}