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

Revision 7878, 4.5 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Retira os caracteres especiais dentro do nome e do campo descricao

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