示例#1
0
 private function getLatchStatus($latchId)
 {
     $api = LatchHelper::getLatchConnection();
     if ($api != NULL) {
         $response = $api->status($latchId);
         if ($this->isLatchResponseValid($response)) {
             $appId = $this->params->get("latch_appID");
             $status = $response->getData()->{"operations"}->{$appId}->{"status"};
             $adaptedResponse = array('accountBlocked' => $status == "off");
             if (property_exists($response->getData()->{"operations"}->{$appId}, "two_factor")) {
                 $adaptedResponse['twoFactor'] = $response->getData()->{"operations"}->{$appId}->{"two_factor"}->{"token"};
             }
             return $adaptedResponse;
         }
     }
     return array('accountBlocked' => false);
 }
//JFactory::getDocument()->addStyleSheet(JUri::root() . "modules/mod_latch/latch.css");
JHtml::stylesheet('mod_latch/latch.css', false, true, false);
// Generate all the variables needed in the view
$user = JFactory::getUser();
$application = JFactory::getApplication();
$input = $application->input;
$latchAction = $input->get("latchAction", false);
$pairingToken = $input->get("pairingToken", false);
$userWantsToPairAccount = $latchAction == "pair";
if ($pairingToken) {
    JSession::checkToken() or die('Invalid Token');
    if (LatchHelper::pair($pairingToken)) {
        $application->enqueueMessage('Account paired successfully.');
    } else {
        $application->enqueueMessage('Error pairing account.', 'warning');
    }
} elseif ($latchAction) {
    JSession::checkToken() or die('Invalid Token');
    if ($latchAction == "pair") {
        $userWantsToPairAccount = true;
    } elseif ($latchAction == "unpair") {
        if (!LatchHelper::unpair()) {
            $application->enqueueMessage('Error unpairing account.', 'warning');
        } else {
            $application->enqueueMessage('Account unpaired successfully.');
        }
    }
}
$paired = LatchHelper::getLatchId($user->id) != NULL;
// Load the view
require JPATH_ROOT . "/modules/mod_latch/tmpl/default.php";