本文整理汇总了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);
}
示例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();
}
示例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();
}
示例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']);
}
}
示例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;
}
示例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');
}
示例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);
}
示例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();
}
示例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()));
}
示例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;
}
示例11: updatePassword
private function updatePassword(User $entity)
{
if ($entity->getPlainPassword()) {
$password = $this->encoder->encodePassword($entity, $entity->getPlainPassword());
$entity->setPassword($password);
}
}
示例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);
}
示例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();
}
示例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');
}
示例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());
}