]> git.mxchange.org Git - mailer.git/commitdiff
Introduced getWernisMapedDataFromApiByChallenge()
authorRoland Haeder <roland@mxchange.org>
Tue, 8 Apr 2014 18:47:07 +0000 (20:47 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 8 Apr 2014 18:47:07 +0000 (20:47 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/libs/wernis_functions.php
templates/de/html/guest/guest_wernis_registration_form.tpl [deleted file]
templates/de/html/guest/guest_wernis_registration_rpc_form.tpl [new file with mode: 0644]

index 67d20182b2d45c1b70c71ca3d875e5f4de9af805..90e88a01e7ffe298f3c3067112999490019b6e3a 100644 (file)
@@ -523,12 +523,38 @@ function doDisplayWernisUserRegistrationForm () {
                } // END - if
        } elseif (!isFormSent('register')) {
                // Form not send, so load form template
-               loadTemplate('guest_wernis_registration_form');
+               loadTemplate('guest_wernis_registration_rpc_form');
        }
 }
 
 // Finish user registration with WDS66 API
 function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status) {
+       // Check status from GET parameters and stored value
+       if (($status == '1') && (isFormSent('wernis_register'))) {
+               // Form has been sent
+               die(__FUNCTION__ . ':' . __LINE__ . ': Reached!');
+       } elseif ($status == '1') {
+               // Get mapped data based on challenge
+               $return = getWernisMapedDataFromApiByChallenge($challenge, $status);
+
+               // Is the array filled?
+               if ((count($return['mapped_data']) > 0) && (empty($return['message']))) {
+                       // Display form
+                       loadTemplate('guest_wernis_registration_form', FALSE, $return['mapped_data']);
+                       return TRUE;
+               } else {
+                       // Something bad happened
+                       displayMessage($return['message']);
+                       return FALSE;
+               }
+       } else {
+               // Status does not need to be changed
+               die(__FUNCTION__ . ':' . __LINE__ . ': Reached!');
+       }
+}
+
+// "Getter" for mapped data by calling the API and given challenge and status
+function getWernisMapedDataFromApiByChallenge ($challenge, $status) {
        // Get stored registration data
        $rows = getWernisRegistrationDataByKey('api_redirect_challenge', $challenge);
 
@@ -538,93 +564,92 @@ function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status
                displayMessage('{--GUEST_WERNIS_REGISTRATION_ZERO_ROWS_FOUND--}');
 
                // Display form
-               loadTemplate('guest_wernis_registration_form');
-               return FALSE;
+               loadTemplate('guest_wernis_registration_rpc_form');
+               return array();
        } // END - if
 
