source: sandbox/webservice/api/rest/admin/GetUsersResource.php @ 7866

Revision 7866, 2.5 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Padronização dos resources REST do Expresso

Line 
1<?php
2
3class GetUsersResource extends AdminAdapter
4{
5
6        public function post($request)
7        {
8                // to Receive POST Params (use $this->params)
9                parent::post($request);
10
11                if( $this->isLoggedIn() )
12                {
13                        // Permission
14                        $permission = array();
15                        $permission['apps'] = $this->getUserApps();
16
17                        //Load Conf Admin
18                        $this->loadConfAdmin();
19
20                        $uidUser        = $this->getParam('accountUidNumber');
21                        $searchUser = $this->getParam('accountSearchUser');
22
23                        //Validate Fields
24                        $uidUser = str_replace("*","",$uidUser);
25                        $uidUser = str_replace("%","",$uidUser);
26
27                        $searchUser = str_replace("*","", $searchUser);
28                        $searchUser = str_replace("%","", $searchUser);
29
30                        if( trim($uidUser) != "" && isset($uidUser) )
31                        {
32                                $permission['action'] = 'edit_users';
33
34                                if( $this->validatePermission($permission) )
35                                {
36                                        // Get User
37                                        $fields = $this->editUser($uidUser);
38
39                                        if( $fields != false )
40                                        {       
41                                                // Return fields
42                                                $return = array();
43                                                $return['accountUidnumber']             = $fields['uidnumber'];
44                                                $return['accountLogin']                 = $fields['uid'];
45                                                $return['accountEmail']                 = $fields['mail'];
46                                                $return['accountName']                  = $fields['givenname']." ".$fields['sn'];
47                                                $return['accountPhone']                 = $fields['telephonenumber'];   
48                                                $return['accountCpf']                   = $fields['corporative_information_cpf'];
49                                                $return['accountRg']                    = $fields['corporative_information_rg'];
50                                                $return['accountRgUf']                  = $fields['corporative_information_rguf'];
51                                                $return['accountDescription']   = $fields['corporative_information_description'];
52                                               
53                                                $this->setResult( array( "users" => $return ));
54                                        }
55                                        else
56                                                Errors::runException( "ADMIN_USER_NOT_FOUND" );                                 
57                                }
58                                else
59                                {
60                                        Errors::runException( "ACCESS_NOT_PERMITTED" );
61                                }                       
62                        }
63                        else
64                        {
65                                $permission['action'] = 'list_users';
66
67                                if( $this->validatePermission($permission) )
68                                {
69                                        $list = $this->listUsers( $searchUser );
70                                       
71                                        // Return list
72                                        $return = array();
73
74                                        foreach( $list as $key => $users )
75                                        {
76                                                $return[$key]['accountId']              = $users['account_id'];
77                                                $return[$key]['accountLid']             = $users['account_lid'];
78                                                $return[$key]['accountCn']              = $users['account_cn'];
79                                                $return[$key]['accountMail']    = $users['account_mail'];
80                                        }
81
82                                        if( count($list) > 0 )
83                                        {
84                                                $this->setResult( array( "users" => $return ) );
85                                        }
86                                        else
87                                        {
88                                                Errors::runException( "ADMIN_USERS_NOT_FOUND" );               
89                                        }
90                                }
91                                else
92                                {
93                                        Errors::runException( "ACCESS_NOT_PERMITTED" );
94                                }                       
95                        }
96                }       
97
98                return $this->getResponse();
99        }               
100}
101
102?>
Note: See TracBrowser for help on using the repository browser.