From d4a33fc1f9e324ce2f81b26c0b5c8675a83b8f26 Mon Sep 17 00:00:00 2001 From: Stefan Puraner Date: Mon, 11 Apr 2016 08:43:29 +0200 Subject: [PATCH] changed method to post --- application/controllers/api/v1/Person.php | 51 ++++++++++++++++++++-- application/models/person/Person_model.php | 20 ++++++--- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/application/controllers/api/v1/Person.php b/application/controllers/api/v1/Person.php index e90dcc2c7..0ac0ba638 100644 --- a/application/controllers/api/v1/Person.php +++ b/application/controllers/api/v1/Person.php @@ -33,13 +33,56 @@ class Person extends REST_Controller { //if (!$this->session_model->validate($this->get('session_id'), $this->get('device_id'))) // $this->response(array(['success' => false, 'message' => 'access denied']), REST_Controller::HTTP_UNAUTHORIZED); - + $code = $this->get('code'); + $email = $this->get('email'); $person_id = $this->get('person_id'); - if (!is_null($code)) + if ((!is_null($code)) && (!is_null($email))) { - $result = $this->person_model->getPersonByCode($code); + $result = $this->person_model->getPersonByCodeAndEmail($code, $email); + } + elseif (!is_null($person_id)) + { + $result = $this->person_model->getPerson($person_id); + } + else + { + $result = $this->person_model->getPerson(); + } + + if (empty($result)) + { + $payload = [ + 'success' => false, + 'message' => 'Person not found' + ]; + $httpstatus = REST_Controller::HTTP_OK; + } + else + { + // return all available persons + $payload = [ + 'success' => true, + 'message' => 'Persons found' + ]; + $payload['data'] = $result; + $httpstatus = REST_Controller::HTTP_OK; + } + + // Set the response and exit + $this->response($payload, $httpstatus); + } + + public function personFromCode_post() + { + $code = $this->post('code'); + $email = $this->post('email'); + $person_id = $this->post('person_id'); + + if ((!is_null($code)) && (!is_null($email))) + { + $result = $this->person_model->getPersonByCodeAndEmail($code, $email); } elseif (!is_null($person_id)) { @@ -134,7 +177,7 @@ class Person extends REST_Controller $this->response($payload, $httpstatus); } - public function checkZugangscodePerson_get() + public function checkZugangscodePerson_get() { $result = $this->person_model->checkZugangscodePerson($this->get("code")); $httpstatus = REST_Controller::HTTP_OK; diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 164b92405..684c1de87 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -21,13 +21,20 @@ class Person_model extends DB_Model return $query->row_object(); } - public function getPersonByCode($code) + public function getPersonByCodeAndEmail($code, $email) { - if ($this->fhc_db_acl->bb->isBerechtigt('person', 's')) - { - $query = $this->db->get_where('public.tbl_person', array('zugangscode' => $code)); - return $query->result_object(); - } +// if ($this->fhc_db_acl->bb->isBerechtigt('person', 'suid')) +// { + $this->db->select("*") + ->from('public.tbl_person p') + ->join("public.tbl_kontakt k", "k.person_id=p.person_id") + ->where("p.zugangscode", $code) + ->where("k.kontakt", $email); + + return $this->db->get()->result_object(); +// $query = $this->db->get_where('public.tbl_person p ', array('zugangscode' => $code)); +// return $query->result_object(); +// } } /** @@ -57,6 +64,7 @@ class Person_model extends DB_Model "gebdatum"=>$person["gebdatum"], "aktiv" => true, "zugangscode"=>$person["zugangscode"], + "zugangscode_timestamp"=>date('Y-m-d H:i:s'), "insertamum"=>date('Y-m-d H:i:s'), "insertvon"=>$person["insertvon"], );