]> git.mxchange.org Git - mailer.git/commitdiff
Also already accepted/rejected/never started authorizations for registration should...
authorRoland Haeder <roland@mxchange.org>
Sat, 4 Apr 2015 02:51:37 +0000 (04:51 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 4 Apr 2015 02:51:37 +0000 (04:51 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/extensions/ext-wernis.php
inc/extensions/wernis/mode-update.php
inc/language/wernis_de.php
inc/libs/wernis_functions.php

index 0ec3db97fffcefb36fea571b904edfad9fe41dfb..53d370471c22856844c6275ccbdda64f619658fc 100644 (file)
@@ -41,10 +41,10 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Version of this extension
 } // END - if
 
 // Version of this extension
-setThisExtensionVersion('0.1.0');
+setThisExtensionVersion('0.1.1');
 
 // Version history array (add more with , '0.0.1' and so on)
 
 // Version history array (add more with , '0.0.1' and so on)
-setExtensionVersionHistory(array('0.0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0'));
+setExtensionVersionHistory(array('0.0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1'));
 
 switch (getExtensionMode()) {
        case 'setup': // Do stuff when installation is running
 
 switch (getExtensionMode()) {
        case 'setup': // Do stuff when installation is running
index 226efc39af55c1ed7dca50150aa9d76d1708bb0c..1271ae0ea2d85c9616336af22bd4efdeee2e8d39 100644 (file)
@@ -147,6 +147,13 @@ INDEX (`wernis_userid`)",
                setExtensionUpdateNotes("Daten f&uuml;r verschl&uuml;sselte &Uuml;bertragungen hinzugef&uuml;gt.");
                break;
 
                setExtensionUpdateNotes("Daten f&uuml;r verschl&uuml;sselte &Uuml;bertragungen hinzugef&uuml;gt.");
                break;
 
+       case '0.1.1': // SQL queries for v0.1.1
+               addExtensionAddTableColumnSql('wernis_regs', 'api_challenge_response', "VARCHAR(255) NOT NULL DEFAULT 'INVALID'");
+
+               // Update notes (these will be set as task text!)
+               setExtensionUpdateNotes("Challange-Reponse muss auch gespeichert werden, da sonst eine erneute API-Anfrage n&ouml;tig w&auml;re, das ist aber &uuml;berfl&uuml;ssig, da bei einer Annahme, bereits ACCEPTED zur&uuml;ckkommt.");
+               break;
+
 } // END - switch
 
 // [EOF]
 } // END - switch
 
 // [EOF]
index 474609e5ab14e6111f57821eb59ff0a2b089ad08..c1be39d073d14f130462e6112f44604b238aabd5 100644 (file)
@@ -42,14 +42,22 @@ if (!defined('__SECURITY')) {
 
 // Language definitions
 addMessages(array(
 
 // Language definitions
 addMessages(array(
-       'WERNIS_STATUS_UNKNWOWN' => "Wernis-Typ <span class=\"data\">%s</span> unbekannt.",
-       'WERNIS_STATUS_WITHDRAW' => "Einzahlung von WDS66",
-       'WERNIS_STATUS_PAYOUT' => "Auszahlung an WDS66",
-       'WERNIS_STATUS_FAILED' => "Fehlgeschlagen",
        'WERNIS_TIMESTAMP' => "Buchungszeitmarke",
        'WERNIS_ACCOUNT' => "WDS66-Hauptaccount",
        'WERNIS_TOTAL_WERNIS' => "Gesamt &uuml;berwiesen",
 
        'WERNIS_TIMESTAMP' => "Buchungszeitmarke",
        'WERNIS_ACCOUNT' => "WDS66-Hauptaccount",
        'WERNIS_TOTAL_WERNIS' => "Gesamt &uuml;berwiesen",
 
+       // Transfer status
+       'WERNIS_TRANSFER_STATUS_UNKNWOWN' => "Wernis-Typ <span class=\"data\">%s</span> unbekannt.",
+       'WERNIS_TRANSFER_STATUS_WITHDRAW' => "Einzahlung von WDS66",
+       'WERNIS_TRANSFER_STATUS_PAYOUT'   => "Auszahlung an WDS66",
+       'WERNIS_TRANSFER_STATUS_FAILED'   => "Fehlgeschlagen",
+
+       // Auth status
+       'WERNIS_AUTH_STATUS_UNKNOWN'  => "Unbekannt",
+       'WERNIS_AUTH_STATUS_ACCEPTED' => "Angenommen",
+       'WERNIS_AUTH_STATUS_REJECTED' => "Abgelehnt",
+       'WERNIS_AUTH_STATUS_PENDING'  => "Wartend",
+
        // Admin messages
        'ADMIN_CONFIG_WERNIS_TITLE' => "Einstellungen zum WDS66-Hauptaccount:",
        'ADMIN_CONFIG_WERNIS_MIN_PAYOUT' => "Minimumguthaben f&uuml;r Auszahlungen.",
        // Admin messages
        'ADMIN_CONFIG_WERNIS_TITLE' => "Einstellungen zum WDS66-Hauptaccount:",
        'ADMIN_CONFIG_WERNIS_MIN_PAYOUT' => "Minimumguthaben f&uuml;r Auszahlungen.",
@@ -101,6 +109,10 @@ addMessages(array(
        'WERNIS_API_REQUEST_FAILED_AMOUNT' => "Konto weist nicht gen&uuml;gend Deckung auf.",
        'WERNIS_API_REQUEST_FAILED_API_AMOUNT' => "API-Konto weist nicht gen&uuml;gend Deckung auf.",
        'WERNIS_API_REQUEST_FAILED_GENERIC' => "API-Abfrage fehlgeschlagen oder Auswertung der Antwort fehlgeschlagen.",
        'WERNIS_API_REQUEST_FAILED_AMOUNT' => "Konto weist nicht gen&uuml;gend Deckung auf.",
        'WERNIS_API_REQUEST_FAILED_API_AMOUNT' => "API-Konto weist nicht gen&uuml;gend Deckung auf.",
        'WERNIS_API_REQUEST_FAILED_GENERIC' => "API-Abfrage fehlgeschlagen oder Auswertung der Antwort fehlgeschlagen.",
+       'WERNIS_API_REQUEST_FAILED_AUTH_STATUS' => "API-Authorisierung hat unerwarteten Status <em>{OPEN_TEMPLATE}pipe,translateWernisAuthStatu=%s{CLOSE_TEMPLATE}</em>.",
+       'WERNIS_API_REQUEST_FAILED_AUTH_STATUS_ACCEPTED' => "Bei der API-Authorisierung ist ein Fehler unterlaufen, da <em>{--WERNIS_AUTH_STATUS_ACCEPTED--}</em> als Fehler gemeldet wurde.",
+       'WERNIS_API_REQUEST_FAILED_AUTH_STATUS_REJECTED' => "Sie hatten dem Datentransfer zu diesem {?MT_WORD?} nicht zugestimmt.",
+       'WERNIS_API_REQUEST_FAILED_AUTH_STATUS_UNKNOWN' => "Sie haben noch keine Authorisierung durchgef&uuml;hrt und haben vermutlich einen alten Link benutzt.",
        'WERNIS_API_PURPOSE_WITHDRAW' => "Einzahlung auf {?MAIN_TITLE?} ({?URL?}), id: <span class=\"data\">%s</span>",
        'WERNIS_API_PURPOSE_PAYOUT' => "Auszahlung von {?MAIN_TITLE?} ({?URL?}), id: <span class=\"data\">%s</span>",
 
        'WERNIS_API_PURPOSE_WITHDRAW' => "Einzahlung auf {?MAIN_TITLE?} ({?URL?}), id: <span class=\"data\">%s</span>",
        'WERNIS_API_PURPOSE_PAYOUT' => "Auszahlung von {?MAIN_TITLE?} ({?URL?}), id: <span class=\"data\">%s</span>",
 
@@ -160,6 +172,7 @@ addMessages(array(
        'GUEST_WERNIS_REGISTRATION_PASSWORD_NOT_SET' => "Bitte geben Sie Ihr Wernis-Passwort ein. Tipp: Dies ist <strong>nicht</strong> Ihr Account-Passwort.",
        'GUEST_WERNIS_REGISTRATION_INVALID_CHALLENGE_RESPONSE' => "Es ist beim Anmeldeversuch ein Fehler unterlaufen: Falsche Challenge-Response",
        'GUEST_WERNIS_REGISTRATION_ZERO_ROWS_FOUND' => "Es konnte keine Anmeldedaten von der WDS66-API gefunden werden. Haben Sie auch den richtigen Link aufgerufen?",
        'GUEST_WERNIS_REGISTRATION_PASSWORD_NOT_SET' => "Bitte geben Sie Ihr Wernis-Passwort ein. Tipp: Dies ist <strong>nicht</strong> Ihr Account-Passwort.",
        'GUEST_WERNIS_REGISTRATION_INVALID_CHALLENGE_RESPONSE' => "Es ist beim Anmeldeversuch ein Fehler unterlaufen: Falsche Challenge-Response",
        'GUEST_WERNIS_REGISTRATION_ZERO_ROWS_FOUND' => "Es konnte keine Anmeldedaten von der WDS66-API gefunden werden. Haben Sie auch den richtigen Link aufgerufen?",
+       'GUEST_WERNIS_REGISTRATION_AUTH_REJECTED' => "Die Anmeldung mit WDS66 kann nicht abgeschlossen werden, da Sie den Datenzugriff verweigert haben.",
        'GUEST_REGISTER_WERNIS_PROVIDER_TITLE' => "Anmeldung mit WDS66 am {?mt_word?} <strong>{?MAIN_TITLE?}</strong>:",
 
        // Points accounts - subject
        'GUEST_REGISTER_WERNIS_PROVIDER_TITLE' => "Anmeldung mit WDS66 am {?mt_word?} <strong>{?MAIN_TITLE?}</strong>:",
 
        // Points accounts - subject
index 41a0b09a27bbcef242327af2522a2bedd2ac24d7..e01bcb9c31c0fc0813eb3fc47c8e21c0faec19bc 100644 (file)
@@ -152,8 +152,21 @@ function sendWernisApiRequest ($scriptName, $requestData = array()) {
 
        // We use only the first two entries (which shall be fine)
        if ($data[0] === 'error') {
 
        // We use only the first two entries (which shall be fine)
        if ($data[0] === 'error') {
-               // The request has failed... :(
-               switch ($data[1]) {
+               // The request has failed...
+               $status = $data[1];
+               $extraData = '';
+
+               // Explode status code
+               $exploded = explode(':', $status);
+
+               // More extra data found?
+               if (count($exploded) > 1) {
+                       // Then set all
+                       $status    = $exploded[0];
+                       $extraData = $exploded[1];
+               } // END - if
+
+               switch ($status) {
                        case '404': // Invalid API id
                        case 'AUTH': // Authorization has failed
                                $return = array(
                        case '404': // Invalid API id
                        case 'AUTH': // Authorization has failed
                                $return = array(
@@ -192,6 +205,39 @@ function sendWernisApiRequest ($scriptName, $requestData = array()) {
                                );
                                break;
 
                                );
                                break;
 
+                       case 'AUTH-STATUS': // Unexpected auth status
+                               // Switch on extra data
+                               switch ($extraData) {
+                                       case 'ACCEPTED':
+                                               $return = array(
+                                                       'status'  => 'api_auth_status_accepted',
+                                                       'message' => '{--WERNIS_API_REQUEST_FAILED_AUTH_STATUS_ACCEPTED--}'
+                                               );
+                                               break;
+
+                                       case 'REJECTED':
+                                               $return = array(
+                                                       'status'  => 'api_auth_status_rejected',
+                                                       'message' => '{--WERNIS_API_REQUEST_FAILED_AUTH_STATUS_REJECTED--}'
+                                               );
+                                               break;
+
+                                       case 'UNKNOWN':
+                                               $return = array(
+                                                       'status'  => 'api_auth_status_unknown',
+                                                       'message' => '{--WERNIS_API_REQUEST_FAILED_AUTH_STATUS_UNKNOWN--}'
+                                               );
+                                               break;
+
+                                       default: // Unknown
+                                               $return = array(
+                                                       'status'  => 'api_auth_status_failed',
+                                                       'message' => getMaskedMessage('WERNIS_API_REQUEST_FAILED_AUTH_STATUS', $extraData)
+                                               );
+                                               break;
+                               } // END - switch
+                               break;
+
                        default: // Unknown error (maybe new?)
                                logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown error %s from WDS66 API received.', $data[1]));
                                $return = array(
                        default: // Unknown error (maybe new?)
                                logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown error %s from WDS66 API received.', $data[1]));
                                $return = array(
@@ -199,7 +245,7 @@ function sendWernisApiRequest ($scriptName, $requestData = array()) {
                                        'message' => '{%message,WERNIS_API_REQUEST_FAILED=' . $data[1] . '%}'
                                );
                                break;
                                        'message' => '{%message,WERNIS_API_REQUEST_FAILED=' . $data[1] . '%}'
                                );
                                break;
-               }
+               } // END - switch
        } else {
                // All fine, then analyze API response
                $return = convertApiResponseToArray($responseLine, '&', '=');
        } else {
                // All fine, then analyze API response
                $return = convertApiResponseToArray($responseLine, '&', '=');
@@ -414,13 +460,18 @@ function executeWernisApiGet ($authData, $subRequest, $fields) {
        return $return;
 }
 
        return $return;
 }
 
+// Translate auth status
+function translateWernisAuthStatu ($status) {
+       return '{%message,WERNIS_AUTH_STATUS_' . strtoupper($status) . '%}';
+}
+
 // Translate the status IN/OUT
 function translateWernisTransferStatus ($status) {
        // Default status is unknown
 // Translate the status IN/OUT
 function translateWernisTransferStatus ($status) {
        // Default status is unknown
-       $return = '{%message,WERNIS_STATUS_UNKNWOWN=' . $status . '%}';
+       $return = '{%message,WERNIS_TRANSFER_STATUS_UNKNWOWN=' . $status . '%}';
 
        // Construct message id
 
        // Construct message id
-       $messageId = 'WERNIS_STATUS_' . $status;
+       $messageId = 'WERNIS_TRANSFER_STATUS_' . $status;
 
        // Is it there?
        if (isMessageIdValid($messageId)) {
 
        // Is it there?
        if (isMessageIdValid($messageId)) {
@@ -581,7 +632,7 @@ function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status
        // Is the status 1? (= all fine with API call)
        if ($status == '1') {
                // Get mapped data based on challenge
        // Is the status 1? (= all fine with API call)
        if ($status == '1') {
                // Get mapped data based on challenge
-               $return = getWernisMappedDataFromApiByChallenge($challenge, $status);
+               $return = getWernisMappedDataFromApiByChallenge($challenge, $challengeResponse, $status);
 
                // Is the array filled?
                //* DEBUG-DIE */ die(__METHOD__ . ':return=<pre>' . print_r($return, TRUE) . '</pre> - EXIT!');
 
                // Is the array filled?
                //* DEBUG-DIE */ die(__METHOD__ . ':return=<pre>' . print_r($return, TRUE) . '</pre> - EXIT!');
@@ -606,13 +657,13 @@ function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status
                        return FALSE;
                }
        } else {
                        return FALSE;
                }
        } else {
-               // Status does not need to be changed
-               die(__FUNCTION__ . ':' . __LINE__ . ': Reached!');
+               // Not accepted
+               displayMessage('{--GUEST_WERNIS_REGISTRATION_AUTH_REJECTED--}');
        }
 }
 
 // "Getter" for mapped data by calling the API and given challenge and status
        }
 }
 
 // "Getter" for mapped data by calling the API and given challenge and status
-function getWernisMappedDataFromApiByChallenge ($challenge, $status) {
+function getWernisMappedDataFromApiByChallenge ($challenge, $challengeResponse, $status) {
        // Get stored registration data
        $rows = getWernisRegistrationDataByKey('api_redirect_challenge', $challenge);
 
        // Get stored registration data
        $rows = getWernisRegistrationDataByKey('api_redirect_challenge', $challenge);
 
@@ -642,6 +693,7 @@ function getWernisMappedDataFromApiByChallenge ($challenge, $status) {
                 * will always run.
                 */
                updateWernisRegistrationDataByKey('api_auth_status', 'api_redirect_challenge', $challenge, 'ACCEPTED');
                 * will always run.
                 */
                updateWernisRegistrationDataByKey('api_auth_status', 'api_redirect_challenge', $challenge, 'ACCEPTED');
+               updateWernisRegistrationDataByKey('api_challenge_response', 'api_redirect_challenge', $challenge, $challengeResponse);
        } // END - if
 
        // Now call "get.php"
        } // END - if
 
        // Now call "get.php"
@@ -747,6 +799,7 @@ function getWernisRegistrationDataByKey ($key, $value, $limit = 1) {
        `api_auth_status`,
        `api_auth_key`,
        `api_redirect_challenge`,
        `api_auth_status`,
        `api_auth_key`,
        `api_redirect_challenge`,
+       `api_challenge_response`,
        UNIX_TIMESTAMP(`record_inserted`) AS `record_inserted`
 FROM
        `{?_MYSQL_PREFIX?}_wernis_regs`
        UNIX_TIMESTAMP(`record_inserted`) AS `record_inserted`
 FROM
        `{?_MYSQL_PREFIX?}_wernis_regs`
@@ -881,7 +934,32 @@ function doWernisAuthAccepted ($args) {
        // auth_key and wernis_userid must be set
        assert(isset($args['auth_key']));
        assert(isset($args['wernis_userid']));
        // auth_key and wernis_userid must be set
        assert(isset($args['auth_key']));
        assert(isset($args['wernis_userid']));
-       die(__FUNCTION__ . ':' . __LINE__ . '<pre>' . print_r($args, TRUE) . '</pre>');
+
+       // Get registration data by auth_key
+       $rows = getWernisRegistrationDataByKey('api_auth_key', $args['auth_key']);
+
+       // 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()) . '&amp;challenge=' . $rows[0]['api_redirect_challenge'] . '&amp;__challenge_response=' . $rows[0]['api_challenge_response'] . '&amp;status=1';
+
+       // Redirect to URL
+       redirectToUrl($url);
 }
 
 //------------------------------------------------------------------------------
 }
 
 //------------------------------------------------------------------------------