本文整理汇总了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";
}