source: sandbox/webservice/api/rest/admin/CreateUserResource.php @ 7931

Revision 7931, 4.9 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Adicionado o cadastro dos seguintes campos datanascimento,st,city e sexo no ldap

  • Property svn:executable set to *
Line 
1<?php
2
3require_once("CommonFunctions.php");
4
5class CreateUserResource 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'] = 'add_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                                $loginUser              = trim($this->getParam('accountLogin'));
28                                $emailUser              = trim($this->getParam('accountEmail'));
29                                $nameUser               = $common->convertChar(trim($this->getParam('accountName')));
30                                $profileUser    = trim($this->getParam('accountProfile'));
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                                $birthDate              = $common->mascaraBirthDate($this->getParam('accountBirthDate'));
38                                $st                     = $this->getParam('accountSt');
39                                $city                   = $this->getParam('accountCity');
40                                $sex                    = $this->getParam('accountSex');
41                                $description    = $common->convertChar(trim($this->getParam('accountDescription')));
42
43                                // Field Validation
44                                if( trim($loginUser) == "" && isset($loginUser) )       
45                                        Errors::runException( "ADMIN_LOGIN_EMPTY" );
46
47                                if( trim($nameUser) == "" && isset($nameUser) )
48                                        Errors::runException( "ADMIN_NAME_EMPTY" );
49
50                                if( trim($profileUser) == "" && isset($profileUser) )
51                                        Errors::runException( "ADMIN_PROFILE_USER_EMPTY" );
52                               
53                                if( trim($emailUser) == "" && isset($emailUser) )
54                                        Errors::runException( "ADMIN_EMAIL_EMPTY" );
55
56                                if( trim($passwordUser) == "" && isset($passwordUser) )
57                                        Errors::runException( "ADMIN_PASSWORD_EMPTY" );
58
59                                if( trim($rePasswordUser) == "" && isset($rePasswordUser) )
60                                        Errors::runException( "ADMIN_RE_PASSWORD_EMPTY" );
61                       
62                                //If rgUser and rgUF
63                                if((trim($rgUser) != "" && trim($rgUF) == "" ) || ( trim($rgUser) == "" && trim($rgUF) != "" ))
64                                {
65                                        Errors::runException("ADMIN_RG_UF_EMPTY");
66                                }
67
68                                // password and repassword are different ?                             
69                                if( trim($passwordUser) != trim($rePasswordUser) )
70                                {
71                                        Errors::runException( "ADMIN_PASSWORD_REPASSWORD" );
72                                }
73                               
74                                // validate password, 8 characteres minimum and 2 numbers
75                                $msg = $common->validatePassword($passwordUser);
76
77                                if( $msg['status'] == false )
78                                {
79                                        Errors::runException( "ADMIN_MINIMUM_CHARACTERS", $msg['msg']);
80                                }
81
82                                // CPF is invalid
83                                if( trim($cpfUser) != "" && !$common->validateCPF($cpfUser) )
84                                {
85                                        Errors::runException( "ADMIN_CPF_INVALID" );
86                                }
87
88                                // Characters not permited login
89                                $msg = $common->validateCharacters( $loginUser, "accountLogin" );
90
91                                if( $msg['status'] == false )
92                                {
93                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountLogin" );
94                                }
95                               
96                                //Characters not permited name
97                                $msg = $common->validateCharacters($nameUser);
98
99                                if( $msg['status'] == false )
100                                {
101                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountName" );
102                                }
103
104                                // Params
105                                $fields = array();
106                                $fields['profileUser']  = $profileUser;
107                                $fields['type']                 = "create_user";
108                                $fields['uid']                  = $loginUser;
109                                $fields['mail']                 = $emailUser;
110
111                                //Name User
112                                $nameUser = explode(" ", $nameUser);
113                                $fields['givenname'] = $nameUser[0];
114                                if( count($nameUser) > 1 )
115                                {
116                                        unset( $nameUser[0] );
117                                }
118                                $fields['sn'] = implode(" ", $nameUser );       
119                                $fields['password1'] = $passwordUser;
120                                $fields['password2'] = $rePasswordUser;
121                                $fields['telephonenumber'] = $common->mascaraPhone($phoneUser);
122                                $fields['cpf'] = $common->mascaraCPF($cpfUser);
123                                $fields['corporative_information_cpf']  = $common->mascaraCPF($cpfUser);
124                                $fields['corporative_information_rg']   = $rgUser;
125                                $fields['corporative_information_rguf'] = $rgUF;
126                                $fields['corporative_information_description'] = $description;
127                                $fields['corporative_information_datanascimento'] = $birthDate;
128                                $fields['corporative_information_st']   = $st;
129                                $fields['corporative_information_city'] = $city;
130                                $fields['corporative_information_sexo'] = $sex;
131
132                                // Validate Fields
133                                $msg = $this->validateFields( array("attributes" => serialize($fields)) );
134
135                                if( $msg['status'] == false )
136                                {
137                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
138                                }
139
140                                // Create User
141                                unset($fields['cpf']);
142
143                                $msg = $this->createUser( $fields );
144
145                                if( $msg['status'] == false )
146                                {
147                                        Errors::runException( "ADMIN_CREATE_USER", $msg['msg'] );
148                                }
149
150                                $this->setResult( array( "createUser" => true ) );
151                        }
152                        else
153                        {
154                                Errors::runException( "ACCESS_NOT_PERMITTED" );
155                        }
156                }
157               
158                return $this->getResponse();
159        }
160}
161
162?>
Note: See TracBrowser for help on using the repository browser.