-       // Check status from GET parameters and stored value
-       if ($status == '1') {
-               // Has the auth status changed?
-               if ($rows[0]['api_auth_status'] != 'ACCEPTED') {
-                       /*
-                        * The authorization of this application has been accepted, so
-                        * update it and ignore result from function because the update
-                        * will always run.
-                        */
-                       updateWernisRegistrationDataByKey('api_auth_status', 'api_redirect_challenge', $challenge, 'ACCEPTED');
-               } // END - if
+       // Init array
+       $return = array(
+               // Mapped data
+               'mapped_data' => array(),
+               // Any error message from API
+               'message'     => ''
+       );
 
-               // Now call "get.php"
-               $response = executeWernisApiGet($rows[0], 'data', 'anrede|vorname|name|strasse|plz|ort|birth_day|birth_month|birth_year|email|werber');
-
-               // Was the status okay?
-               if (isHttpResponseStatusOkay($response)) {
-                       // API returned non-errous response, 'data=' must be found
-                       assert(substr($response['response'], 0, 5) == 'data=');
-
-                       // And remove it, this is now BASE64-encoded
-                       $encodedData = urldecode(substr($response['response'], 5));
-
-                       // And decode it (all steps separated to later "easily" debug them)
-                       $decodedData = base64_decode($encodedData);
-
-                       /*
-                        * Do some checks on the decoded string, it should be a
-                        * serialized array with 11 entries (see above
-                        * executeWernisApiGet() call).
-                        */
-                       assert(substr($decodedData, 0, 6) == 'a:11:{');
-                       assert(substr($decodedData, -1, 1) == '}');
-
-                       // The array seems to be fine, unserialize it
-                       $userData = unserialize($decodedData);
-
-                       // All mappings WDS66->mailer
-                       $mappings = array(
-                               'anrede'      => 'gender',
-                               'vorname'     => 'surname',
-                               'name'        => 'family',
-                               'strasse'     => 'street_nr',
-                               'plz'         => 'zip',
-                               'ort'         => 'city',
-                               'email'       => 'email',
-                               'birth_day'   => 'birth_day',
-                               'birth_month' => 'birth_month',
-                               'birth_year'  => 'birth_year',
-                               'werber'      => 'wernis_refid'
-                       );
-
-                       // Array for mapped data
-                       $mappedData = array();
-
-                       // Map all WDS66 entries into mailer entries
-                       foreach ($mappings as $from => $to) {
-                               // All must exist
-                               if (!isset($userData[$from])) {
-                                       // Element $from does not exist
-                                       reportBug(__FUNCTION__, __LINE__, 'Cannot map from=' . $from . ' -> to=' . $to . ': element does not exist.');
-                               } // END - if
+       // Has the auth status changed?
+       if ($rows[0]['api_auth_status'] != 'ACCEPTED') {
+               /*
+                * The authorization of this application has been accepted, so
+                * update it and ignore result from function because the update
+                * will always run.
+                */
+               updateWernisRegistrationDataByKey('api_auth_status', 'api_redirect_challenge', $challenge, 'ACCEPTED');
+       } // END - if
 
-                               // "Map" all
-                               $mappedData[$to] = convertEmptyToNull($userData[$from]);
-                       } // END - foreach
+       // Now call "get.php"
+       $response = executeWernisApiGet($rows[0], 'data', 'anrede|vorname|name|strasse|plz|ort|birth_day|birth_month|birth_year|email|werber');
 
-                       // Both arrays must have same size
-                       assert(count($userData) == count($mappedData));
+       // Was the status okay?
+       if (isHttpResponseStatusOkay($response)) {
+               // API returned non-errous response, 'data=' must be found
+               assert(substr($response['response'], 0, 5) == 'data=');
 
-                       // Now add userid and registration provider from WDS66
-                       $mappedData['wernis_userid']         = bigintval($rows[0]['wernis_userid']);
-                       $mappedData['registration_provider'] = 'wernis';
+               // And remove it, this is now BASE64-encoded
+               $encodedData = urldecode(substr($response['response'], 5));
 
-                       die(__FUNCTION__ . '<pre>'.print_r($mappedData, TRUE).'</pre>');
-               } else {
-                       // Something bad happened
-                       displayMessage($response['message']);
-                       return FALSE;
-               }
+               // And decode it (all steps separated to later "easily" debug them)
+               $decodedData = base64_decode($encodedData);
+
+               /*
+                * Do some checks on the decoded string, it should be a
+                * serialized array with 11 entries (see above
+                * executeWernisApiGet() call).
+                */
+               assert(substr($decodedData, 0, 6) == 'a:11:{');
+               assert(substr($decodedData, -1, 1) == '}');
+
+               // The array seems to be fine, unserialize it
+               $userData = unserialize($decodedData);
+
+               // All mappings WDS66->mailer
+               $mappings = array(
+                       'anrede'      => 'gender',
+                       'vorname'     => 'surname',
+                       'name'        => 'family',
+                       'strasse'     => 'street_nr',
+                       'plz'         => 'zip',
+                       'ort'         => 'city',
+                       'email'       => 'email',
+                       'birth_day'   => 'birth_day',
+                       'birth_month' => 'birth_month',
+                       'birth_year'  => 'birth_year',
+                       'werber'      => 'wernis_refid'
+               );
+
+               // Map all WDS66 entries into mailer entries
+               foreach ($mappings as $from => $to) {
+                       // All must exist
+                       if (!isset($userData[$from])) {
+                               // Element $from does not exist
+                               reportBug(__FUNCTION__, __LINE__, 'Cannot map from=' . $from . ' -> to=' . $to . ': element does not exist.');
+                       } // END - if
+
+                       // "Map" all
+                       $return['mapped_data'][$to] = convertEmptyToNull($userData[$from]);
+               } // END - foreach
+
+               // Both arrays must have same size
+               assert(count($userData) == count($return['mapped_data']));
+
+               // Now add userid from WDS66
+               $return['mapped_data']['wernis_userid'] = bigintval($rows[0]['wernis_userid']);
        } else {
-               // Status does not need to be changed
+               // Something bad happened so copy the message
+               $return['message'] = $response['message'];
        }
+
+       // Return mapped data array
+       return $return;
 }
 
 // Updates auth status by given key/value pair
