public function updateUser() { $user = false; $updateError = null; if ($this->passwordOld !== $this->passwordNew) { $webserviceUrl = String::prepare('%svisualization/wo/user', WEBSERVICE_URL); $webserviceParams = array('user' => WEBSERVICE_USER, 'password' => WEBSERVICE_PASSWORD, 'userName' => $this->user['UserName'], 'userKey' => $this->user['ApiKey'], 'userPasswordOld' => $this->passwordOld, 'userPasswordNew' => $this->passwordNew, 'userPasswordConfirm' => $this->passwordConfirm, 'format' => 'application/json'); $requestContents = Connectivity::runCurl($webserviceUrl, array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => http_build_query($webserviceParams))); if ($requestContents) { $jsonOutput = json_decode($requestContents, true); if (isset($jsonOutput['response']['user']) && $jsonOutput['response']['user']) { $userOutput = $jsonOutput['response']['user']; if ($userOutput['user'] && !$userOutput['error']) { $user = $userOutput['user']; } else { $updateError = is_array($userOutput['error']) ? implode('<br>', Collection::flatten($userOutput['error'])) : $userOutput['error']; } } } if ($user) { $saltSize = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB); $salt = base64_encode(mcrypt_create_iv($saltSize, MCRYPT_RAND)); $this->vizDb->update(self::DB_CONNECTION_VIZ_WRITE, 'VisualizationUser', array('Password' => hash('sha256', $salt . $this->passwordNew), 'PasswordSalt' => $salt), 'Name=?', array($this->user['UserName'])); Session::setData(REQUEST_PARAMETER_USER_NAME, $user); } elseif (empty($updateError)) { $updateError = __('An unknown error occured while updating'); } } else { $updateError = __('The new password can not be equal to the old password'); } // Return the user update result return array(REQUEST_RESULT => $user ? true : false, REQUEST_ERROR => $updateError); }
/** * Execute an insert statement. * * @param string $connectionName Name of the connection to use * @param string $table Name of the table to call * @param array $params Input parameters * @param int $rowCount Number of rows to insert (optional) * @return boolean True on success, false otherwise */ public function insert($connectionName, $table, $params, $rowCount = 1) { // Make sure the statement parameters are in array form if (empty($params) || !is_array($params)) { $this->error('Invalid insert parameters found, expecting an array of key-value pairs'); } // Prepare the value string $query = ''; // Determine whether we are inserting multiple rows if ($rowCount > 1) { // In case of an invalid parameter count, throw an exception if ($rowCount !== count($params)) { $this->error('Invalid insert row count'); } // Prepare the values clause foreach ($params as $fieldParams) { $fields = implode(',', array_keys($fieldParams)); $valueString = $this->prepareWhereIn($fieldParams); // Prepare the query string $query .= "INSERT INTO {$table} ({$fields}) VALUES ({$valueString});"; } // Flatten the parameter array $params = Collection::flatten($params); } else { $fields = implode(',', array_keys($params)); // We are inserting a single row $valueString = $this->prepareWhereIn($params); // Prepare the query string $query = "INSERT INTO {$table} ({$fields}) VALUES ({$valueString})"; } // Execute the statement and return its results return $this->execute($connectionName, $query, array_values($params)); }