Inheritance: implements Zend_Acl_Role_Interface, implements Symfony\Component\Security\Core\User\UserInterface, implements Symfony\Component\Security\Core\User\AdvancedUserInterface, implements Serializable, implements Symfony\Component\Security\Core\User\EquatableInterface, implements Newscoop\Search\DocumentInterface
示例#1
0
 public function indexAction()
 {
     $form = new Application_Form_Profile();
     $form->setMethod('POST');
     $form->setDefaultsFromEntity($this->user);
     $request = $this->getRequest();
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $values = $form->getValues();
         try {
             if (!empty($values['image'])) {
                 $imageInfo = array_pop($form->image->getFileInfo());
                 $values['image'] = $this->_helper->service('image')->save($imageInfo);
             }
             $this->service->save($values, $this->user);
             $this->_helper->redirector('index');
         } catch (\InvalidArgumentException $e) {
             switch ($e->getMessage()) {
                 case 'username_conflict':
                     $form->username->addError($this->view->translate("User with given username exists."));
                     break;
                 default:
                     $form->image->addError($e->getMessage());
                     break;
             }
         }
     }
     $this->view->user_first_name = $this->user->getFirstName();
     $this->view->user_last_name = $this->user->getLastName();
     $this->view->user_email = $this->user->getEmail();
     $this->view->form = $form;
     $this->view->user = new MetaUser($this->user);
     $this->view->first_time = $this->_getParam('first', false);
 }
示例#2
0
 /**
  * Find topics for user
  *
  * @param Newscoop\Entity\User
  * @return array
  */
 public function findByUser(User $user)
 {
     $em = $this->getEntityManager();
     $query = $em->createQuery('SELECT ut FROM Newscoop\\Entity\\UserTopic ut INNER JOIN ut.topic t WHERE ut.user = :user');
     $query->setParameter('user', $user->getId());
     return $query->getResult();
 }
 /**
  * Find results for user and topic
  *
  * @param Newscoop\Entity\User                 $user
  * @param Newscoop\NewscoopBundle\Entity\Topic $topic
  *
  * @return Newscoop\Entity\UserTopic
  */
 public function findByTopicAndUser(User $user, Topic $topic)
 {
     $em = $this->getEntityManager();
     $locale = $em->getRepository("Newscoop\\NewscoopBundle\\Entity\\Topic")->getTranslatableTopicLocale($topic);
     $qb = $em->createQueryBuilder()->select(array('ut'))->from('Newscoop\\Entity\\UserTopic', 'ut')->leftJoin('ut.user', 'u')->leftJoin('ut.topic', 't')->leftJoin('t.translations', 'tt')->where('u.id = :user_id')->andWhere('t.id = :topic_id')->andWhere('tt.locale = :topic_language_id')->setParameters(array('user_id' => $user->getId(), 'topic_id' => $topic->getId(), 'topic_language_id' => $locale));
     return $qb->getQuery()->getResult();
 }
示例#4
0
 public function testSendPasswordRestoreToken()
 {
     $this->markTestSkipped();
     // @todo refactor the view dependency
     $this->service->sendPasswordRestoreToken($this->user);
     $this->assertRegExp('#user/' . $this->user->getId() . '/token/[a-z0-9]{40}#i', $this->getEmailBody());
     $this->assertArrayHasKey('Subject', $this->getEmailHeaders());
 }
 public function it_shouldnt_edit_comment(EditorialComment $comment, User $user, User $newUser)
 {
     $comment->getUser()->willReturn($user);
     $comment->setComment(Argument::type('string'))->willReturn(true);
     $newUser->getId()->willReturn(5);
     $newUser->isAdmin()->willReturn(false);
     $this->shouldThrow('Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException')->during('edit', array('updated comment', $comment, $newUser));
 }
示例#6
0
 private function addUser($name, $status = 1, $isPublic = 1)
 {
     $user = new User($name);
     $user->setStatus($status);
     $user->setPublic($isPublic);
     $this->em->persist($user);
     $this->em->flush();
 }
 /**
  * Invalidate token
  *
  * @param Newscoop\Entity\User $user
  * @param string $action
  * @return void
  */
 public function invalidateTokens(User $user, $action = 'any')
 {
     $tokens = $this->em->getRepository('Newscoop\\Entity\\UserToken')->findBy(array('user' => $user->getId(), 'action' => $action));
     foreach ($tokens as $token) {
         $this->em->remove($token);
     }
     $this->em->flush();
 }
