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


PHP User::addRole方法代码示例

本文整理汇总了PHP中AppBundle\Entity\User::addRole方法的典型用法代码示例。如果您正苦于以下问题:PHP User::addRole方法的具体用法?PHP User::addRole怎么用?PHP User::addRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AppBundle\Entity\User的用法示例。


在下文中一共展示了User::addRole方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: authenticateUser

 /**
  * @param User $user
  * @param $role
  */
 protected function authenticateUser(User $user, $role)
 {
     if ($role) {
         if (is_array($role)) {
             foreach ($role as $loopedRole) {
                 $user->addRole($loopedRole);
             }
         } else {
             $user->addRole($role);
         }
     }
     $token = new UsernamePasswordToken($user, 'dummy', $providerKey = 'main');
     $this->authenticateToken($token);
 }
开发者ID:erickr,项目名称:Kompisbyran,代码行数:18,代码来源:AuthenticationExtensionTrait.php

示例2: injectUser

 protected function injectUser()
 {
     $this->user = new User();
     //$admin = 'tester'; // MWAHAHAHA
     //$departmentId = 5; // UiB
     $role = $this->em->getRepository('AppBundle:Role')->findOneByRole('ROLE_USER');
     $this->user->addRole($role);
     $this->user->setGender(1);
     $this->user->setFirstName("Shi");
     $this->user->setLastName("LaLong");
     $emd = $this->em->getRepository('AppBundle:FieldOfStudy')->find(40);
     // Tuple "Andre" from UiB, id 40 for fos
     $this->user->setFieldOfStudy($emd);
     $this->user->setUserName("shiluib");
     // Weird typo?
     $this->user->setEmail("shiluib@student.uib.no");
     $this->user->setPhone("47661674");
     $this->user->setPicturePath("images/defaultProfile.png");
     $this->user->setPassword("pimwrneil");
     $createNewUserCode = bin2hex(openssl_random_pseudo_bytes(16));
     $hashedNewUserCode = hash('sha512', $createNewUserCode, false);
     $this->user->setNewUserCode($hashedNewUserCode);
     // Persist the user
     $this->user->setIsActive(1);
     $this->em->persist($this->user);
     $this->em->flush();
     return $this;
 }
开发者ID:vegardbb,项目名称:webpage,代码行数:28,代码来源:UserRepositoryFunctionalTest.php

示例3: userIsModeratorAction

 /**
  * @Route("/user_is_moderator/{id}", name="admin_user_is_moderator")
  * @ParamConverter("user", options={"mapping": {"id": "id"}})
  */
 public function userIsModeratorAction(Request $request, User $user)
 {
     $user->addRole('ROLE_MODERATOR');
     $em = $this->getDoctrine()->getEntityManager();
     $em->flush();
     return $this->redirectToRoute('admin_users_show');
 }
开发者ID:KateSyrotchuk,项目名称:blog,代码行数:11,代码来源:UserController.php

示例4: loadUsers

 /**
  * @param ObjectManager $manager
  */
 protected function loadUsers(ObjectManager $manager)
 {
     $user = new User();
     $user->setEmail('learner@example.com');
     $user->setFirstName('Kalle');
     $user->setLastName('Anka');
     $user->setEnabled(true);
     $user->addRole('ROLE_COMPLETE_USER');
     $user->setWantToLearn(true);
     $user->setAge(35);
     $user->setAbout('Sportintresserad man med 3 barn');
     $user->setCategories([$this->getReference('category-1'), $this->getReference('category-2')]);
     $user->setFrom('SY');
     $user->setGender('M');
     $user->setProfilePicture('http://api.randomuser.me/portraits/thumb/men/1.jpg');
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword('asdf123', $user->getSalt()));
     $manager->persist($user);
     $this->addReference('user-learner', $user);
     $user = new User();
     $user->setEmail('fluentspeaker@example.com');
     $user->setFirstName('Kal p');
     $user->setLastName('Dal');
     $user->setEnabled(true);
     $user->setRoles(['ROLE_COMPLETE_USER', 'ROLE_ADMIN']);
     $user->setWantToLearn(false);
     $user->setAge(40);
     $user->setAbout('Sportintresserad lärare');
     $user->setCategories([$this->getReference('category-0'), $this->getReference('category-1')]);
     $user->setFrom('SE');
     $user->setGender('M');
     $user->setProfilePicture('http://api.randomuser.me/portraits/thumb/men/2.jpg');
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword('asdf123', $user->getSalt()));
     $manager->persist($user);
     $this->addReference('user-fluentspeaker', $user);
     $user = new User();
     $user->setEmail('glenn@example.com');
     $user->setFirstName('Glenn');
     $user->setLastName('GBG');
     $user->setEnabled(true);
     $user->setRoles(['ROLE_COMPLETE_USER', 'ROLE_ADMIN']);
     $user->setWantToLearn(false);
     $user->setAge(20);
     $user->setAbout('Göteborgare');
     $user->setCategories([$this->getReference('category-1'), $this->getReference('category-2')]);
     $user->setFrom('SE');
     $user->setGender('M');
     $user->setProfilePicture('http://api.randomuser.me/portraits/thumb/men/3.jpg');
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword('asdf123', $user->getSalt()));
     $manager->persist($user);
     $this->addReference('user-glenn', $user);
     $user = new User();
     $user->setEmail('incomplete@example.com');
     $user->setEnabled(true);
     $user->setPassword($encoder->encodePassword('asdf123', $user->getSalt()));
     $manager->persist($user);
 }