diff --git a/templates/de/html/guest/guest_wernis_registration_form.tpl b/templates/de/html/guest/guest_wernis_registration_form.tpl
deleted file mode 100644 (file)
index 74d606a..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<div class="para">
-<div align="center">
-       {%form,formMethodPost=modules.php?module=index&amp;what=register&amp;provider=wernis%}
-       <div class="table dashed">
-               <div class="table_header bottom">
-                       {--GUEST_WERNIS_REGISTRATION_TITLE--}
-               </div>
-
-               <fieldset id="wernis_registration_fields">
-                       <legend>{--GUEST_WERNIS_REGISTRATION_LEGEND--}</legend>
-
-                       <div class="guest_input" align="left">
-                               <label for="wernis_id">{--GUEST_ENTER_WERNIS_ID--}</label>
-                               <input type="text" class="form_field" id="base_path" name="wernis_id" size="10" maxlength="20" />
-                       </div>
-
-                       <div class="clear"></div>
-
-                       <div class="guest_input" align="left">
-                               <label for="wernis_password">{--GUEST_ENTER_WERNIS_PASSWORD--}</label>
-                               <input type="password" class="form_field" id="base_path" name="wernis_password" size="10" maxlength="255" />
-                       </div>
-
-                       <div class="clear"></div>
-               </fieldset>
-
-               <div class="table_footer top">
-                       <input type="reset" class="form_reset" value="{--CLEAR_FORM--}" />
-                       <input type="submit" class="form_submit" name="register" value="{--GUEST_WERNIS_REGISTRATION_SUBMIT--}" />
-               </div>
-       </div>
-       {%form_close%}
-
-       <div class="notice">
-               {--GUEST_WERNIS_REGISTRATION_NOTICE--}
-       </div>
-</div>
-</div>
-
-<div class="para" align="left">
-       <ul>
-               <li>{--GUEST_WERNIS_SIGNUP_NOTICE--}</li>
-               <li>{--GUEST_WERNIS_RESTORE_PASSWORD_NOTICE--}</li>
-       </ul>
-</div>
diff --git a/templates/de/html/guest/guest_wernis_registration_rpc_form.tpl b/templates/de/html/guest/guest_wernis_registration_rpc_form.tpl
new file mode 100644 (file)
index 0000000..74d606a
--- /dev/null
@@ -0,0 +1,45 @@
+<div class="para">
+<div align="center">
+       {%form,formMethodPost=modules.php?module=index&amp;what=register&amp;provider=wernis%}
+       <div class="table dashed">
+               <div class="table_header bottom">
+                       {--GUEST_WERNIS_REGISTRATION_TITLE--}
+               </div>
+
+               <fieldset id="wernis_registration_fields">
+                       <legend>{--GUEST_WERNIS_REGISTRATION_LEGEND--}</legend>
+
+                       <div class="guest_input" align="left">
+                               <label for="wernis_id">{--GUEST_ENTER_WERNIS_ID--}</label>
+                               <input type="text" class="form_field" id="base_path" name="wernis_id" size="10" maxlength="20" />
+                       </div>
+
+                       <div class="clear"></div>
+
+                       <div class="guest_input" align="left">
+                               <label for="wernis_password">{--GUEST_ENTER_WERNIS_PASSWORD--}</label>
+                               <input type="password" class="form_field" id="base_path" name="wernis_password" size="10" maxlength="255" />
+                       </div>
+
+                       <div class="clear"></div>
+               </fieldset>
+
+               <div class="table_footer top">
+                       <input type="reset" class="form_reset" value="{--CLEAR_FORM--}" />
+                       <input type="submit" class="form_submit" name="register" value="{--GUEST_WERNIS_REGISTRATION_SUBMIT--}" />
+               </div>
+       </div>
+       {%form_close%}
+
+       <div class="notice">
+               {--GUEST_WERNIS_REGISTRATION_NOTICE--}
+       </div>
+</div>
+</div>
+
+<div class="para" align="left">
+       <ul>
+               <li>{--GUEST_WERNIS_SIGNUP_NOTICE--}</li>
+               <li>{--GUEST_WERNIS_RESTORE_PASSWORD_NOTICE--}</li>
+       </ul>
+</div>