* $Author:: $ *
* -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009 - 2015 by Mailer Developer Team *
+ * Copyright (c) 2009 - 2016 by Mailer Developer Team *
* For more information visit: http://mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
}
// Sends out a request to the API and returns it's result
-function sendWernisApiRequest ($scriptName, $requestData = array()) {
+function sendWernisApiRequest ($scriptName, $requestData = []) {
// Debug call
//* DEBUG */ reportBug(__FUNCTION__, __LINE__, 'scriptName=' . $scriptName . ',requestData=<pre>' . print_r($requestData, TRUE) . '</pre>');
// Get the raw response from the lower function
$response = sendHttpPostRequest($requestString, $requestData);
+ // Debug message
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf('isDeveloperSystem()=%d', intval(isDeveloperSystem())));
+
+ // Log response only for development
+ if (isDeveloperSystem()) {
+ // Log whole message
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf('response[%s]=%s', gettype($response), print_r($response, TRUE)));
+ } // END - if
+
// Check the response header if all is fine
if (!isHttpStatusOkay($response[0])) {
// Something bad happend... :(
$data = explode('=', $responseLine);
// Default return array (should not stay empty)
- $return = array();
+ $return = [];
// We use only the first two entries (which shall be fine)
if ($data[0] === 'error') {
// Status was okay?
if (isHttpResponseStatusOkay($args)) {
- // Is status set?
+ // Is auth_status set?
//* DEBUG-DIE */ die('response=<pre>' . print_r($response, TRUE) . '</pre>,args=' . '<pre>'.print_r($args, TRUE).'</pre>');
assert(isset($args['auth_status']));
$return['mapped_data'] = runFilterChain('register_must_fillout', $return['mapped_data']);
// Add missing elements
- $return['mapped_data']['gender'] = NULL;
+ $return['mapped_data']['sex'] = NULL;
$return['mapped_data']['birthday_selection'] = generateDayMonthYearSelectionBox($return['mapped_data']['birth_day'], $return['mapped_data']['birth_month'], $return['mapped_data']['birth_year']);
$return['mapped_data']['challenge'] = getRequestElement('challenge');
$return['mapped_data']['__challenge_response'] = getRequestElement('__challenge_response');
// Display form
loadTemplate('guest_wernis_registration_rpc_form');
- return array();
+ return [];
} // END - if
// Init array
$return = array(
// Mapped data
- 'mapped_data' => array(),
+ 'mapped_data' => [],
// Any error message from API
'message' => ''
);
reportBug(__FUNCTION__, __LINE__, 'Cannot map from=' . $from . ' -> to=' . $to . ': element does not exist.');
} // END - if
- // "Map" all
+ // "Map" all and make empty strings to NULL
$return['mapped_data'][$to] = convertEmptyToNull($userData[$from]);
} // END - foreach
// "Getter" for Wernis registration data by given key and value
function getWernisRegistrationDataByKey ($key, $value, $limit = 1) {
// Init array
- $rows = array();
+ $rows = [];
// Now search for it
$result = sqlQueryEscaped("SELECT
WHERE
`%s`='%s'
ORDER BY
- `id`
+ `id` ASC
LIMIT %d",
array(
$key,
return $key;
}
-//-----------------------------------------------------------------------------
-// Auth status callback functions
-//-----------------------------------------------------------------------------
-
-// Handler for auth_status=PENDING
-function doWernisAuthPending ($args) {
- // $args must always be an array
+// Registers or updates Wernis registration data
+function registerUpdateWernisRegistrationCall ($args, $challenge, $status) {
+ // Make sure the required array elements are there
assert(is_array($args));
-
- // auth_key and wernis_userid must be set
assert(isset($args['auth_key']));
assert(isset($args['wernis_userid']));
- // Generate a challenge that will be added to the URL
- $challenge = hashSha256(generatePassword(128));
-
// Search entry in database by auth_key
if (countSumTotalData($args['auth_key'], 'wernis_regs', 'id', 'api_auth_key', TRUE) == 0) {
// "Register" this call
`api_redirect_challenge`
) VALUES (
%s,
- 'PENDING',
+ '%s',
'%s',
'%s'
)",
array(
bigintval($args['wernis_userid']),
+ $status,
$args['auth_key'],
$challenge
), __FUNCTION__, __LINE__
sqlQueryEscaped("UPDATE
`{?_MYSQL_PREFIX?}_wernis_regs`
SET
- `api_redirect_challenge`='%s'
+ `api_redirect_challenge`='%s',
+ `api_auth_status`='%s'
WHERE
`api_auth_key`='%s' AND
- `wernis_userid`=%s AND
- `api_auth_status`='PENDING'
+ `wernis_userid`=%s
LIMIT 1",
array(
$challenge,
+ $status,
$args['auth_key'],
bigintval($args['wernis_userid'])
), __FUNCTION__, __LINE__
);
}
- // Should always update/insert
- assert(sqlAffectedRows() == 1);
+ // Return whether something has been inserted or updated
+ return (sqlAffectedRows() == 1);
+}
+
+//-----------------------------------------------------------------------------
+// Auth status callback functions
+//-----------------------------------------------------------------------------
+
+// Handler for auth_status=PENDING
+function doWernisAuthPending ($args) {
+ // $args must always be an array
+ assert(is_array($args));
+
+ // auth_key and wernis_userid must be set
+ assert(isset($args['auth_key']));
+ assert(isset($args['wernis_userid']));
+
+ // Generate a challenge that will be added to the URL
+ $challenge = hashSha256(generatePassword(128));
+
+ // Register or update the record
+ $registered = registerUpdateWernisRegistrationCall($args, $challenge, 'PENDING');
+
+ // Should always register/update
+ assert($registered === TRUE);
// Redirect to WDS66 module=auth ...
//* DEBUG-DIE */ die(__FUNCTION__ . ':' . __LINE__ . '<pre>' . print_r($args, TRUE) . '</pre>');
// Get registration data by auth_key
$rows = getWernisRegistrationDataByKey('api_auth_key', $args['auth_key']);
+ // Is developer system?
+ if (isDeveloperSystem()) {
+ // Log whole rows array
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf('args[%s]=%s,rows[%s]=%s', gettype($args), print_r($args, TRUE), gettype($rows), print_r($rows, TRUE)));
+ } // END - if
+
+ // Is rows empty?
+ if (count($rows) == 0) {
+ // Generate challenge
+ $challenge = hashSha256(generatePassword(128));
+
+ // Then register it ...
+ $registered = registerUpdateWernisRegistrationCall($args, $challenge, $args['auth_status']);
+
+ // Should always register/update
+ assert($registered === TRUE);
+
+ // ... and redirect to module=auth
+ redirectToUrl(getWernisBaseUrl() . '/modules.php?module=auth&auth_key=' . trim($args['auth_key']) . '&params=' . urlencode(base64_encode('&module=' . getModule() . '&what=' . getWhat())) . '&challenge=' . $challenge, FALSE, FALSE);
+ } // END - if
+
// The userid should be same
assert(isset($rows[0]['wernis_userid']));
assert($rows[0]['wernis_userid'] === $args['wernis_userid']);
//* DEBUG-DIE */ die('algorithms=<pre>' . print_r($algorithms, TRUE) . '</pre>');
// Init array
- $options = array();
+ $options = [];
// And fill it
foreach ($algorithms as $key => $dummy) {
$modes = getSupportedEncryptionModes();
// Init array
- $options = array();
+ $options = [];
// And fill it
foreach ($modes as $key => $dummy) {