当前位置: 首页>>代码示例>>PHP>>正文


PHP User::setIsAdmin方法代码示例

本文整理汇总了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()));
 }
开发者ID:gikusan,项目名称:ProyectoSymfony,代码行数:28,代码来源:RegistrationController.php

示例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()));
 }
开发者ID:PrDenisa,项目名称:eco,代码行数:26,代码来源:RegistrationController.php

示例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!');
 }
开发者ID:maximzh,项目名称:Blog,代码行数:33,代码来源:CreateAdminCommand.php


注:本文中的AppBundle\Entity\User::setIsAdmin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。