开发者ID:EmmaHammar,项目名称:Kompisbyran,代码行数:62,代码来源:LoadData.php

示例5: authenticateUser

 /**
  * @param User $user
  * @param $role
  */
 protected function authenticateUser(User $user, $role)
 {
     if ($role) {
         $user->addRole($role);
     }
     $token = new UsernamePasswordToken($user, 'dummy', $providerKey = 'main');
     $this->authenticateToken($token);
 }
开发者ID:raziraz,项目名称:Kompisbyran,代码行数:12,代码来源:AuthenticationExtensionTrait.php

示例6: loadUser2

 private function loadUser2(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername('user2');
     $user->setEmail('user2@gmail.com');
     $user->setPlainPassword('user2_pass');
     $user->addRole(User::ROLE_SUPER_ADMIN);
     $manager->persist($user);
     $manager->flush($user);
     $this->addReference('user_user2', $user);
 }
开发者ID:Algatux,项目名称:symfony3.0,代码行数:11,代码来源:LoadUserData.php

示例7: createUser

 /**
  * @Given /^que existen los siguientes usuarios:$/
  */
 public function createUser(TableNode $tableNode)
 {
     foreach ($tableNode->getHash() as $userHash) {
         $user = new User();
         $user->setUsername($userHash['username']);
         $user->setEmail($userHash['email']);
         $user->setPlainPassword($userHash['plainPassword']);
         $user->addRole($userHash['role']);
         $this->getEntityManager()->persist($user);
         $this->getEntityManager()->flush();
     }
 }
开发者ID:aulasoftwarelibre,项目名称:ritsiga,代码行数:15,代码来源:UserContext.php

示例8: load

 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $userAdmin = new User();
     $userAdmin->setUsername('admin');
     $userAdmin->setEmail('admin@admin.lan');
     $userAdmin->setEnabled(true);
     $userAdmin->addRole('ROLE_ADMIN');
     $hash = $this->container->get('security.password_encoder')->encodePassword($userAdmin, 'admin');
     $userAdmin->setPassword($hash);
     $manager->persist($userAdmin);
     $manager->flush();
 }
开发者ID:redssie,项目名称:EP_Trgovina,代码行数:15,代码来源:LoadUserData.php

示例9: load

 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setEmail('john@example.com');
     $user->setUsername('john.doe');
     $user->setEnabled(true);
     $user->addRole('ROLE_ADMIN');
     // шифрует и устанавливает пароль для пользователя,
     // настройки берет из security.yml
     $encoder = $this->container->get('security.password_encoder');
     $password = $encoder->encodePassword($user, 'pass');
     $user->setPassword($password);
     $manager->persist($user);
     $manager->flush();
 }
开发者ID:KnightSlayer,项目名称:epicStartsHere,代码行数:15,代码来源:FixtureLoader.php

示例10: load

 public function load(ObjectManager $manager)
 {
     foreach ($this->getAllUser() as $singleUser) {
         $user = new User();
         $user->setUsername($singleUser['username']);
         $user->setPlainPassword($singleUser['PlainPassword']);
         $user->setEmail($singleUser['Email']);
         $user->setEnabled(true);
         $user->addRole($singleUser['roles']);
         $user->setName($singleUser['name']);
         $user->setIsStaff($singleUser['isStaff']);
         $user->setSiteId($this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('AppBundle:Site')->findBy(array('url' => $singleUser['siteId'])));
         $manager->persist($user);
     }
     $manager->flush();
 }
开发者ID:johnmackenzie91,项目名称:ClientDocumentArea,代码行数:16,代码来源:LoadUserData.php

示例11: generateUsers

 /**
  * @Given /^existen los siguientes usuarios:$/
  */
 public function generateUsers(TableNode $usersTable)
 {
     $em = $this->getEntityManager();
     foreach ($usersTable->getHash() as $userHash) {
         $user = $this->getEntityManager()->getRepository('AppBundle:User')->findOneByUsername($userHash['nombre']);
         if (!$user) {
             $user = new User();
         }
         $user->setUsername($userHash['nombre']);
         $user->setPlainPassword($userHash['clave']);
         $user->setEmail($userHash['email']);
         $user->setEnabled($userHash['activado']);
         $user->addRole($userHash['rol']);
         $em->persist($user);
     }
     $em->flush();
 }
