+
+ // 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']);
+
+ // Check both challenge + response
+ assert(isset($rows[0]['api_redirect_challenge']));
+ assert(isset($rows[0]['api_challenge_response']));
+
+ // Both are fine, so get the data
+ $return = doWernisFinishUserRegistration($rows[0]['api_redirect_challenge'], $rows[0]['api_challenge_response'], '1');
+
+ // All fine?
+ if ($return === FALSE) {
+ // @TODO Should not happen???
+ reportBug(__FUNCTION__, __LINE__, 'args=<pre>' . print_r($args, TRUE) . '</pre>rows=<pre>' . print_r($rows, TRUE) . '</pre> - Failed!');
+ } // END - if
+
+ // Generate URL
+ $url = basename(detectRequestUri()) . '&challenge=' . $rows[0]['api_redirect_challenge'] . '&__challenge_response=' . $rows[0]['api_challenge_response'] . '&status=1';
+
+ // Redirect to URL
+ redirectToUrl($url);
+}
+
+//------------------------------------------------------------------------------
+// Template helper functions
+//------------------------------------------------------------------------------
+
+// Template helper to generate a selection box for encryption alogrithms
+function doTemplateSelectWernisEncryptionAlgorithm ($templateName, $clear = FALSE, $default = NULL) {
+ // Get all available algorithms
+ $algorithms = getSupportedEncryptionAlgorithms();
+ //* DEBUG-DIE */ die('algorithms=<pre>' . print_r($algorithms, TRUE) . '</pre>');
+
+ // Init array
+ $options = [];
+
+ // And fill it
+ foreach ($algorithms as $key => $dummy) {
+ $options[$key] = array('algorithms' => $key);
+ } // END - if
+
+ // Handle it over to generateSelectionBoxFromArray()
+ $content = generateSelectionBoxFromArray($options, 'wernis_encryption_algorithm', 'algorithms', '', '_wernis', '', $default, '', TRUE, FALSE);
+
+ // Return prepared content
+ return $content;
+}
+
+// Template helper to generate a selection box for encryption alogrithms
+function doTemplateSelectWernisEncryptionMode ($templateName, $clear = FALSE, $default = NULL) {
+ // Get all available modes
+ $modes = getSupportedEncryptionModes();
+
+ // Init array
+ $options = [];
+
+ // And fill it
+ foreach ($modes as $key => $dummy) {
+ $options[$key] = array('modes' => $key);
+ } // END - if
+
+ // Handle it over to generateSelectionBoxFromArray()
+ $content = generateSelectionBoxFromArray($options, 'wernis_encryption_mode', 'modes', '', '_wernis', '', $default, '', TRUE, FALSE);
+
+ // Return prepared content
+ return $content;