Plugin Directory

Changeset 1245505


Ignore:
Timestamp:
09/14/2015 10:56:43 PM (11 years ago)
Author:
luisfpg
Message:

Handle error when activating the access client

Location:
cyclos/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cyclos/trunk/cyclos-admin.php

    r1179180 r1245505  
    102102        <form name="cyclos_edit" method="post" action="#">
    103103            <input type="hidden" name="goto_cyclos_settings" value="yes">
    104             <input type="submit" name="Submit" value="Edit Cyclos plugin settings"/></div>
     104            <input type="submit" name="Submit" value="Edit Cyclos plugin settings"/>
    105105        </form>
    106106        <form name="cyclos_translate" method="post" action="#">
    107107            <input type="hidden" name="goto_cyclos_translate" value="yes">
    108             <input type="submit" name="Submit" value="Change or translate labels of login form"/></div>
     108            <input type="submit" name="Submit" value="Change or translate labels of login form"/>
    109109        </form>
    110110    </div>
     
    212212    // Activate the access client
    213213    $accessClientService = new Cyclos\AccessClientService();
    214     $result = $accessClientService->activate($actcode, null);
    215     $token = $result->token;
    216    
    217     // Save the options
    218     update_option('cyclos_url', $url);
    219     update_option('cyclos_adminuser', $adminuser);
    220     update_option('cyclos_token', $token);
    221    
    222     ?>
    223     <div class="updated"><p><strong>Options saved</strong></p></div>
    224     <?php
    225    
     214    $errorMessage = NULL;
     215    try {
     216        $result = $accessClientService->activate($actcode, null);
     217        $token = $result->token;
     218    } catch (Cyclos\ConnectionException $e) {
     219        $errorMessage = "The Cyclos server couldn't be contacted";
     220    } catch (Cyclos\ServiceException $e) {
     221        switch ($e->errorCode) {
     222            case 'CREDENTIALS_NOT_SUPPLIED':
     223                $errorMessage = "Please, supply both login name and password for the Cyclos administrator";
     224                break;
     225            case 'REMOTE_ADDRESS_BLOCKED':
     226                $errorMessage = "The wordpress IP address has been temporarily blocked by exceeding login attempts";
     227                break;
     228            case 'ENTITY_NOT_FOUND':
     229                $errorMessage = "The given activation code didn't match an access client pending activation";
     230                break;
     231            case 'VALIDATION':
     232                $errorMessage = validationExceptionMessage($e);
     233                break;
     234            default:
     235                $errorMessage = "Error activating the access client: {$e->errorCode}";
     236        }
     237    }
     238   
     239    if (empty($errorMessage)) {
     240        // Save the options
     241        update_option('cyclos_url', $url);
     242        update_option('cyclos_adminuser', $adminuser);
     243        update_option('cyclos_token', $token);
     244        ?>
     245        <div class="updated">
     246            <p>Options saved</p>
     247        </div>
     248        <?php
     249    } else {
     250        ?>
     251        <div class="error">
     252            <p><?= $errorMessage ?></p>
     253        </div>
     254        <?php
     255    }
    226256    cyclosNormalAdminPage();
    227257}
     
    261291   
    262292    ?>
    263     <div class="updated"><p><strong>Options saved</strong></p></div>
     293    <div class="cyclosMsgInfo">Options saved</div>
    264294    <?php
    265295   
  • cyclos/trunk/cyclos-common.php

    r1111214 r1245505  
    8787}
    8888
     89
     90// Function which returns an appropriate error message for a validation exception
     91function validationExceptionMessage($e) {
     92    $val = $e->error->validation;
     93    $errors = array();
     94    if (!empty($val->generalErrors)) {
     95        $errors = array_merge($errors, $val->generalErrors);
     96    }
     97    if (!empty($val->propertyErrors)) {
     98        foreach ($val->propertyErrors as $key => $value) {
     99            $errors = array_merge($errors, $value);
     100        }
     101    }
     102    if (empty($errors)) {
     103        return "Validation error";
     104    } else {
     105        return implode("\n", $errors);
     106    }
     107}
     108
    89109?>
  • cyclos/trunk/cyclos-public.php

    r1243318 r1245505  
    4848    wp_enqueue_style( 'cyclosWordpressStylesheet' );
    4949}   
    50 
    51 // Function which returns an appropriate error message for a validation exception
    52 function validationExceptionMessage($e) {
    53     $val = $e->error->validation;
    54     $errors = array();
    55     if (!empty($val->generalErrors)) {
    56         $errors = array_merge($errors, $val->generalErrors);
    57     }
    58     if (!empty($val->propertyErrors)) {
    59         foreach ($val->propertyErrors as $key => $value) {
    60             $errors = array_merge($errors, $value);
    61         }
    62     }
    63     if (empty($errors)) {
    64         return "Validation error";
    65     } else {
    66         return implode("\n", $errors);
    67     }
    68 }
    6950
    7051// Function that is called when the shortcode is used
Note: See TracChangeset for help on using the changeset viewer.