1 | <?php |
---|
2 | |
---|
3 | require_once("CommonFunctions.php"); |
---|
4 | |
---|
5 | class 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 = 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 | $description = trim($this->getParam('accountDescription')); |
---|
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 |
---|
85 | $msg = $common->validateCharacters($loginUser); |
---|
86 | |
---|
87 | if( $msg['status'] == false ) |
---|
88 | { |
---|
89 | Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] ); |
---|
90 | } |
---|
91 | |
---|
92 | // Params |
---|
93 | $fields = array(); |
---|
94 | $fields['profileUser'] = $profileUser; |
---|
95 | $fields['type'] = "create_user"; |
---|
96 | $fields['uid'] = $loginUser; |
---|
97 | $fields['mail'] = $emailUser; |
---|
98 | |
---|
99 | //Name User |
---|
100 | $nameUser = explode(" ", $nameUser); |
---|
101 | $fields['givenname'] = $nameUser[0]; |
---|
102 | if( count($nameUser) > 1 ) |
---|
103 | { |
---|
104 | unset( $nameUser[0] ); |
---|
105 | } |
---|
106 | $fields['sn'] = implode(" ", $nameUser ); |
---|
107 | $fields['password1'] = $passwordUser; |
---|
108 | $fields['password2'] = $rePasswordUser; |
---|
109 | $fields['telephonenumber'] = $common->mascaraPhone($phoneUser); |
---|
110 | $fields['cpf'] = $common->mascaraCPF($cpfUser); |
---|
111 | $fields['corporative_information_cpf'] = $common->mascaraCPF($cpfUser); |
---|
112 | $fields['corporative_information_rg'] = $rgUser; |
---|
113 | $fields['corporative_information_rguf'] = $rgUF; |
---|
114 | $fields['corporative_information_description'] = $description; |
---|
115 | |
---|
116 | // Validate Fields |
---|
117 | $msg = $this->validateFields( array("attributes" => serialize($fields)) ); |
---|
118 | |
---|
119 | if( $msg['status'] == false ) |
---|
120 | { |
---|
121 | Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] ); |
---|
122 | } |
---|
123 | |
---|
124 | // Create User |
---|
125 | unset($fields['cpf']); |
---|
126 | |
---|
127 | $msg = $this->createUser( $fields ); |
---|
128 | |
---|
129 | if( $msg['status'] == false ) |
---|
130 | { |
---|
131 | Errors::runException( "ADMIN_CREATE_USER", $msg['msg'] ); |
---|
132 | } |
---|
133 | |
---|
134 | $this->setResult( array( "result" => true ) ); |
---|
135 | } |
---|
136 | else |
---|
137 | { |
---|
138 | Errors::runException( "ACCESS_NOT_PERMITTED" ); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | return $this->getResponse(); |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | ?> |
---|