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