/** * {@inheritdoc} */ public function onExecuteAction(ExecuteActionEvent $event, $eventConfig) { $request = $event->getRequest(); try { $userId = $request->getSession()->get('user.id'); $user = $this->cast('Mapper\\User', $userId); $redirectUrl = null; if ($request->getController() == 'Resource') { return; } else { if (!$user->getLocation() && ($request->getController() != 'Authenticate' || $request->getMethod() != 'setLocation')) { $redirectUrl = '/login/location'; } else { if ($user->getLocation() && $request->getController() == 'Authenticate' && $request->getMethod() == 'setLocation') { $redirectUrl = '/'; } else { return; } } } $response = new Response(); $response->redirect($redirectUrl); $event->setResponse($response); } catch (ValueNotFoundException $e) { return; } catch (UserNotFoundExceptio $e) { $request->getSession()->clear(); $response = new Response(); $response->redirect('/login'); $event->setResponse($response); } }
private function createResponseRedirect($redirect, $request) { $response = new Response(); if ($request->isAjax()) { $response->setStatusCode(401); $response->setHeader('X-Location', $redirect); } else { $response->redirect($redirect); } return $response; }
/** * Saves user entity to database after edit * * @param User $entity * @return Response|array */ public function edit($entity) { $form = $this->createForm($entity); if ($form->isValid()) { $data = $form->getData(); $this->setEntity($entity, $data); $this->flush(); $response = new Response(); $response->redirect('/user'); return $response; } return compact('form'); }
/** * Removes location entity * * @param \Entity\Location $entity * @return Response */ public function remove($entity) { if ($entity == $this->getUser()->getLocation()) { throw new UnableToDeleteOwnLocationException(); } $this->getDoctrine()->getEntityManager()->remove($entity); $this->flush(); $response = new Response(); $response->redirect('/location'); return $response; }
/** * Form with contact data to current owner * * @return Response|array */ public function addApply() { $data = $this->getRequest()->getSession()->get('order.info'); $device = $this->cast('Mapper\\Device', $data['device']); /* @var $device Device */ $location = $device->getLocation(); /* @var $location Location */ $form = $this->createApplyForm(); if ($form->isValid()) { if ($device->getLocation() == $this->getUser()->getLocation()) { throw new OrderWrongLocationException(); } $entity = new \Entity\Order(); $entity->setOwner($this->getUser()); $entity->setDevice($device); $entity->setState($this->cast('Mapper\\OrderState', 1)); $this->persist($entity); $device->setState($this->cast('Mapper\\DeviceState', 2)); $this->flush(); $response = new Response(); $response->redirect('/order'); $this->getRequest()->getSession()->remove('order.info'); return $response; } return compact('form', 'device', 'location'); }
/** * Removing device type from database * * @param \Entity\DeviceType $entity * @return Response */ public function remove($entity) { $this->getDoctrine()->getEntityManager()->remove($entity); $this->flush(); $response = new Response(); $response->redirect('/devicetype'); return $response; }
/** * Logout method * * @return Response * @throws \Arbor\Exception\ServiceNotFoundException */ public function logout() { $googleService = $this->getService('google'); $client = $googleService->getClient(); $client->revokeToken(); $this->getRequest()->getSession()->clear(); $response = new Response(); $response->redirect('/'); return $response; }
/** * Assign device to me * * @param \Entity\Device $entity * @return Response */ public function assign($entity) { if ($entity->getLocation()->getId() != $this->getUser()->getId()) { throw new DeviceNotFoundException(); } if ($entity->getUser()) { throw new AlreadyHasOwnerException(); } $entity->setUser($this->getUser()); $this->flush(); $response = new Response(); $response->redirect('/device/location'); return $response; }
/** * Save changes on device after edit * * @param \Entity\Device $device * @return Response|array */ public function edit($device) { $form = $this->createForm($device); if ($form->isValid()) { $data = $form->getData(); $conn = $this->getDoctrine()->getEntityManager()->getConnection(); $conn->beginTransaction(); if ($data['photo']) { //save uploaded photo to cache file $data['tmpPhoto'] = $this->saveTmpPhoto($data['photo']); } $this->saveEntity($device, $data, $data['serialNumber']); $this->flush(); $conn->commit(); $response = new Response(); $response->redirect('/device'); return $response; } return compact('form'); }
/** * create response with configure redirect action * * @param \Arbor\Core\Container $container * @param string $url - destiny http address * @return \Arbor\Provider\Response */ public function redirect(Container $container, $url) { $response = new Response(); $response->redirect($url); return $response; }
/** * Assign device to my location * * @param \Entity\Device $entity * @return Response */ public function assign($entity) { if ($entity->getUser()->getId() != $this->getUser()->getId()) { throw new YouAreNotOwnerException(); } $entity->setUser(null); $this->flush(); $response = new Response(); $response->redirect('/device/my'); return $response; }