[6149] | 1 | <?php |
---|
| 2 | class ExpressoAdapter extends Resource { |
---|
| 3 | |
---|
| 4 | private $expressoVersion; |
---|
| 5 | private $request; |
---|
| 6 | private $params; |
---|
| 7 | private $result; |
---|
| 8 | private $error; |
---|
| 9 | private $id; |
---|
| 10 | |
---|
| 11 | function __construct($id){ |
---|
| 12 | $GLOBALS['phpgw_info'] = array( |
---|
| 13 | 'flags' => array( |
---|
| 14 | 'currentapp' => 'login', |
---|
| 15 | 'noheader' => True, |
---|
| 16 | 'disable_Template_class' => True |
---|
| 17 | ) |
---|
| 18 | ); |
---|
| 19 | |
---|
[6227] | 20 | include_once(__DIR__.'/../../header.inc.php'); |
---|
[6149] | 21 | $this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | protected function setRequest($request){ |
---|
| 25 | $this->request = $request; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | public function getRequest(){ |
---|
| 29 | return $this->request; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | protected function getExpressoVersion(){ |
---|
| 33 | return $this->expressoVersion; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | protected function setResult($result){ |
---|
| 37 | $this->result = $result; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | public function getResult(){ |
---|
| 41 | return $this->result; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | protected function setId($id){ |
---|
| 45 | $this->id = $id; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | public function getId(){ |
---|
| 49 | return $this->id; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | protected function setParams($params){ |
---|
| 53 | $this->params = $params; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | public function getParams(){ |
---|
| 57 | return $this->params; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | public function getParam($param){ |
---|
| 61 | return $this->params->$param; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | public function setError($error) { |
---|
| 65 | $this-> error = $error; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | protected function getError() { |
---|
| 69 | return $this-> error; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | public function post($request){ |
---|
| 73 | $this->setRequest($request); |
---|
| 74 | parse_str($request->data, &$array); |
---|
| 75 | $data = (object)$array; |
---|
| 76 | if($data){ |
---|
| 77 | if($data->params){ |
---|
| 78 | $this->setParams(json_decode($data->params)); |
---|
| 79 | } |
---|
| 80 | if($data->id) |
---|
| 81 | $this->setId($data->id); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | public function get($request){ |
---|
| 86 | $response = new Response($request); |
---|
| 87 | $response->code = Response::OK; |
---|
| 88 | $response->addHeader('content-type', 'text/html'); |
---|
| 89 | $response->body = "<H4>Metodo GET nao permitido para este recurso.</H4>"; |
---|
| 90 | return $response; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | public function getResponse(){ |
---|
| 94 | $response = new Response($this->getRequest()); |
---|
| 95 | $response->code = Response::OK; |
---|
| 96 | $response->addHeader('content-type', 'application/json'); |
---|
| 97 | |
---|
| 98 | if($this->getId()) |
---|
| 99 | $body['id'] = $this->getId(); |
---|
| 100 | if($this->getResult()) |
---|
| 101 | $body['result'] = $this->getResult(); |
---|
[6165] | 102 | else { |
---|
| 103 | Errors::runException("E_UNKNOWN_ERROR"); |
---|
| 104 | } |
---|
[6149] | 105 | |
---|
[6165] | 106 | |
---|
[6149] | 107 | $response->body = json_encode($body); |
---|
| 108 | |
---|
| 109 | return $response; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | protected function isLoggedIn(){ |
---|
| 113 | if($this->getParam('auth') != null) { |
---|
| 114 | list($sessionid, $kp3) = explode(":", $this->getParam('auth')); |
---|
| 115 | if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){ |
---|
| 116 | return $sessionid; |
---|
| 117 | } |
---|
| 118 | else{ |
---|
[6165] | 119 | Errors::runException("LOGIN_AUTH_INVALID"); |
---|
[6149] | 120 | } |
---|
| 121 | } |
---|
[6273] | 122 | elseif($sessionid = $GLOBALS['_COOKIE']['sessionid']) { |
---|
| 123 | if($GLOBALS['phpgw']->session->verify($sessionid)) { |
---|
| 124 | return $sessionid; |
---|
| 125 | } |
---|
| 126 | else{ |
---|
| 127 | Errors::runException("LOGIN_NOT_LOGGED_IN"); |
---|
| 128 | } |
---|
| 129 | } |
---|
[6149] | 130 | else{ |
---|
[6165] | 131 | Errors::runException("LOGIN_NOT_LOGGED_IN"); |
---|
[6149] | 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | } |
---|