當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AuthManager::setAuth方法代碼示例

本文整理匯總了PHP中AuthManager::setAuth方法的典型用法代碼示例。如果您正苦於以下問題:PHP AuthManager::setAuth方法的具體用法?PHP AuthManager::setAuth怎麽用?PHP AuthManager::setAuth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AuthManager的用法示例。


在下文中一共展示了AuthManager::setAuth方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validateFormAndSubmit

 /**
  * on-enter callback for the "submit" state.
  * Should validate the data and then submit the data to AG
  *
  * @param $action
  * @param $flowScope
  */
 public function validateFormAndSubmit($action, &$flowScope)
 {
     $registry = Zend_Registry::getInstance();
     $translate = $registry->get("Zend_Translate");
     $validationErrors = array();
     $isNew = $flowScope['isNew'];
     /**
      * @var Auth $auth
      */
     $auth = $flowScope['auth'];
     $howMany = $flowScope['howMany'];
     if ($isNew && empty($howMany)) {
         $validationErrors['howMany'] = "Please choose how many Auths you would like";
     }
     $shouldValidateCreds = $isNew && $howMany === "1" || !$isNew;
     if ($shouldValidateCreds && $auth->type === AuthType::$AUTHKEY && empty($auth->authKeyAuth->keyValue)) {
         $validationErrors['authKey'] = $translate->translate("For authKey auth, you must specify a key");
     }
     if ($shouldValidateCreds && ($auth->type === AuthType::$BASIC || $auth->type === AuthType::$WSSE) && empty($auth->basicAuth->username) && empty($auth->wsseAuth->username)) {
         $validationErrors['username'] = $translate->translate("Username is required");
     }
     if ($shouldValidateCreds && ($auth->type === AuthType::$BASIC || $auth->type === AuthType::$WSSE) && empty($auth->basicAuth->password) && empty($auth->wsseAuth->password)) {
         $validationErrors['password'] = $translate->translate("Password is required");
     }
     if ($shouldValidateCreds && $auth->type === AuthType::$IPWHITELIST && empty($auth->ipWhiteListAuth->ips)) {
         $validationErrors['ipWhiteList'] = $translate->translate("IP list is required");
     }
     SharedViewUtility::validateHeaderTransformations($auth->headerTransformations, $validationErrors);
     SharedViewUtility::validateProperties($auth->properties, $validationErrors);
     SharedViewUtility::validateTdrRules($auth->tdrData, $validationErrors);
     if (count($validationErrors) > 0) {
         $flowScope['validationErrors'] = $validationErrors;
         return "invalid";
     }
     /**
      * Submit to AG
      */
     $authManager = new AuthManager();
     $creds = array();
     for ($i = 0; $i < $howMany; $i++) {
         // If we are doing a batch create, then generate the credentials
         if ($howMany > 1) {
             switch ($auth->type) {
                 case AuthType::$AUTHKEY:
                     $auth->authKeyAuth->keyValue = uniqid();
                     break;
                 case AuthType::$BASIC:
                     $auth->basicAuth->username = uniqid();
                     $auth->basicAuth->password = uniqid();
                     break;
                 case AuthType::$WSSE:
                     $auth->wsseAuth->username = uniqid();
                     $auth->wsseAuth->password = uniqid();
                     break;
             }
             $auth->id = "";
         }
         $result = $authManager->setAuth($auth, $isNew);
         if ($result->getHTTPCode() !== "200") {
             $xml = simplexml_load_string($result->getPayload());
             $validationErrors['default'] = (string) $xml->error->errorText;
             $flowScope['validationErrors'] = $validationErrors;
             return "invalid";
         }
         // Pull the credentials out for display
         switch ($auth->type) {
             case AuthType::$AUTHKEY:
                 $creds[$auth->id] = "key: " . $auth->authKeyAuth->keyValue;
                 break;
             case AuthType::$BASIC:
                 $creds[$auth->id] = "u/p: " . $auth->basicAuth->username . " / " . $auth->basicAuth->password;
                 break;
             case AuthType::$WSSE:
                 $creds[$auth->id] = "u/p: " . $auth->wsseAuth->username . " / " . $auth->wsseAuth->password;
                 break;
             case AuthType::$IPWHITELIST:
                 $creds[$auth->id] = implode("; ", $auth->ipWhiteListAuth->ips);
                 break;
         }
     }
     if ($isNew) {
         $this->_helper->FlashMessenger("Successfully Created Auth(s)");
         foreach ($creds as $key => $value) {
             $this->_helper->FlashMessenger("{$key} ({$value})");
         }
     } else {
         $this->_helper->FlashMessenger("Successfully Updated Auth");
     }
     $flowScope['authIds'] = array_keys($creds);
     return "valid";
 }
開發者ID:kyroskoh,項目名稱:apigrove,代碼行數:98,代碼來源:AuthController.php


注:本文中的AuthManager::setAuth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。