当前位置: 首页>>代码示例>>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;未经允许,请勿转载。