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


PHP Entity\User类代码示例

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


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

示例1: load

 public function load(ObjectManager $manager)
 {
     $encoder = $this->container->get('security.password_encoder');
     $userAdmin = new User();
     $userAdmin->setEmail('paul.mesnilgrente@gmail.com');
     $userAdmin->setEnabled(1);
     $userAdmin->setUsername('Paul Mesnilgrente');
     $password = $encoder->encodePassword($userAdmin, 'lB7Xq9WdOxCz7Xzod1FH');
     $userAdmin->setPassword($password);
     $userAdmin->setRoles(array('ROLE_SUPER_ADMIN'));
     $manager->persist($userAdmin);
     $manager->flush();
     $user1 = new User();
     $user1->setEmail('karol-anne.pelosato@hotmail.fr');
     $user1->setEnabled(1);
     $user1->setUsername('Karol-anne Pelosato');
     $password = $encoder->encodePassword($user1, '2pMJVtuDtwkctwtf3fLQ');
     $user1->setPassword($password);
     $user1->setRoles(array('ROLE_USER'));
     $manager->persist($user1);
     $manager->flush();
     $user2 = new User();
     $user2->setEmail('mesnil.paul@gmail.com');
     $user2->setEnabled(1);
     $user2->setUsername('Fabien Mesnilgrente');
     $password = $encoder->encodePassword($user2, 'lv4Uem4OtFmfSYYDGX');
     $user2->setPassword($password);
     $user2->setRoles(array('ROLE_USER'));
     $manager->persist($user2);
     $manager->flush();
     $this->addReference('user-admin', $userAdmin);
     $this->addReference('user-karo', $user1);
     $this->addReference('user-fabien', $user2);
 }
开发者ID:paul-mesnilgrente,项目名称:paul-mesnilgrente,代码行数:34,代码来源:LoadUserData.php

示例2: load

 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername(self::TEST_USER_USERNAME)->setPlainPassword(self::TEST_USER_PASSWORD)->setRoles(['ROLE_ADMIN']);
     $manager->persist($user);
     $manager->flush();
 }
开发者ID:mkhrystunov,项目名称:guest_book,代码行数:10,代码来源:LoadUser.php

示例3: createToken

 /**
  * @param User $user
  * @return Token
  */
 public function createToken(User $user) : Token
 {
     $issued = Carbon::now();
     $expire = Carbon::now()->addSeconds((int) $this->config['expire']);
     $notBefore = Carbon::now()->addSeconds((int) $this->config['notbefore']);
     return $this->tokenBuilder->setIssuer($this->config['issuer'])->setAudience($this->config['audience'])->setId($this->config['appid'], true)->setIssuedAt($issued->getTimestamp())->setNotBefore($notBefore->getTimestamp())->setExpiration($expire->getTimestamp())->set('data', ["uid" => $user->getId(), "uidentifier" => $user->getUsername()])->sign($this->signer, $this->secret)->getToken();
 }
开发者ID:Algatux,项目名称:symfony3.0,代码行数:11,代码来源:TokenGenerator.php

示例4: createAnonymouslyAction

 /**
  * @Route("/record/anonymous", name="createRecordAnonymously")
  * @Method("POST")
  */
 public function createAnonymouslyAction(Request $request)
 {
     // user anonymous
     $repository = $this->getDoctrine()->getRepository('AppBundle:User');
     $count = $repository->count();
     $username = 'Player' . dechex($count);
     $password = chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90));
     $user = new User();
     $user->setUsername($username);
     $user->setPassword(md5($password));
     $em = $this->getDoctrine()->getManager();
     $em->persist($user);
     $em->flush();
     // record
     $content = $request->getContent();
     $response = json_decode($content, true);
     if ($user != null) {
         $record = new Record();
         $record->setScore($response['score']);
         $record->setUserId($user->getId());
         $em = $this->getDoctrine()->getManager();
         $em->persist($record);
         $em->flush();
         return new JsonResponse(['code' => 1, 'record' => ['id' => $record->getId(), 'score' => $record->getScore(), 'userId' => $record->getUserId()], 'user' => ['username' => $user->getUsername(), 'password' => $password]]);
     } else {
         return new JsonResponse(['code' => 0, 'message' => 'record not save']);
     }
 }
开发者ID:8785496,项目名称:record,代码行数:32,代码来源:RecordController.php

