source: sandbox/webservice/api/rest/admin/UpdateUserResource.php @ 7882

Revision 7882, 4.7 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Implementado a alteração da quota do usuário

  • Property svn:executable set to *
Line 
1<?php
2
3require_once("CommonFunctions.php");
4
5class UpdateUserResource extends AdminAdapter
6{
7        public function post($request)
8        {
9                // to Receive POST Params (use $this->params)
10                parent::post($request);
11
12                if( $this->isLoggedIn() )
13                {
14                        // Permission
15                        $permission = array();
16                        $permission['action'] = 'edit_users';
17                        $permission['apps'] = $this->getUserApps();
18
19                        //Load Conf Admin
20                        $this->loadConfAdmin();
21
22                        if( $this->validatePermission($permission) )   
23                        {       
24                                //Class CommonFunctions
25                                $common = new CommonFunctions();
26
27                                $uidNumber              = trim($this->getParam('accountUidNumber'));
28                                $loginUser              = trim($this->getParam('accountLogin'));
29                                $emailUser              = trim($this->getParam('accountEmail'));
30                                $nameUser               = $common->convertChar(trim($this->getParam('accountName')));
31                                $passwordUser   = trim($this->getParam('accountPassword'));
32                                $rePasswordUser = trim($this->getParam('accountRePassword'));
33                                $phoneUser              = trim($this->getParam('accountPhone'));
34                                $cpfUser                = trim($this->getParam('accountCpf'));
35                                $rgUser                 = trim($this->getParam('accountRg'));
36                                $rgUF                   = trim($this->getParam('accountRgUf'));
37                                $description    = $common->convertChar(trim($this->getParam('accountDescription')));
38                                $mailQuota              = trim($this->getParam('accountMailQuota'));
39
40                                // Field Validation
41                                if( trim($uidNumber) == "" && isset($uidNumber) )
42                                        Errors::runException( "ADMIN_UIDNUMBER_EMPTY" );
43                               
44                                if( trim($loginUser) == "" && isset($loginUser) )       
45                                        Errors::runException( "ADMIN_LOGIN_EMPTY" );
46
47                                // If rgUser and rgUF
48                                if( (trim($rgUser) != "" && trim($rgUF) == "" ) || ( trim($rgUser) == "" && trim($rgUF) != "" ) )
49                                {
50                                        Errors::runException("ADMIN_RG_UF_EMPTY");
51                                }
52
53                                // If not empty
54                                if( trim($passwordUser) != "" && trim($rePasswordUser) != "" )
55                                {       
56                                        if( isset($passwordUser) && isset($rePasswordUser) )
57                                        {
58                                                // password and repassword are different ?                             
59                                                if( trim($passwordUser) != trim($rePasswordUser) )
60                                                {
61                                                        Errors::runException( "ADMIN_PASSWORD_REPASSWORD" );
62                                                }
63                                       
64                                                // validate password, 8 characteres minimum and 2 numbers
65                                                $msg = $common->validatePassword($passwordUser);
66
67                                                if( $msg['status'] == false )
68                                                {
69                                                        Errors::runException( "ADMIN_MINIMUM_CHARACTERS", $msg['msg']);
70                                                }
71                                        }
72                                }
73
74                                // CPF is invalid
75                                if( trim($cpfUser) != "" && !$common->validateCPF($cpfUser) )
76                                {
77                                        Errors::runException( "ADMIN_CPF_INVALID" );
78                                }
79
80                                // Characters not permited login
81                                $msg = $common->validateCharacters($loginUser, "accountLogin");
82
83                                if( $msg['status'] == false )
84                                {
85                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountLogin" );
86                                }
87
88                                //Characters not permited name
89                                $msg = $common->validateCharacters($nameUser);
90
91                                if( $msg['status'] == false )
92                                {
93                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountName" );
94                                }
95
96                                //Characters not permited mailQuota
97                                $msg = $common->validateCharacters($mailQuota, "accountMailQuota");
98
99                                if( $msg['status'] == false )
100                                {
101                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountMailQuota" );
102                                }
103
104                                // Params - Validade / Update Fields
105                                $fields = array();
106                                $fields['type']                 = "edit_user";
107                                $fields['uid']                  = $loginUser;
108                                $fields['uidnumber']    = $uidNumber;
109                                $fields['mail']                 = $emailUser;
110                                $fields['cpf']                  = $common->mascaraCPF($cpfUser);
111
112                                // Validate Fields
113                                $msg = $this->validateFields( array("attributes" => serialize($fields)) );
114
115                                if( $msg['status'] == false )
116                                {
117                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
118                                }
119
120                                //Name User
121                                $nameUser = explode(" ", $nameUser);
122                               
123                                $fields['givenname'] = $nameUser[0];
124                               
125                                if( count($nameUser) > 1 )
126                                {
127                                        unset( $nameUser[0] );
128                                }
129
130                                if( trim($passwordUser) != "" )
131                                {
132                                        $fields['password1'] = $passwordUser;
133                                        $fields['password2'] = $rePasswordUser;
134                                }
135
136                                $fields['sn']                                                           = implode(" ", $nameUser );     
137                                $fields['telephonenumber']                                      = $common->mascaraPhone($phoneUser);
138                                $fields['corporative_information_cpf']          = $common->mascaraCPF($cpfUser);
139                                $fields['corporative_information_rg']           = $rgUser;
140                                $fields['corporative_information_rguf']         = $rgUF;
141                                $fields['corporative_information_description'] = $description;
142                                $fields['mailquota']                                            = $mailQuota;
143
144                                // Update Fields
145                                unset($fields['cpf']);
146
147                                $msg = $this->updateUser($fields);
148
149                                if( $msg['status'] == false )
150                                {
151                                        Errors::runException( "ADMIN_UPDATE_USER", $msg['msg'] );
152                                }
153
154                                $this->setResult( array( "result" => true ) );
155                        }
156                        else
157                        {
158                                Errors::runException( "ACCESS_NOT_PERMITTED" );
159                        }                       
160                }
161
162                return $this->getResponse();   
163        }       
164}
165
166?>
Note: See TracBrowser for help on using the repository browser.