public function findFollowingForUser(User $user)
 {
     $userFollowingIds = $user->getFollowingIds();
     if (empty($userFollowingIds)) {
         return [];
     }
     $activeGroups = $this->getEntityManager()->getRepository('CivixCoreBundle:UserGroup')->getActiveGroupIds($user);
     $qb = $this->createQueryBuilder('sa');
     $qb->addSelect('f')->addSelect('g')->leftJoin('sa.following', 'f')->leftJoin('sa.group', 'g')->where($qb->expr()->andX('sa.recipient is NULL', $qb->expr()->in('sa.following', ':followings'), empty($activeGroups) ? 'sa.group is NULL' : 'sa.group is NULL OR sa.group IN (:groups)'))->setParameter('followings', $userFollowingIds)->setParameter('groups', $activeGroups)->orderBy('sa.id', 'DESC')->setMaxResults(200);
     return $qb->getQuery()->getResult();
 }
 public function load(ObjectManager $manager)
 {
     $users = array(array('username' => 'facebook1'), array('username' => 'facebook2'));
     foreach ($users as $key => $data) {
         $user = new User();
         $user->setUsername($data['username'])->setEmail($data['username'] . '@example.com')->setPassword('fakepassword')->setFacebookId('1000000000' . $key);
         $this->addReference('user-' . $data['username'], $user);
         $manager->persist($user);
     }
     $manager->flush();
 }
Exemplo n.º 3
0
 public function getNewGroupsByUser(User $user)
 {
     $groupOfUserIds = $user->getGroupsIds();
     $qb = $this->getEntityManager()->createQueryBuilder();
     $limitDate = new \DateTime('NOW');
     $limitDate->sub(new \DateInterval('P7D'));
     $qb->select('g')->from('CivixCoreBundle:Group', 'g')->leftJoin('g.users', 'u')->where('g.groupType = :type')->andWhere('g.createdAt > :limit_date')->setParameters(array('type' => Group::GROUP_TYPE_COMMON, 'limit_date' => $limitDate))->orderBy('g.createdAt', 'DESC');
     if (!empty($groupOfUserIds)) {
         $qb->andWhere('g.id NOT IN (:ids)')->setParameter('ids', $groupOfUserIds);
     }
     return $qb->getQuery()->getResult();
 }
Exemplo n.º 4
0
 public function load(ObjectManager $manager)
 {
     $factory = $this->container->get('security.encoder_factory');
     $users = array(array('username' => 'mobile1'), array('username' => 'mobile2'));
     foreach ($users as $data) {
         $user = new User();
         $user->setUsername($data['username']);
         $user->setEmail($data['username'] . '@example.com');
         $encoder = $factory->getEncoder($user);
         $password = $encoder->encodePassword($data['username'], $user->getSalt());
         $user->setPassword($password);
         $manager->persist($user);
     }
     $manager->flush();
 }
Exemplo n.º 5
0
 public function saveSquareAvatarFromPath(User $entity, $srcPath, $size = self::AVATAR_HEIGHT)
 {
     $fileInfo = explode('.', basename($srcPath));
     $fileExt = array_pop($fileInfo);
     $filename = uniqid() . '.' . $fileExt;
     $tempFile = tempnam(sys_get_temp_dir(), 'avatar') . '.' . $fileExt;
     //square avatars
     try {
         $this->serviceCropImage->rebuildImage($tempFile, $srcPath, $size);
     } catch (\Exception $exc) {
         $this->logger->addError('Image ' . $srcPath . '. ' . $exc->getMessage());
     }
     $entity->setAvatarFileName($tempFile);
     $fileUpload = new UploadedFile($tempFile, $filename);
     $entity->setAvatar($fileUpload);
 }
 /**
  * @Route("/{id}/approve",requirements={"id"="\d+"}, name="civix_front_group_members_approve")
  * @Method({"POST"})
  */
 public function approveUser(User $user)
 {
     $entityManager = $this->getDoctrine()->getManager();
     $csrfProvider = $this->get('form.csrf_provider');
     if ($csrfProvider->isCsrfTokenValid('approve_members_' . $user->getId(), $this->getRequest()->get('_token'))) {
         $userGroup = $entityManager->getRepository('CivixCoreBundle:UserGroup')->isJoinedUser($this->getUser(), $user);
         if ($userGroup) {
             $userGroup->setStatus(UserGroup::STATUS_ACTIVE);
             $entityManager->persist($userGroup);
             $entityManager->flush();
             $this->get('civix_core.social_activity_manager')->noticeGroupJoiningApproved($userGroup);
             $this->get('session')->getFlashBag()->add('notice', 'User has been successfully approved');
             return $this->redirect($this->generateUrl('civix_front_group_manage_approvals'));
         }
     }
     $this->get('session')->getFlashBag()->add('error', 'Something went wrong');
 }
