Beispiel #1
0
 public function loginAction()
 {
     $form = new Syj_Form_Login(array('name' => 'loginform'));
     $request = $this->getRequest();
     $formData = $request->getPost();
     $this->view->form = $form;
     $httprequest = $request->isXmlHttpRequest();
     if (!$httprequest) {
         $this->_jsLocaleStrings();
     }
     if (empty($formData) or !$form->isValid($formData)) {
         if ($httprequest) {
             throw new Syj_Exception_Request();
         } else {
             return;
         }
     }
     /* form has been filled */
     if (!$this->_helper->SyjUserManager->validate($formData['login_user'], sha1($formData['login_password']), $formData['login_rememberme'])) {
         if ($httprequest) {
             throw new Syj_Exception_Forbidden();
         } else {
             $form->addError('Wrong login/password');
             return;
         }
     }
     $user = $this->_helper->SyjUserManager->current();
     if ($httprequest) {
         $api = $this->_helper->SyjApi->setCode(200);
         $data = array('pseudo' => $user->pseudo);
         $login_geom_id = $formData['login_geom_id'];
         if ($login_geom_id) {
             $path = new Syj_Model_Path();
             $pathMapper = new Syj_Model_PathMapper();
             if (!$pathMapper->find((int) $login_geom_id, $path)) {
                 throw new Syj_Exception_Request();
             }
             $data['iscreator'] = $path->creator->id === $user->id;
         } else {
             $data['iscreator'] = true;
         }
         $api->setBodyJson($data);
     } else {
         $this->redirect();
     }
 }
Beispiel #2
0
 public function getPath()
 {
     $idx = $this->getRequest()->getUserParam('idx');
     $path = new Syj_Model_Path();
     $pathMapper = new Syj_Model_PathMapper();
     if (!$pathMapper->find($idx, $path)) {
         if ($pathMapper->hasexisted($idx)) {
             throw new Syj_Exception_NotFound('Gone', 410);
         } else {
             throw new Syj_Exception_NotFound('Not Found', 404);
         }
     }
     $user = $this->_helper->SyjUserManager->current();
     if (!$path->isCreator($user)) {
         throw new Syj_Exception_Forbidden();
     }
     return $path;
 }
Beispiel #3
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $idx = $request->idx;
     $pathMapper = new Syj_Model_PathMapper();
     $path = new Syj_Model_Path();
     $api = $this->_helper->SyjApi;
     $ext = "";
     $parts = explode('.', $idx);
     if (count($parts) >= 2) {
         $ext = end($parts);
         if (in_array($ext, array('kml', 'gpx', 'json'))) {
             $idx = implode('.', explode('.', $idx, -1));
         } else {
             $ext = "";
         }
     }
     if (!$pathMapper->find($idx, $path)) {
         if (!$pathMapper->findByTitle($idx, $path)) {
             if ($pathMapper->hasexisted($idx)) {
                 $api->setCode(410);
             } else {
                 $api->setCode(404);
             }
             return;
         }
     }
     switch ($ext) {
         case 'kml':
             $this->kml($path);
             break;
         case 'gpx':
             $this->gpx($path);
             break;
         case 'json':
         default:
             $this->json($path);
             return;
             break;
     }
 }