示例#8
0
 public function setDefaultsFromEntity(User $user)
 {
     $defaults = array('first_name' => $user->getFirstName(), 'last_name' => $user->getLastName(), 'username' => $user->getUsername(), 'attributes' => array());
     $profile = $this->getSubForm('attributes');
     foreach ($profile as $field) {
         $defaults['attributes'][$field->getName()] = (string) $user->getAttribute($field->getName());
     }
     $this->setDefaults($defaults);
 }
示例#9
0
 public function setUp()
 {
     parent::setUp('Newscoop\\Entity\\UserToken', 'Newscoop\\Entity\\Acl\\Role', 'Newscoop\\Entity\\User');
     $this->service = new UserTokenService($this->em);
     $this->user = new User('test');
     $this->user->setEmail('petr@localhost');
     $this->em->persist($this->user);
     $this->em->flush();
 }
 /**
  * Remove user attributes
  *
  * @param Newscoop\Entity\User $user
  * @param array $attributes
  *
  * @return void
  */
 public function removeAttributes(User $user, array $attributes)
 {
     foreach ($attributes as $attribute) {
         if ($entity = $user->removeAttribute($attribute)) {
             $this->em->remove($entity);
         }
     }
     $this->em->flush();
 }
 private function processUser(User $user)
 {
     $em = $this->get('em');
     $types = array();
     foreach ($user->getUserTypes() as $type) {
         $types[] = $type->getName();
     }
     $userPermission = $em->getRepository('Newscoop\\EditorBundle\\Entity\\Permissions')->findOneByUser($user);
     return array('id' => $user->getId(), 'email' => $user->getEmail(), 'username' => $user->getUsername(), 'first_name' => $user->getFirstName(), 'last_name' => $user->getLastName(), 'updated' => $userPermission ? $userPermission->getUpdatedAt()->format('Y-m-d H:i:s') : '-', 'types' => implode(', ', $types), 'assigned' => $userPermission ? $userPermission->getIsAssigned() : false);
 }
示例#12
0
 public function it_upload_new_image()
 {
     $filesystem = new Filesystem();
     $newFileName = __DIR__ . '/../../assets/images/temp-image.jpg';
     $filesystem->copy(__DIR__ . '/../../assets/images/picture.jpg', $newFileName);
     $uploadedFile = new UploadedFile($newFileName, 'temp-image.jpg', 'image/jpg', null, null, true);
     $user = new User('*****@*****.**');
     $user->setAdmin(true);
     $this->upload($uploadedFile, array('user' => $user))->shouldHaveType('Newscoop\\Image\\LocalImage');
 }
示例#13
0
 public function testAuthenticateValidAdmin()
 {
     $this->user->setActive();
     $this->user->setAdmin(TRUE);
     $this->em->persist($this->user);
     $this->em->flush();
     $this->service->setUsername(self::USERNAME)->setPassword(self::PASSWORD)->setAdmin(TRUE);
     $result = $this->service->authenticate();
     $this->assertEquals(\Zend_Auth_Result::SUCCESS, $result->getCode());
 }
 public function let($die, \Doctrine\ORM\EntityManager $em, \Symfony\Component\Routing\Router $router, UserService $userService, \Newscoop\Entity\Repository\AutoIdRepository $repository, \Newscoop\Entity\User $user)
 {
     $em->getRepository('Newscoop\\Entity\\AutoId')->willReturn($repository);
     $em->persist(Argument::any())->willReturn(true);
     $em->flush(Argument::any())->willReturn(true);
     $em->remove(Argument::any())->willReturn(true);
     $repository->getNextTranslationPhraseId()->willReturn('7');
     $user->hasPermission('AddFile')->willReturn(true);
     $userService->getCurrentUser()->willReturn($user);
     $this->beConstructedWith(array('file_base_url' => "files/", 'file_directory' => realpath(__DIR__ . '/../../../newscoop/public/files') . '/', 'file_num_dirs_level_1' => 1000, 'file_num_dirs_level_2' => 1000), $em, $router, $userService);
 }
示例#15
0
 public function testFindWithLimit()
 {
     for ($i = 0; $i < 50; $i++) {
         $user = new User();
         $user->setEmail(uniqid("email_{$i}", true));
         $user->setUsername(uniqid("username_{$i}", true));
         $this->em->persist($user);
     }
     $this->em->flush();
     $this->assertEquals(25, count($this->service->find('email_')));
 }