开发者ID:jmibla,项目名称:sgcl,代码行数:20,代码来源:UserContext.php

示例12: create

 /**
  * @Route("/admin/teacher/create")
  */
 public function create(Request $request)
 {
     $user = new User();
     $user->setActive(true);
     $roles = $this->getDoctrine()->getRepository('AppBundle:Role')->findOneById(2);
     $user->addRole($roles);
     $form = $this->createFormBuilder($user)->add('lastName', 'text', array('label' => 'Last Name:'))->add('firstName', 'text', array('label' => 'First Name:'))->add('englishName', 'text', array('label' => 'English Name:'))->add('username', 'text', array('label' => 'Login:'))->add('password', 'repeated', array('type' => 'password', 'invalid_message' => 'Password fields do not match', 'first_options' => array('label' => 'Password', 'required' => false), 'second_options' => array('label' => 'Repeat Password', 'required' => false)))->add('email', 'text', array('label' => 'Email:', 'required' => false))->add('mobilePhone', 'text', array('label' => 'Mobile Phone:', 'required' => false))->add('homePhone', 'text', array('label' => 'Home Phone:', 'required' => false))->add('roles', 'entity', array('multiple' => true, 'expanded' => true, 'class' => 'AppBundle:Role', 'choice_label' => 'name', 'label' => 'Roles: '))->add('save', 'submit', array('label' => 'Create'))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $user = $form->getData();
         $em = $this->getDoctrine()->getManager();
         if ($user->getPassword() != '') {
             $user->setPassword(md5($user->getPassword()));
         }
         $em->persist($user);
         $em->flush();
         return $this->redirectToRoute($this->displayRoute);
     }
     return $this->render('forms/teacher.html.twig', array('form' => $form->createView()));
 }
开发者ID:pmolchanov2002,项目名称:gradebook,代码行数:23,代码来源:TeacherController.php

示例13: loadUsers

 private function loadUsers(ObjectManager $manager)
 {
     $admin = $manager->getRepository('AppBundle:Role')->findOneBy(array('role' => 'ROLE_ADMIN'));
     $student = $manager->getRepository('AppBundle:Role')->findOneBy(array('role' => 'ROLE_STUDENT'));
     //        var_dump($admin);
     $passwordEncoder = $this->container->get('security.password_encoder');
     $johnUser = new User();
     $johnUser->setUsername('john_user');
     $johnUser->setEmail('john_user@symfony.com');
     $encodedPassword = $passwordEncoder->encodePassword($johnUser, 'kitten');
     $johnUser->setPassword($encodedPassword);
     $johnUser->addRole($student);
     $manager->persist($johnUser);
     $annaAdmin = new User();
     $annaAdmin->setUsername('anna_admin');
     $annaAdmin->setEmail('anna_admin@symfony.com');
     $annaAdmin->addRole($admin);
     $encodedPassword = $passwordEncoder->encodePassword($annaAdmin, 'kitten');
     $annaAdmin->setPassword($encodedPassword);
     $manager->persist($annaAdmin);
     $manager->flush();
 }
开发者ID:BookWorld1,项目名称:courses,代码行数:22,代码来源:LoadFixtures.php

示例14: signUpAction

 /**
  * @Route("/signup", name="signup")
  */
 public function signUpAction(Request $request)
 {
     $user = new User();
     $em = $this->getDoctrine()->getManager();
     $roleRepository = $em->getRepository('AppBundle\\Entity\\Role')->findOneBy(array('role' => 'ROLE_USER'));
     $user->addRole($roleRepository);
     $form = $this->createForm(UserType::class, $user);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $emailRepository = $em->getRepository('AppBundle\\Entity\\User')->findOneBy(array('email' => $user->getEmail()));
         if ($emailRepository) {
             throw new \LogicException('Email already used!');
         }
         // Encoding the password
         $plainPassword = $user->getPassword();
         $encoder = $this->container->get('security.password_encoder');
         $encoded = $encoder->encodePassword($user, $plainPassword);
         $user->setPassword($encoded);
         $em->persist($user);
         $em->flush();
         return $this->redirectToRoute('homepage');
     }
     return $this->render('default/new.html.twig', array('form' => $form->createView()));
 }
开发者ID:RGLong,项目名称:kosmes,代码行数:27,代码来源:SecurityController.php

示例15: addRole

 /**
  * {@inheritDoc}
  */
 public function addRole($role)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'addRole', [$role]);
     return parent::addRole($role);
 }
开发者ID:reathh,项目名称:MotikarqSystem,代码行数:8,代码来源:__CG__AppBundleEntityUser.php


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