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