Exemplo n.º 7
0
 /**
  * @group forgot
  */
 public function testCheckResetInterval()
 {
     $userManager = $this->getMockBuilder('Civix\\CoreBundle\\Service\\User\\UserManager')->disableOriginalConstructor()->setMethods(array('updateDistrictsIds'))->getMock();
     $user = new User();
     $user->setResetPasswordAt(null);
     $this->assertTrue($userManager->checkResetInterval($user), 'True if reset password date is empty');
     $user->setResetPasswordAt(new \DateTime());
     $this->assertFalse($userManager->checkResetInterval($user), 'False if reset password date is current date');
     $yesterday = new \DateTime();
     $yesterday->sub(new \DateInterval('PT24H'));
     $user->setResetPasswordAt($yesterday);
     $this->assertTrue($userManager->checkResetInterval($user), 'True if reset password date is yesterday');
     $checkDate = new \DateTime();
     $checkDate->sub(new \DateInterval('PT23H'));
     $user->setResetPasswordAt($checkDate);
     $this->assertFalse($userManager->checkResetInterval($user), 'False if reset password date is 23 hours ago');
 }
 public function findByUser(User $user, \DateTime $start)
 {
     $districtsIds = $user->getDistrictsIds();
     $groupsIds = $user->getGroupsIds();
     $representativeIds = array();
     if (!empty($districtsIds)) {
         $qb = $this->getEntityManager()->createQueryBuilder();
         $representativeIds = $qb->select('r.id')->from('CivixCoreBundle:Representative', 'r')->where($qb->expr()->in('r.district', $districtsIds))->getQuery()->getArrayResult();
         $representativeIds = array_reduce($representativeIds, function ($ids, $item) {
             $ids[] = $item['id'];
             return $ids;
         }, array());
     }
     $representativeIds = empty($representativeIds) ? array(0) : $representativeIds;
     $groupsIds = empty($groupsIds) ? array(0) : $groupsIds;
     $qb = $this->getEntityManager()->createQueryBuilder();
     return $qb->select('a, r, gr, rs')->from('CivixCoreBundle:Announcement', 'a')->leftJoin('a.group', 'gr')->leftJoin('a.representative', 'r')->leftJoin('r.representativeStorage', 'rs')->where($qb->expr()->orX($qb->expr()->in('a.representative', $representativeIds), $qb->expr()->in('a.group', $groupsIds)))->andWhere('a.publishedAt > :start')->setParameter('start', $start->format('Y-m-d H:i:s'))->orderBy('a.publishedAt', 'DESC')->getQuery()->getResult();
 }
 /**
  * @Route("/{id}/approve",requirements={"id"="\d+"}, name="civix_front_group_members_approve")
  * @Method({"POST"})
  */
 public function approveUser(User $user)
 {
     $entityManager = $this->getDoctrine()->getManager();
     $csrfProvider = $this->get('form.csrf_provider');
     if ($csrfProvider->isCsrfTokenValid('approve_members_' . $user->getId(), $this->getRequest()->get('_token'))) {
         $userGroup = $entityManager->getRepository('CivixCoreBundle:UserGroup')->isJoinedUser($this->getUser(), $user);
         if ($userGroup) {
             $slugify = new Slugify();
             $groupName = $slugify->slugify($userGroup->getGroup()->getOfficialName(), '');
             $mailgun = $this->get('civix_core.mailgun')->listaddmemberAction($groupName, $userGroup->getUser()->getEmail(), $userGroup->getUser()->getFirstName() . ' ' . $userGroup->getUser()->getLastName());
             if ($mailgun['http_response_code'] != 200) {
                 $this->get('session')->getFlashBag()->add('error', 'cannot add user to mailgun list');
                 return $this->redirect($this->generateUrl('civix_front_group_manage_approvals'));
             }
             $userGroup->setStatus(UserGroup::STATUS_ACTIVE);
             $entityManager->persist($userGroup);
             $entityManager->flush();
             $this->get('civix_core.social_activity_manager')->noticeGroupJoiningApproved($userGroup);
             $this->get('session')->getFlashBag()->add('notice', 'User has been successfully approved');
             return $this->redirect($this->generateUrl('civix_front_group_manage_approvals'));
         }
     }
     $this->get('session')->getFlashBag()->add('error', 'Something went wrong');
 }
Exemplo n.º 10
0
 /**
  * Get Join status
  *
  * @return Integer
  */
 public function getJoined(User $user)
 {
     return $user->getGroups()->contains($this) ? 1 : 0;
 }
