Beispiel #1
0
 /**
  * @param Request $request
  * @param Created $payload
  */
 public function created(Request $request, Created $payload)
 {
     $serializer = User::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]);
 }
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Group::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['users', 'actions']));
     $resource = $resource->fields($params->getFields(['group' => Group::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'action' => Action::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
Beispiel #3
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Judge::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['startgroup', 'user', 'performance-score']));
     $resource = $resource->fields($params->getFields(['judge' => Judge::getSerializer()->getFields(), 'startgroup' => Startgroup::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'performance-score' => PerformanceScore::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Activity::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['actor', 'object', 'target']));
     $resource = $resource->fields($params->getFields(['activity' => Activity::getSerializer()->getFields(), 'actor' => User::getSerializer()->getFields(), 'object' => ActivityObject::getSerializer()->getFields(), 'target' => ActivityObject::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Session::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['user']));
     $resource = $resource->fields($params->getFields(['session' => Session::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
Beispiel #6
0
 /**
  * @param mixed $model
  * @return Relationship
  */
 public function user($model)
 {
     $serializer = User::getSerializer();
     $id = $serializer->getId($model->getUser());
     if ($id !== null) {
         $relationship = new Relationship(new Resource($model->getUser(), $serializer));
         $relationship->setLinks(['related' => '%apiurl%' . $serializer->getType(null) . '/' . $id]);
         return $this->addRelationshipSelfLink($relationship, $model, 'user');
     }
     return null;
 }
Beispiel #7
0
 protected function updateDisplayName(User $user)
 {
     $prefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences();
     $choice = $prefs->getUserDisplayName();
     if ($prefs->getUserDisplayName() == SystemPreferences::DISPLAY_USERSELECT) {
         $choice = $user->getDisplayNameUserSelect();
     }
     switch ($choice) {
         case SystemPreferences::DISPLAY_GIVENFAMILYNAME:
             $user->setDisplayName($user->getGivenName() . ' ' . $user->getFamilyName());
             break;
         case SystemPreferences::DISPLAY_FAMILYGIVENNAME:
             $user->setDisplayName($user->getFamilyName() . ' ' . $user->getGivenName());
             break;
         case SystemPreferences::DISPLAY_NICKNAME:
             $user->setDisplayName($user->getNickName());
             break;
         case SystemPreferences::DISPLAY_USERNAME:
             $user->setDisplayName($user->getUserName());
             break;
     }
 }
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $data = $payload->getModel();
     $serializer = Judge::getSerializer();
     $resource = new Collection($data, $serializer);
     $resource = $resource->with($params->getInclude(['startgroup', 'user', 'performance-score']));
     $resource = $resource->fields($params->getFields(['judge' => Judge::getSerializer()->getFields(), 'startgroup' => Startgroup::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'performance-score' => PerformanceScore::getSerializer()->getFields()]));
     $document = new Document($resource);
     // meta
     $document->setMeta(['total' => $data->getNbResults(), 'first' => $data->getFirstPage(), 'next' => $data->getNextPage(), 'previous' => $data->getPreviousPage(), 'last' => $data->getLastPage()]);
     // return response
     return new JsonResponse($document->toArray());
 }
Beispiel #9
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->aGroup) {
         $this->aGroup->removeUserGroup($this);
     }
     if (null !== $this->aUser) {
         $this->aUser->removeUserGroup($this);
     }
     $this->user_id = null;
     $this->group_id = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $data = $payload->getModel();
     $serializer = Group::getSerializer();
     $resource = new Collection($data, $serializer);
     $resource = $resource->with($params->getInclude(['users', 'actions']));
     $resource = $resource->fields($params->getFields(['group' => Group::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'action' => Action::getSerializer()->getFields()]));
     $document = new Document($resource);
     // meta
     if ($params->getPage('size') != -1) {
         $document->setMeta(['total' => $data->getNbResults(), 'first' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getFirstPage()]]), 'next' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getNextPage()]]), 'previous' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getPreviousPage()]]), 'last' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getLastPage()]])]);
     }
     // return response
     return new JsonResponse($document->toArray());
 }
Beispiel #11
0
 /**
  * @param User $user
  * @param string $password
  * @return boolean
  */
 public function verifyUser(User $user, $password)
 {
     return password_verify($password, $user->getPassword());
 }
Beispiel #12
0
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $serializer = User::getSerializer();
     $relationship = $serializer->sessions($payload->getModel());
     return new JsonResponse($relationship->toArray());
 }
