[5595] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class Expresso { |
---|
| 4 | |
---|
| 5 | var $result; |
---|
| 6 | var $error; |
---|
| 7 | var $id; |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | function __construct($id){ |
---|
| 11 | $this->result = null; |
---|
| 12 | $this->error = null; |
---|
| 13 | $this-> id = $id; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | protected function getResponse(){ |
---|
| 17 | return array( |
---|
| 18 | 'result' => $this->result, |
---|
| 19 | 'error' => $this->error, |
---|
| 20 | 'id' => $this->id |
---|
| 21 | ); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | protected function isLoggedIn($params){ |
---|
| 26 | list($sessionid, $kp3) = explode(":", $params['auth']); |
---|
| 27 | if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){ |
---|
| 28 | return true; |
---|
| 29 | } |
---|
| 30 | else{ |
---|
| 31 | $this-> error = "You are not logged in"; |
---|
| 32 | return false; |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | public function login($params){ |
---|
| 38 | if(!$this-> isLoggedIn($params)) |
---|
| 39 | { |
---|
| 40 | if($params['auth'] != "") |
---|
| 41 | { |
---|
| 42 | $this->error = "Your auth is invalid"; |
---|
| 43 | |
---|
| 44 | } |
---|
| 45 | elseif($sessionid = $GLOBALS['phpgw']->session->create($params['user'], $params['password'])) |
---|
| 46 | { |
---|
| 47 | $this->error = null; |
---|
| 48 | $this->result = array('auth' => $sessionid.":".$GLOBALS['phpgw']->session->kp3); |
---|
| 49 | } |
---|
| 50 | else |
---|
| 51 | { |
---|
| 52 | $this-> error = $GLOBALS['phpgw']->session->reason; |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | else |
---|
| 56 | { |
---|
| 57 | $this->result = array('auth' => $params['auth']); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | return $this->getResponse(); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | public function logout($params){ |
---|
| 64 | |
---|
| 65 | if($this->isLoggedIn($params)) |
---|
| 66 | { |
---|
| 67 | if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'])) |
---|
| 68 | { |
---|
| 69 | $dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir']. SEP . $_SESSION['phpgw_session']['session_id']); |
---|
| 70 | while ($file = readdir($dh)) |
---|
| 71 | { |
---|
| 72 | if ($file != '.' && $file != '..') |
---|
| 73 | { |
---|
| 74 | unlink($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'].SEP.$file); |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | rmdir($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']); |
---|
| 78 | } |
---|
| 79 | $GLOBALS['phpgw']->hooks->process('logout'); |
---|
| 80 | $GLOBALS['phpgw']->session->destroy($_SESSION['phpgw_session']['session_id'], $GLOBALS['kp3']); |
---|
| 81 | $this->result = true; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | return $this->getResponse(); |
---|
| 85 | } |
---|
| 86 | } |
---|