Exemplo n.º 11
0
 public static function toUserOwnerData(User $user)
 {
     return ['id' => $user->getId(), 'type' => $user->getType(), 'official_title' => '', 'first_name' => $user->getFirstName(), 'last_name' => $user->getLastName(), 'avatar_file_path' => $user->getAvatarFileName()];
 }
Exemplo n.º 12
0
 public function checkResetInterval(User $user)
 {
     $lastResetDate = $user->getResetPasswordAt();
     if (is_null($lastResetDate)) {
         return true;
     }
     $currentDate = new \DateTime();
     $resetIntervalHours = ($currentDate->getTimestamp() - $lastResetDate->getTimestamp()) / 3600;
     if ($resetIntervalHours >= 24) {
         return true;
     }
     return false;
 }
Exemplo n.º 13
0
 public function sendRegistrationEmail(User $user)
 {
     $message = $this->createMessage('Welcome to Powerline', $user->getEmail(), 'CivixCoreBundle:Email:registration.html.twig', compact('user'), '*****@*****.**');
     $this->mailer->send($message);
 }
 public function findByQuery($query, User $user)
 {
     $userDistrictIds = $user->getDistrictsIds();
     $qb = $this->getEntityManager()->createQueryBuilder();
     $representativesFromStorage = $qb->select('rs, r')->from('CivixCoreBundle:RepresentativeStorage', 'rs')->leftJoin('rs.representative', 'r')->leftJoin('rs.district', 'd')->where($qb->expr()->in('rs.district', $userDistrictIds ? $userDistrictIds : array(0)))->andWhere($qb->expr()->orX($qb->expr()->like('rs.officialTitle', $qb->expr()->literal('%' . $query . '%')), $qb->expr()->like('rs.firstName', $qb->expr()->literal('%' . $query . '%')), $qb->expr()->like('rs.lastName', $qb->expr()->literal('%' . $query . '%'))))->orderBy('d.districtType')->getQuery()->getResult();
     $qb = $this->getEntityManager()->createQueryBuilder();
     $representatives = $qb->select('r')->from('CivixCoreBundle:Representative', 'r')->leftJoin('r.district', 'd')->where($qb->expr()->in('r.district', $userDistrictIds ? $userDistrictIds : array(0)))->andWhere('r.isNonLegislative = 1')->andWhere($qb->expr()->orX($qb->expr()->like('r.officialTitle', $qb->expr()->literal('%' . $query . '%')), $qb->expr()->like('r.firstName', $qb->expr()->literal('%' . $query . '%')), $qb->expr()->like('r.lastName', $qb->expr()->literal('%' . $query . '%'))))->orderBy('d.districtType')->getQuery()->getResult();
     return array_merge($representativesFromStorage, $representatives);
 }
 public function findActivitiesByFollowing(User $following)
 {
     return $this->createQueryBuilder('act')->leftJoin('act.activityConditions', 'act_c')->where('act_c.userId = :following')->setParameter('following', $following->getId())->orderBy('act.sentAt', 'DESC')->setMaxResults(100)->getQuery()->getResult();
 }
 public function getAddressQuery()
 {
     $this->__load();
     return parent::getAddressQuery();
 }
Exemplo n.º 17
0
 private function createUserActivityConditions(Activity $activity, User $user)
 {
     $condition = new ActivityCondition($activity);
     $condition->setUserId($user->getId());
     $this->entityManager->persist($condition);
     $this->entityManager->flush($condition);
 }
 public function create(Request $request)
 {
     $user = new User();
     $user->setUsername($request->get('username'))->setFirstName($request->get('first_name'))->setLastName($request->get('last_name'))->setEmail($request->get('email'))->setBirth($request->get('birth') ? new \DateTime($request->get('birth')) : null)->setAddress1($request->get('address1'))->setAddress2($request->get('address2'))->setCity($request->get('city'))->setState($request->get('state'))->setZip($request->get('zip'))->setCountry($request->get('country'))->setPhone($request->get('phone'))->setPassword($request->get('password'));
     return $user;
 }
Exemplo n.º 19
0
 private function addUnfollowingFilter(QueryBuilder $qb, User $user)
 {
     $excludedIds = array_merge(array($user->getId()), $user->getFollowingIds());
     $qb->andWhere('u.id NOT IN (:excluded_ids)')->setParameter('excluded_ids', $excludedIds);
     return $qb;
 }
Exemplo n.º 20
0
 /**
  * Check if $group private (need passcode) and not invited user
  * 
  * @param \Civix\CoreBundle\Entity\Group $group
  * 
  * @return boolean
  */
 public function isNeedCheckPasscode(Group $group, User $user)
 {
     return $group->getMembershipControl() === Group::GROUP_MEMBERSHIP_PASSCODE && !$user->getInvites()->contains($group);
 }