示例5: startTestAction

 /**
  * @Route("/startTest", name="start_test")
  */
 public function startTestAction(Request $request)
 {
     $response = new Response();
     $response->headers->set('Content-Type', 'application/json');
     $data = json_decode($request->getContent(), true);
     $request->request->replace($data);
     //fetching user name
     if (!($userName = $request->request->get('user_name'))) {
         $response->setContent(json_encode(array('error' => 'Invalid name')));
         return $response;
     }
     //saving user
     $user = new User();
     $user->setName($userName);
     $user->setScore(0);
     $em = $this->getDoctrine()->getManager();
     $em->persist($user);
     $em->flush();
     //start sesssion
     $session = $request->getSession();
     $session->start();
     $session->set('user_id', $user->getId());
     $session->set('name', $user->getName());
     $session->set('score', $user->getScore());
     $session->set('errors_count', 0);
     $response->setContent(json_encode(array('success' => true)));
     return $response;
 }
开发者ID:virtyos,项目名称:dictionary,代码行数:31,代码来源:DefaultController.php

示例6: getRecentFrequent

 protected function getRecentFrequent(User $user, array $criteria = null, $limit = 10)
 {
     $sql = '
         SELECT text, MAX(createdAt) AS recency, COUNT(*) AS frequency
         FROM stress_log_factors
         JOIN stress_logs ON stress_log_id = stress_logs.id
         WHERE user_id = ?
     ';
     $params = array($user->getId());
     if (is_array($criteria)) {
         foreach ($criteria as $key => $val) {
             $op = '=';
             if (is_array($val)) {
                 reset($val);
                 $op = key($val);
                 $val = current($val);
             }
             $sql .= 'AND `' . $key . '` ' . $op . ' ? ';
             $params[] = $val;
         }
     }
     $sql .= 'GROUP BY text ';
     $sql .= 'ORDER BY recency DESC, frequency DESC ';
     $sql .= 'LIMIT ' . (int) $limit;
     $result = $this->conn->fetchAll($sql, $params);
     return array_column($result, 'text');
 }
开发者ID:jasongrimes,项目名称:stressmonkey,代码行数:27,代码来源:TagManager.php

示例7: geolocAction

 /**
  * @Route("/geoloc/{id}", requirements={"id" = "\d+"})
  * @Method("POST")
  */
 public function geolocAction($id)
 {
     $request = $this->getRequest();
     if ($request->isXmlHttpRequest()) {
         $em = $this->getDoctrine()->getManager();
         $wine = $em->getRepository('AppBundle:Wine')->find($id);
         if (null !== $wine) {
             $lat = $request->request->get('lat');
             $lng = $request->request->get('lng');
             if (null !== $lat && null !== $lng) {
                 $date = new \DateTime();
                 $user = new User();
                 $user->setLat($lat);
                 $user->setLng($lng);
                 $user->setDate($date);
                 $wine->addUser($user);
                 $em->persist($user);
                 $em->flush();
                 return new JsonResponse($this->normalizeJson($user), 200);
             }
         }
     } else {
         throw $this->createNotFoundException();
     }
     return new Response('', 200);
 }
开发者ID:potogan,项目名称:mobile-wine,代码行数:30,代码来源:DefaultController.php

示例8: loadUsers

 private function loadUsers(ObjectManager $manager)
 {
     $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);
     $manager->persist($johnUser);
     $annaAdmin = new User();
     $annaAdmin->setUsername('anna_admin');
     $annaAdmin->setEmail('anna_admin@symfony.com');
     $annaAdmin->setRoles(array('ROLE_ADMIN'));
     $encodedPassword = $passwordEncoder->encodePassword($annaAdmin, 'kitten');
     $annaAdmin->setPassword($encodedPassword);
     $manager->persist($annaAdmin);
     $avantripAdmin = new User();
     $avantripAdmin->setUsername('admin');
     $avantripAdmin->setEmail('info@avantrip.com');
     $avantripAdmin->setRoles(array('ROLE_ADMIN'));
     $encodedPassword = $passwordEncoder->encodePassword($avantripAdmin, 'adminavantrip');
     $avantripAdmin->setPassword($encodedPassword);
     $manager->persist($avantripAdmin);
     $manager->flush();
 }
开发者ID:jbarad,项目名称:symfony_demo,代码行数:25,代码来源:LoadFixtures.php

示例9: registrationAction

 /**
  * @Route("/registration/new", name="registrationNew")
  */
 public function registrationAction(Request $request)
 {
     $user = new User();
     $user->setUsername(mb_strtolower($request->get('_username')));
     if ($request->get('_password') != $request->get('_password-2')) {
         $error = 'Пароли не совпадают';
         return $this->render(':user:registration.html.twig', array('error' => $error));
     }
     $plainPassword = $request->get('_password');
     $encoder = $this->container->get('security.password_encoder');
     $encoded = $encoder->encodePassword($user, $plainPassword);
     $user->setPassword($encoded);
     $user->setFirstName($request->get('_firstName'));
     $user->setSecondName($request->get('_secondName'));
     $user->setEmail($request->get('_email'));
     $user->setPost($request->get('_select'));
     //        $user->setRoles('ROLE_USER');
     $em = $this->getDoctrine()->getManager();
     try {
         $em->persist($user);
         $em->flush();
     } catch (\Exception $e) {
         $error = 'Логин уже занят';
         return $this->render(':user:registration.html.twig', array('error' => $error));
     }
     //        if ($this->isGranted('ROLE_ADMIN')) {
     //            return $this->showUserAction($user->getId());
     //        }
     $token = new UsernamePasswordToken($user, $user->getPassword(), 'database_users', $user->getRoles());
     $this->get('security.token_storage')->setToken($token);
     return $this->redirectToRoute('userPage', array('id' => $user->getId()));
 }