示例#16
0
 /**
  * Get blog info article
  *
  * @param Newscoop\Entity\User $user
  * @return Article|null
  */
 public function getBlogInfo(User $user)
 {
     $articles = \Article::GetArticles($this->config['publication'], $this->config['issue'], null, null, null, false, array("Type = '" . $this->config['type'] . "'"));
     foreach ($articles as $article) {
         $data = $article->getArticleData();
         $authors = array_map('trim', explode(self::SEPARATOR, $data->getFieldValue('loginname')));
         if (in_array($user->getUsername(), $authors)) {
             return $article;
         }
     }
     return null;
 }
示例#17
0
 /**
  * Add identity
  *
  * @param Newscoop\Entity\User $user
  * @param string $provider
  * @param string $providerUserId
  * @return void
  */
 public function addIdentity(User $user, $provider, $providerUserId)
 {
     $userIdentity = $this->em->getRepository('Newscoop\\Entity\\UserIdentity')->findOneBy(array('provider' => $provider, 'provider_user_id' => $providerUserId));
     if ($userIdentity) {
         return $userIdentity;
     }
     $userIdentity = new UserIdentity($provider, $providerUserId, $user);
     $this->em->persist($userIdentity);
     $user->setLastLogin(new \DateTime());
     $this->em->flush();
     return $userIdentity;
 }
 public function let(Container $container, EntityManager $entityManager, Request $request, AbstractQuery $query, UserTopicService $userTopicService, UserRepository $userRepository, User $user, Paginator $knpPaginator, PaginatorService $paginator, EntityRepository $repository)
 {
     $container->get('em')->willReturn($entityManager);
     $container->get('user.topic')->willReturn($userTopicService);
     $container->get('newscoop.paginator.paginator_service')->willReturn($paginator);
     $entityManager->persist(Argument::any())->willReturn(true);
     $entityManager->flush(Argument::any())->willReturn(true);
     $entityManager->remove(Argument::any())->willReturn(true);
     $entityManager->getRepository('Newscoop\\Entity\\User')->willReturn($repository);
     $user->getId()->willReturn(1);
     $user->getUsername()->willReturn('admin');
     $user->getEmail()->willReturn('*****@*****.**');
     $this->setContainer($container);
 }
 public function saveTopicsAction()
 {
     $form = new Application_Form_Topics();
     $topics = $this->_helper->service('topic')->getMultiOptions();
     $form->topics->setMultiOptions($topics);
     $form->selected->setMultiOptions($topics);
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
         $command = new SaveUserTopicsCommand($form->getValues());
         $command->userId = $this->user->getId();
         $this->_helper->service('user.topic')->saveUserTopics($command);
         $this->_helper->json($command->selected);
     }
     $this->getResponse()->setHttpResponseCode(400);
     $this->_helper->json($form->getMessages());
 }
 public function its_lockUnlockArticle_should_lock_article($request, $article, $query, $number, $language, $user, $token, $security)
 {
     $query->getOneOrNullResult()->willReturn($article);
     $request->getMethod()->willReturn('POST');
     $article->isLocked()->willReturn(false);
     $user = new User('*****@*****.**');
     $user->setUsername('doe');
     $security->getToken()->willReturn($token);
     $token->getUser()->willReturn($user);
     $article->setLockUser($user)->willReturn(null);
     $article->setLockTime(Argument::type('\\DateTime'))->willReturn(null);
     $response = $this->lockUnlockArticle($request, $number, $language);
     $response->shouldBeAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response');
     $response->getStatusCode()->shouldReturn(200);
 }
 public function testSave()
 {
     $user = new User();
     $user->setUsername('testname');
     $user->setEmail('email');
     $this->em->persist($user);
     $this->em->flush();
     $event = new CommunityTickerEvent();
     $this->repository->save($event, array('event' => 'test.event', 'user' => 1, 'params' => array('param1' => 'value1')));
     $this->em->flush();
     $this->em->clear();
     $this->assertEquals(1, $event->getId());
     $this->assertEquals('test.event', $event->getEvent());
     $this->assertEquals($user, $event->getUser());
     $this->assertEquals(array('param1' => 'value1'), $event->getParams());
 }
