public function postAction(Request $request)
 {
     $repo = $this->get('tekstove.user.repository');
     /* @var $repo \Tekstove\ApiBundle\Model\User\UserRepository */
     $recaptchaSecret = $this->container->getParameter('tekstove_api.recaptcha.secret');
     $requestData = \json_decode($request->getContent(), true);
     $userData = $requestData['user'];
     $recaptchaData = $requestData['recaptcha'];
     $user = new User();
     try {
         $recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret);
         $recaptchaResponse = $recaptcha->verify($recaptchaData['g-recaptcha-response']);
         if (!$recaptchaResponse->isSuccess()) {
             $recaptchaException = new UserHumanReadableException("Recaptcha validation failed");
             $recaptchaException->addError("recaptcha", "Validation failed");
             throw $recaptchaException;
         }
         $user->setUsername($userData['username']);
         $user->setMail($userData['mail']);
         $user->setPassword($this->hashPassword($userData['password']));
         $user->setapiKey(sha1(str_shuffle(uniqid())));
         $repo->save($user);
     } catch (UserHumanReadableException $e) {
         $view = $this->handleData($request, $e->getErrors());
         $view->setStatusCode(400);
         return $view;
     }
 }
Exemple #2
0
 /**
  * Anonymous user try to edit existing lyric
  */
 public function testGetAllowedFields()
 {
     $user = new User();
     $lyric = new Lyric();
     $lyric->setId(5);
     $allowedFields = $user->getAllowedLyricFields($lyric);
     $this->assertEmpty($allowedFields);
 }
 public function indexAction(Request $request, $id)
 {
     if ($this->getUser()) {
         $user = $this->getUser();
     } else {
         $user = new User();
     }
     if ($id) {
         $lyricQuery = new LyricQuery();
         $lyric = $lyricQuery->findOneById($id);
     } else {
         $lyric = new Lyric();
     }
     $allowedFields = $user->getAllowedLyricFields($lyric);
     $data = ['item' => ['fields' => $allowedFields]];
     return $this->handleData($request, $data);
 }
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aUser) {
         $this->aUser->removePermissionGroupUser($this);
     }
     if (null !== $this->aPermissionGroup) {
         $this->aPermissionGroup->removePermissionGroupUser($this);
     }
     $this->user_id = null;
     $this->group_id = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Exemple #5
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aUser) {
         $this->aUser->removeLyricVote($this);
     }
     if (null !== $this->aLyric) {
         $this->aLyric->removeLyricVote($this);
     }
     $this->id = null;
     $this->lyric_id = null;
     $this->user_id = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
 /**
  * Filter the query by a related \Tekstove\ApiBundle\Model\User object
  *
  * @param \Tekstove\ApiBundle\Model\User|ObjectCollection $user The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @throws \Propel\Runtime\Exception\PropelException
  *
  * @return ChildPermissionGroupUserQuery The current query, for fluid interface
  */
 public function filterByUser($user, $comparison = null)
 {
     if ($user instanceof \Tekstove\ApiBundle\Model\User) {
         return $this->addUsingAlias(PermissionGroupUserTableMap::COL_USER_ID, $user->getId(), $comparison);
     } elseif ($user instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(PermissionGroupUserTableMap::COL_USER_ID, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByUser() only accepts arguments of type \\Tekstove\\ApiBundle\\Model\\User or Collection');
     }
 }
 public function deleteAction(Request $request, $id)
 {
     $this->getContext()->setGroups(['Details']);
     $lyricQuery = new LyricQuery();
     /* @var $lyric Lyric */
     $lyric = $lyricQuery->findOneById($id);
     try {
         if ($this->getUser()) {
             $user = $this->getUser();
         } else {
             $user = new User();
         }
         $allowedFields = $user->getAllowedLyricFields($lyric);
         if (!in_array('delete', $allowedFields)) {
             throw new \Exception("Delete not allowed");
         }
         $lyric->delete();
         return $this->handleData($request, $lyric);
     } catch (LyricHumanReadableException $e) {
         $view = $this->handleData($request, $e->getErrors());
         $view->setStatusCode(400);
         return $view;
     }
 }
 public function save(User $user)
 {
     $user->setValidator($this->validator);
     $user->save();
 }
Exemple #9
0
 /**
  * Exclude object from result
  *
  * @param   ChildUser $user Object to remove from the list of results
  *
  * @return $this|ChildUserQuery The current query, for fluid interface
  */
 public function prune($user = null)
 {
     if ($user) {
         $this->addUsingAlias(UserTableMap::COL_ID, $user->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Exemple #10
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aUser) {
         $this->aUser->removeArtist($this);
     }
     $this->id = null;
     $this->name = null;
     $this->user_id = null;
     $this->forbidden = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Exemple #11
0
 /**
  * Validates the object and all objects related to this table.
  *
  * @see        getValidationFailures()
  * @param      ValidatorInterface|null $validator A Validator class instance
  * @return     boolean Whether all objects pass validation.
  */
 public function validate(ValidatorInterface $validator = null)
 {
     if (null === $validator) {
         $validator = new RecursiveValidator(new ExecutionContextFactory(new IdentityTranslator()), new LazyLoadingMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory());
     }
     $failureMap = new ConstraintViolationList();
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         // We call the validate method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         // If validate() method exists, the validate-behavior is configured for related object
         if (method_exists($this->aUser, 'validate')) {
             if (!$this->aUser->validate($validator)) {
                 $failureMap->addAll($this->aUser->getValidationFailures());
             }
         }
         $retval = $validator->validate($this);
         if (count($retval) > 0) {
             $failureMap->addAll($retval);
         }
         if (null !== $this->collArtistLyrics) {
             foreach ($this->collArtistLyrics as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyricLanguages) {
             foreach ($this->collLyricLanguages as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyricTranslations) {
             foreach ($this->collLyricTranslations as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyricVotes) {
             foreach ($this->collLyricVotes as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     $this->validationFailures = $failureMap;
     return (bool) (!(count($this->validationFailures) > 0));
 }