开发者ID:AnastasiyaDev,项目名称:VisualizationModule,代码行数:35,代码来源:UserController.php

示例10: canSelfEdit

 /**
  * @param User $user
  * @return bool
  */
 private function canSelfEdit(User $user)
 {
     if ($user->getFacebookId() === null && $user->getGoogleId() === null && $user->getVkontakteId() === null) {
         return true;
     }
     return false;
 }
开发者ID:vsmihaylovsky,项目名称:GeekHubSymfonyShop,代码行数:11,代码来源:UserVoter.php

示例11: updatePassword

 private function updatePassword(User $entity)
 {
     if ($entity->getPlainPassword()) {
         $password = $this->encoder->encodePassword($entity, $entity->getPlainPassword());
         $entity->setPassword($password);
     }
 }
开发者ID:drymek,项目名称:fcs-backend,代码行数:7,代码来源:PasswordListener.php

示例12: authenticateUser

 private function authenticateUser(User $user)
 {
     $providerKey = 'frontend_area';
     // Firewall name
     $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
     $this->container->get('security.token_storage')->setToken($token);
 }
开发者ID:Wolframcheg,项目名称:symfonyblog,代码行数:7,代码来源:AuthController.php

示例13: getNotifications

 /**
  * @param User $user
  * @return array
  */
 public function getNotifications(User $user)
 {
     $qb = $this->createQueryBuilder('n');
     $qb->select('n.id, a.articleId, a.heading as article_heading, a.createdAt, u.username, img.path, v.heading as video_heading, v.videoId, l.linkId, l.heading as link_heading');
     $qb->leftJoin('n.article', 'a')->leftJoin('n.user', 'u')->leftJoin('u.profileImg', 'img')->leftJoin('n.video', 'v')->leftJoin('n.link', 'l')->where('a.userId = ' . $user->getId())->orWhere('v.userId = ' . $user->getId())->orWhere('l.userId = ' . $user->getId())->andWhere('n.seen = 0');
     return $qb->getQuery()->getResult();
 }
开发者ID:ugra92,项目名称:knowledgems,代码行数:11,代码来源:NotificationRepository.php

示例14: userNoModeratorAction

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

示例15: commit

 /**
  * @param User $user
  * @param PageAnimal $pageAnimal
  * @throws HistoryException
  * @throws ValidationException
  */
 public function commit(User $user, PageAnimal $pageAnimal)
 {
     /** @var PageAnimalBranch $pageAnimalBranch */
     $pageAnimalBranch = $this->pageAnimalBranchRepository->find($pageAnimal->getId());
     if ($pageAnimalBranch == null) {
         throw new HistoryException(HistoryException::BRANCHE_INCONNUE);
     }
     if ($user->getId() !== $pageAnimalBranch->getOwner()->getId()) {
         throw new HistoryException(HistoryException::DROIT_REFUSE);
     }
     /** @var PageAnimalCommit $clientHead */
     $clientHead = $this->pageAnimalCommitRepository->find($pageAnimal->getHead());
     if ($clientHead->getId() !== $pageAnimalBranch->getCommit()->getId()) {
         throw new HistoryException(HistoryException::NON_FAST_FORWARD);
     }
     if (empty($pageAnimal->getNom())) {
         throw new ValidationException(ValidationException::EMPTY_NOM);
     }
     if (empty($pageAnimal->getDateNaissance())) {
         throw new ValidationException(ValidationException::EMPTY_DATE_NAISSANCE);
     }
     $commit = new PageAnimalCommit($clientHead, $pageAnimal->getNom(), $pageAnimal->getDateNaissance(), $pageAnimal->getDescription(), $pageAnimal->getStatut(), $pageAnimal->getSexe(), $pageAnimal->getPhotos());
     $this->doctrine->persist($commit);
     $pageAnimalBranch->setCommit($commit);
     $this->doctrine->flush([$commit, $pageAnimalBranch]);
     $pageAnimal->setHead($commit->getId());
 }
开发者ID:apflieger,项目名称:zigotoo,代码行数:33,代码来源:PageAnimalService.php


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