source: sandbox/webservice/api/rest/core/LoginResource.php @ 6239

Revision 6239, 1.5 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Implementado mapeamento dos modulos do Expresso via arquivo ".ini"

Line 
1<?php
2
3class LoginResource extends ExpressoAdapter {
4
5        private function getUserProfile(){
6       
7                return array(
8                                'contactID'                     => $GLOBALS['phpgw_info']['user']['account_dn'],
9                                'contactMails'          => array($GLOBALS['phpgw_info']['user']['email']),
10                                'contactPhones'         => array($GLOBALS['phpgw_info']['user']['telephonenumber']),
11                                'contactFullName'       => $GLOBALS['phpgw_info']['user']['fullname'],
12                                'contactApps'           => $this->getUserApps()
13                );
14        }
15       
16        private function getUserApps(){
17                // Load Granted Apps for Web Service
18                $config = parse_ini_file( __DIR__ . '/../../config/user.ini',true);
19                $apps   = $config['Applications.mapping'];
20       
21                // Load Granted Apps for User
22                $contactApps = array();
23                $acl    = CreateObject('phpgwapi.acl');
24                $user_id = $GLOBALS['phpgw_info']['user']['account_id']['acl'];
25                foreach($acl->get_user_applications($user_id) as $app => $value){
26                        $enabledApp = array_search($app, $apps);
27                        if($enabledApp !== FALSE)
28                                $contactApps[] = $enabledApp;
29                }
30       
31                return $contactApps;
32        }
33       
34        public function post($request){
35                // to Receive POST Params (use $this->params)
36                parent::post($request);
37                if($sessionid = $GLOBALS['phpgw']->session->create($this->getParam('user'), $this->getParam('password')))
38                {
39                        $result = array(
40                                'auth'                  => $sessionid.":".$GLOBALS['phpgw']->session->kp3,
41                                'profile'               => array($this->getUserProfile())
42                        );
43                        $this->setResult($result);
44                }
45                else
46                {
47                        Errors::runException($GLOBALS['phpgw']->session->cd_reason);
48                }
49                return $this->getResponse();
50        }       
51
52}
Note: See TracBrowser for help on using the repository browser.