Beispiel #13
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $page = $this->getServiceContainer()->getKernel()->getApplication()->getPage();
     $page->setTitle($this->getServiceContainer()->getTranslator()->trans('registration'));
     if ($request->isMethod('POST')) {
         $post = $request->request;
         $prefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences();
         $translator = $this->getServiceContainer()->getTranslator();
         // check errors first
         $errors = [];
         // username
         if ($prefs->getUserLogin() == SystemPreferences::LOGIN_USERNAME && !$post->has('user-name')) {
             $errors[] = $translator->trans('error.required', ['field' => $translator->trans('user_name')]);
         }
         // email
         $emailRequired = $prefs->getUserEmail() || $prefs->getUserLogin() == SystemPreferences::LOGIN_EMAIL || $prefs->getUserLogin() == SystemPreferences::LOGIN_USERNAME_EMAIL;
         if ($emailRequired && !$post->has('email')) {
             $errors[] = $translator->trans('error.required', ['field' => $translator->trans('email')]);
         }
         // given name
         if ($prefs->getUserNames() == SystemPreferences::VALUE_REQUIRED && !$post->has('given-name')) {
             $errors[] = $translator->trans('error.required', ['field' => $translator->trans('given_name')]);
         }
         // family name
         if ($prefs->getUserNames() == SystemPreferences::VALUE_REQUIRED && !$post->has('family-name')) {
             $errors[] = $translator->trans('error.required', ['field' => $translator->trans('family_name')]);
         }
         // birth
         if ($prefs->getUserBirth() == SystemPreferences::VALUE_REQUIRED && !$post->has('birth')) {
             $errors[] = $translator->trans('error.required', ['field' => $translator->trans('birth')]);
         }
         // sex
         if ($prefs->getUserSex() == SystemPreferences::VALUE_REQUIRED && !$post->has('sex')) {
             $errors[] = $translator->trans('error.required', ['field' => $translator->trans('sex')]);
         }
         // passwords
         if (!$post->has('password') && !$post->has('password_confirm')) {
             $errors[] = $translator->trans('error.required', ['field' => $translator->trans('password')]);
         }
         if ($post->get('password') != $post->get('password_confirm')) {
             $errors[] = $translator->trans('error.password_nomatch');
         }
         $vars = ['failures' => $errors, 'fields' => $post->all()];
         if (count($errors) == 0) {
             $serializer = User::getSerializer();
             $fields = $serializer->getFields();
             $attribs = ['password' => $post->get('password')];
             foreach ($fields as $field) {
                 if ($post->has($field)) {
                     $attribs[$field] = $post->get($field);
                 }
             }
             $domain = new UserDomain($this->getServiceContainer());
             $payload = $domain->create(['attributes' => $attribs]);
             if ($payload instanceof NotValid) {
                 $payload = new NotValid(array_merge($payload->get(), $vars));
             } else {
                 if ($payload instanceof Created) {
                     $user = $payload->getModel();
                     // send mail
                     $prefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences();
                     $localeService = $this->getServiceContainer()->getLocaleService();
                     $file = $localeService->findLocaleFile('/keeko/account/locales/{locale}/mail/registration.twig');
                     $body = $this->render($file, ['user' => $user->getDisplayName(), 'username' => $user->getUserName(), 'plattform' => $prefs->getPlattformName()]);
                     $mailer = $this->getServiceContainer()->getMailer();
                     $message = $this->getServiceContainer()->createMessage();
                     $message->setTo($user->getEmail());
                     $message->setSubject($translator->trans('registration.subject', ['plattform' => $prefs->getPlattformName()]));
                     $message->setBody($body);
                     $mailer->send($message);
                 }
             }
         } else {
             $post->remove('password');
             $post->remove('password_confirm');
             $payload = new NotValid($vars);
         }
     } else {
         $payload = new Blank();
     }
     return $this->responder->run($request, $payload);
 }
Beispiel #14
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->aActor) {
         $this->aActor->removeActivity($this);
     }
     if (null !== $this->aObject) {
         $this->aObject->removeActivityRelatedByObjectId($this);
     }
     if (null !== $this->aTarget) {
         $this->aTarget->removeActivityRelatedByTargetId($this);
     }
     $this->id = null;
     $this->actor_id = null;
     $this->verb = null;
     $this->object_id = null;
     $this->target_id = null;
     $this->created_at = null;
     $this->updated_at = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Beispiel #15
0
 /**
  * @param mixed $model
  * @return Relationship
  */
 public function users($model)
 {
     $method = 'get' . $this->getCollectionMethodPluralName('users');
     $relationship = new Relationship(new Collection($model->{$method}(), User::getSerializer()));
     return $this->addRelationshipSelfLink($relationship, $model, 'user');
 }
Beispiel #16
0
 /**
  */
 public function getRelationships()
 {
     return ['actor' => User::getSerializer()->getType(null), 'object' => ActivityObject::getSerializer()->getType(null), 'target' => ActivityObject::getSerializer()->getType(null)];
 }
Beispiel #17
0
 /**
  * Interal mechanism to remove Sessions from User
  * 
  * @param User $model
  * @param mixed $data
  */
 protected function doRemoveSessions(User $model, $data)
 {
     $errors = [];
     foreach ($data as $entry) {
         if (!isset($entry['id'])) {
             $errors[] = 'Missing id for Session';
         } else {
             $related = SessionQuery::create()->findOneById($entry['id']);
             $model->removeSession($related);
         }
     }
     if (count($errors) > 0) {
         return new ErrorsException($errors);
     }
 }
Beispiel #18
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->removeSession($this);
     }
     $this->token = null;
     $this->user_id = null;
     $this->ip = null;
     $this->user_agent = null;
     $this->browser = null;
     $this->device = null;
     $this->os = null;
     $this->location = null;
     $this->created_at = null;
     $this->updated_at = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Beispiel #19
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;
 }
Beispiel #20
0
 /**
  * Filter the query by a related \keeko\core\model\User object
  *
  * @param \keeko\core\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 ChildJudgeQuery The current query, for fluid interface
  */
 public function filterByUser($user, $comparison = null)
 {
     if ($user instanceof \keeko\core\model\User) {
         return $this->addUsingAlias(JudgeTableMap::COL_USER_ID, $user->getId(), $comparison);
     } elseif ($user instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(JudgeTableMap::COL_USER_ID, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByUser() only accepts arguments of type \\keeko\\core\\model\\User or Collection');
     }
 }
Beispiel #21
0
 private function isGuest(User $user)
 {
     return $user->getId() === -1;
 }