示例#22
0
 /**
  * Send comment notification
  *
  * @param Newscoop\Entity\Comment $comment
  * @param Article $article
  * @param array $authors
  * @param Newscoop\Entity\User $user
  * @return void
  */
 public function sendCommentNotification(Comment $comment, \Article $article, array $authors, User $user = null)
 {
     $emails = array_unique(array_filter(array_map(function ($author) {
         return $author->getEmail();
     }, $authors)));
     if (empty($emails)) {
         return;
     }
     $this->view->placeholder(self::PLACEHOLDER_SUBJECT)->set('New Comment');
     $message = $this->view->action('comment-notify', 'email', 'default', array('comment' => $comment, 'article' => $article, 'user' => $user));
     $mail = new \Zend_Mail(self::CHARSET);
     $mail->setSubject($this->view->placeholder(self::PLACEHOLDER_SUBJECT));
     $mail->setBodyHtml($message);
     $mail->setFrom($user ? $user->getEmail() : $this->config['from']);
     foreach ($emails as $email) {
         $mail->addTo($email);
     }
     $mail->send();
 }
示例#23
0
 public function testGetPublicUserCount()
 {
     $this->assertEquals(0, $this->service->getPublicUserCount());
     $this->user->setActive();
     $this->em->persist($this->user);
     $this->em->flush();
     $this->assertEquals(0, $this->service->getPublicUserCount());
     $this->user->setPublic();
     $this->em->flush();
     $this->assertEquals(1, $this->service->getPublicUserCount());
 }
示例#24
0
 /**
  * Set form defaults
  *
  * @param  Newscoop\Entity\User   $user
  * @return Admin_Form_Geolocation
  */
 public function setDefaultsFromEntity(User $user)
 {
     return $this->setDefaults(array('geolocation' => $user->getAttribute('geolocation')));
 }
 public function preUpdate()
 {
     $this->__load();
     return parent::preUpdate();
 }
示例#26
0
 /**
  * Log in user
  *
  * @param Newscoop\Entity\User $user
  * @param string               $providerKey
  *
  * @return UsernamePasswordToken
  */
 public function loginUser(User $user, $providerKey)
 {
     $roles = $user->getRoles();
     $token = new UsernamePasswordToken($user, null, $providerKey, $roles);
     $this->security->setToken($token);
     return $token;
 }
示例#27
0
 public function testGenerateUsername()
 {
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setUsername('Foo Bar');
     $this->em->persist($user);
     $this->em->flush();
     $this->assertEquals('Foos Bar', $this->service->generateUsername('Foos', 'Bar'));
     $this->assertEquals('Foo Bar1', $this->service->generateUsername('Foo', 'Bar'));
     $this->assertEquals('', $this->service->generateUsername(' ', ' '));
     $this->assertEquals('Foo', $this->service->generateUsername('Foo', ''));
     $this->assertEquals('Bar', $this->service->generateUsername('', 'Bar'));
     $this->assertEquals('', $this->service->generateUsername('!@#$%^&*()+-={}[]\\|;\':"§-?/.>,<', ''));
     $this->assertEquals('_', $this->service->generateUsername('_', ''));
     $this->assertEquals('Foo Bar Jr', $this->service->generateUsername('Foo  Bar ', ' Jr '));
 }
示例#28
0
 /**
  * Remove user attributes
  *
  * @param  Newscoop\Entity\User $user
  * @return void
  */
 private function removeAttributes(User $user)
 {
     $attributes = $this->getEntityManager()->getRepository('Newscoop\\Entity\\UserAttribute')->findBy(array('user' => $user->getId()));
     foreach ($attributes as $attribute) {
         $user->addAttribute($attribute->getName(), null);
         $this->getEntityManager()->remove($attribute);
     }
 }
示例#29
0
 /**
  * Get articles count for user if is author.
  *
  * @param Newscoop\Entity\User $user
  *
  * @return int
  */
 public function countByAuthor(User $user)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->select('count(a)')->from('Newscoop\\Entity\\Article', 'a')->from('Newscoop\\Entity\\ArticleAuthor', 'aa')->from('Newscoop\\Entity\\User', 'u')->where('a.number = aa.articleNumber')->andWhere('a.language = aa.languageId')->andWhere('aa.author = u.author')->andwhere('u.id = :user')->andWhere($qb->expr()->in('a.type', array('news', 'blog')))->andWhere('a.workflowStatus = :status')->setParameters(array('user' => $user->getId(), 'status' => Article::STATUS_PUBLISHED));
     $count = $qb->getQuery()->getSingleScalarResult();
     return (int) $count;
 }
示例#30
0
 /**
  * Get user image
  *
  * @param Newscoop\Entity\User $user
  * @param int $width
  * @param int $height
  * @return string
  */
 public function getUserImage(User $user, $width = 65, $height = 65)
 {
     if ($user->getImage() !== null) {
         return $this->getSrc('images/' . $user->getImage(), $width, $height, 'crop');
     }
     return null;
 }