[7810] | 1 | <?php |
---|
| 2 | |
---|
| 3 | require_once("CommonFunctions.php"); |
---|
| 4 | |
---|
| 5 | class 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('account_uidnumber_up')); |
---|
| 28 | $loginUser = trim($this->getParam('account_login_up')); |
---|
| 29 | $emailUser = trim($this->getParam('account_email_up')); |
---|
| 30 | $nameUser = trim($this->getParam('account_name_up')); |
---|
| 31 | $passwordUser = trim($this->getParam('account_password_up')); |
---|
| 32 | $rePasswordUser = trim($this->getParam('account_re_password_up')); |
---|
| 33 | $phoneUser = trim($this->getParam('account_phone_up')); |
---|
| 34 | $cpfUser = trim($this->getParam('account_cpf_up')); |
---|
| 35 | $rgUser = trim($this->getParam('account_rg_up')); |
---|
| 36 | $rgUF = trim($this->getParam('account_rg_uf_up')); |
---|
| 37 | $description = trim($this->getParam('account_description_up')); |
---|
| 38 | |
---|
| 39 | // Field Validation |
---|
| 40 | if( trim($uidNumber) == "" && isset($uidNumber) ) |
---|
| 41 | Errors::runException( "ADMIN_UIDNUMBER_EMPTY" ); |
---|
| 42 | |
---|
| 43 | if( trim($loginUser) == "" && isset($loginUser) ) |
---|
| 44 | Errors::runException( "ADMIN_LOGIN_EMPTY" ); |
---|
| 45 | |
---|
| 46 | // If rgUser and rgUF |
---|
| 47 | if( (trim($rgUser) != "" && trim($rgUF) == "" ) || ( trim($rgUser) == "" && trim($rgUF) != "" ) ) |
---|
| 48 | { |
---|
| 49 | Errors::runException("ADMIN_RG_UF_EMPTY"); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | // If not empty |
---|
| 53 | if( trim($passwordUser) != "" && trim($rePasswordUser) != "" ) |
---|
| 54 | { |
---|
| 55 | if( isset($passwordUser) && isset($rePasswordUser) ) |
---|
| 56 | { |
---|
| 57 | // password and repassword are different ? |
---|
| 58 | if( trim($passwordUser) != trim($rePasswordUser) ) |
---|
| 59 | { |
---|
| 60 | Errors::runException( "ADMIN_PASSWORD_REPASSWORD" ); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | // validate password, 8 characteres minimum and 2 numbers |
---|
| 64 | $msg = $common->validatePassword($passwordUser); |
---|
| 65 | |
---|
| 66 | if( $msg['status'] == false ) |
---|
| 67 | { |
---|
| 68 | Errors::runException( "ADMIN_MINIMUM_CHARACTERS", $msg['msg']); |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | // CPF is invalid |
---|
| 74 | if( trim($cpfUser) != "" && !$common->validateCPF($cpfUser) ) |
---|
| 75 | { |
---|
| 76 | Errors::runException( "ADMIN_CPF_INVALID" ); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | // Characters not permited login |
---|
| 80 | $msg = $common->validateCharacters($loginUser); |
---|
| 81 | |
---|
| 82 | if( $msg['status'] == false ) |
---|
| 83 | { |
---|
| 84 | Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] ); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | // Params - Validade / Update Fields |
---|
| 88 | $fields = array(); |
---|
| 89 | $fields['type'] = "edit_user"; |
---|
| 90 | $fields['uid'] = $loginUser; |
---|
| 91 | $fields['uidnumber'] = $uidNumber; |
---|
| 92 | $fields['mail'] = $emailUser; |
---|
| 93 | $fields['cpf'] = $common->mascaraCPF($cpfUser); |
---|
| 94 | |
---|
| 95 | // Validate Fields |
---|
| 96 | $msg = $this->validateFields( array("attributes" => serialize($fields)) ); |
---|
| 97 | |
---|
| 98 | if( $msg['status'] == false ) |
---|
| 99 | { |
---|
| 100 | Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] ); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | //Name User |
---|
| 104 | $nameUser = explode(" ", $nameUser); |
---|
| 105 | |
---|
| 106 | $fields['givenname'] = $nameUser[0]; |
---|
| 107 | |
---|
| 108 | if( count($nameUser) > 1 ) |
---|
| 109 | { |
---|
| 110 | unset( $nameUser[0] ); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | if( trim($passwordUser) != "" ) |
---|
| 114 | { |
---|
| 115 | $fields['password1'] = $passwordUser; |
---|
| 116 | $fields['password2'] = $rePasswordUser; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | $fields['sn'] = implode(" ", $nameUser ); |
---|
| 120 | $fields['telephonenumber'] = $common->mascaraPhone($phoneUser); |
---|
| 121 | $fields['corporative_information_cpf'] = $common->mascaraCPF($cpfUser); |
---|
| 122 | $fields['corporative_information_rg'] = $rgUser; |
---|
| 123 | $fields['corporative_information_rguf'] = $rgUF; |
---|
| 124 | $fields['corporative_information_description'] = $description; |
---|
| 125 | |
---|
| 126 | // Update Fields |
---|
| 127 | unset($fields['cpf']); |
---|
| 128 | |
---|
| 129 | $msg = $this->updateUser($fields); |
---|
| 130 | |
---|
| 131 | if( $msg['status'] == false ) |
---|
| 132 | { |
---|
| 133 | Errors::runException( "ADMIN_UPDATE_USER", $msg['msg'] ); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | $this->setResult( array( "result" => true ) ); |
---|
| 137 | } |
---|
| 138 | else |
---|
| 139 | { |
---|
| 140 | Errors::runException( "ACCESS_NOT_PERMITTED" ); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | return $this->getResponse(); |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | ?> |
---|