/** * Return all messages in an array without status info. */ public function getMessagesOnly() { if ($this->hasMessages()) { $messages = $this->getMessages(); } else { $messages = array(); } if ($this->hasCurrentMessages()) { $messages = array_merge($messages, $this->getCurrentMessages()); } if (!$messages) { return null; } $output = array(); foreach ($messages as $message) { if (is_array($message)) { if (2 === count($message) && isset($message[0], $message[1]) && is_string($message[1])) { $message = $message[0]; } } $output[] = $message; } return \MUtil_Ra::flatten($output); }
/** * Check for password weakness. * * @param string $password Or null when you want a report on all the rules for this password. * @return mixed String or array of strings containing warning messages or nothing */ public function reportPasswordWeakness($password = null) { if ($this->canSetPassword()) { $checker = $this->userLoader->getPasswordChecker(); $codes[] = $this->getCurrentOrganization()->getCode(); $codes[] = $this->getRoles(); $codes[] = $this->_getVar('__user_definition'); return $checker->reportPasswordWeakness($this, $password, \MUtil_Ra::flatten($codes)); } }
/** * * @param string $key_arg1 First of optionally many arguments * @return \Gems_Util_RequestCache */ public function removeParams($key_arg1) { $args = \MUtil_Ra::flatten(func_get_args()); $this->_baseUrl = null; $params = $this->getProgramParams(); foreach ($args as $key) { if (isset($params[$key])) { unset($params[$key]); } } // \MUtil_Echo::track($params); $this->setProgramParams($params); return $this; }
/** * Default login page */ public function loginAction() { $request = $this->getRequest(); $form = $this->createLoginForm(); // Retrieve these before the session is reset $staticSession = \GemsEscort::getInstance()->getStaticSession(); $previousRequestParameters = $staticSession->previousRequestParameters; $previousRequestMode = $staticSession->previousRequestMode; if ($form->wasSubmitted()) { if ($form->isValid($request->getPost(), false)) { $user = $form->getUser(); $user->setAsCurrentUser(); if ($messages = $user->reportPasswordWeakness($request->getParam($form->passwordFieldName))) { $user->setPasswordResetRequired(true); $this->addMessage($this->_('Your password must be changed.')); foreach ($messages as &$message) { $message = ucfirst($message) . '.'; } $this->addMessage($messages); } /** * Fix current locale in cookies */ \Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath()); /** * Ready */ $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $user->getFullName()), 'success'); /** * Log the login */ $this->accesslog->logChange($request); if ($previousRequestParameters) { $this->_reroute(array('controller' => $previousRequestParameters['controller'], 'action' => $previousRequestParameters['action']), false); } else { // This reroutes to the first available menu page after login. // // Do not user $user->gotoStartPage() as the menu is still set // for no login. $this->_reroute(array('controller' => null, 'action' => null), true); } return; } else { $errors = \MUtil_Ra::flatten($form->getMessages()); // \MUtil_Echo::track($errors); //Also log the error to the log table //when the project has logging enabled $logErrors = join(' - ', $errors); $msg = sprintf('Failed login for : %s (%s) - %s', $request->getParam($form->usernameFieldName), $request->getParam($form->organizationFieldName), $logErrors); $this->accesslog->logChange($request, $msg); } // */ } else { if ($request->isPost()) { $form->populate($request->getPost()); } } $this->displayLoginForm($form); }
/** * Add items in hidden form to the bridge, and remove them from the items array * * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge * @param string $element1 * * @return void */ protected function addItemsHidden(\MUtil_Model_Bridge_FormBridgeInterface $bridge, $element1) { $args = func_get_args(); if (count($args) < 2) { throw new \Gems_Exception_Coding('Use at least 2 arguments, first the bridge and then one or more individual items'); } $bridge = array_shift($args); $elements = \MUtil_Ra::flatten($args); $form = $bridge->getForm(); //Remove the elements from the _items variable $this->_items = array_diff($this->_items, $elements); // And add them to the bridge foreach ($elements as $name) { // Use $bridge->addHidden as that adds validators and filters. $bridge->addHidden($name); } }
/** * All string values passed to this function are added as a field the * dependency depends on. * * @param mixed $dependsOn * @return \MUtil\Model\Dependency\DependencyAbstract (continuation pattern) */ public function addDependsOn($dependsOn) { $dependsOn = \MUtil_Ra::flatten(func_get_args()); foreach ($dependsOn as $dependOn) { $this->_dependentOn[$dependOn] = $dependOn; } return $this; }
/** * Progress a single step on the command stack * * @return boolean */ protected function step() { if ($this->stack->hasNext()) { try { $command = $this->stack->getNext(); if (!isset($command[0], $command[1])) { throw new \MUtil_Batch_BatchException("Invalid batch command: '{$command}'."); } list($method, $params) = $command; if (!method_exists($this, $method)) { throw new \MUtil_Batch_BatchException("Invalid batch method: '{$method}'."); } if (call_user_func_array(array($this, $method), $params)) { $this->stack->gotoNext(); } else { $this->_session->count = $this->_session->count + 1; } $this->_session->processed = $this->_session->processed + 1; } catch (\Exception $e) { $this->addMessage('ERROR!!!'); $this->addMessage('While calling:' . $command[0] . '(' . implode(',', \MUtil_Ra::flatten($command[1])) . ')'); $this->addException($e); $this->stopBatch($e->getMessage()); //\MUtil_Echo::track($e); } return true; } else { return false; } }
/** * Delete all, one or some values for a certain field name. * * @param string $name Field name * @param string|array|null $arrayOrKey1 Null or the name of a single attribute or an array of attribute names * @param string $key2 Optional a second attribute name. */ public function del($name, $arrayOrKey1 = null, $key2 = null) { if (func_num_args() == 1) { unset($this->_model[$name], $this->_model_order[$name], $this->_model_used[$name]); } else { $args = func_get_args(); array_shift($args); $args = \MUtil_Ra::flatten($args); foreach ($args as $arg) { unset($this->_model[$name][$arg]); } } }
/** * Adds one or more messages to the session based message store. * * @param mixed $message_args Can be an array or multiple argemuents. Each sub element is a single message string * @return self (continuation pattern) */ public function addMessage($message_args) { $messages = \MUtil_Ra::flatten(func_get_args()); $messenger = $this->getMessenger(); foreach ($messages as $message) { $messenger->addMessage($message); } return $this; }
/** * Add items to the bridge, and remove them from the items array * * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge * @param string $element1 * * @return void */ protected function addItems(\MUtil_Model_Bridge_FormBridgeInterface $bridge, $element1) { $args = func_get_args(); if (count($args) < 2) { throw new \Gems_Exception_Coding('Use at least 2 arguments, first the bridge and then one or more individual items'); } array_shift($args); // Remove bridge $elements = \MUtil_Ra::flatten($args); $model = $this->getModel(); //Remove the elements from the _items variable $this->_items = array_diff($this->_items, $elements); //And add them to the bridge foreach ($elements as $name) { if ($model->has($name, 'label') || $model->has($name, 'elementClass')) { $bridge->add($name); } else { $bridge->addHidden($name); } } }
/** * Render the element * * @param string $content Content to decorate * @return string */ public function render($content) { if (null === ($element = $this->getElement()) || null === ($view = $element->getView()) || null === ($htmlelement = $this->getHtmlElement())) { return $content; } if ($prologue = $this->getPrologue()) { if ($prologue instanceof \MUtil_Lazy_RepeatableFormElements) { // Not every browser can handle empty divs (e.g. IE 6) if ($hidden = $prologue->getHidden()) { $prologue = \MUtil_Html::create()->div($hidden); } else { $prologue = null; } } if ($prologue instanceof \MUtil_Html_HtmlInterface) { $prologue = $prologue->render($view); } else { $prologue = \MUtil_Html::getRenderer()->renderAny($view, $prologue); } } else { $prologue = ''; } if ($prependErrors = $this->getPrependErrors()) { $form = $this->getElement(); if ($errors = $form->getMessages()) { $errors = \MUtil_Ra::flatten($errors); $errors = array_unique($errors); if ($prependErrors instanceof \MUtil_Html_ElementInterface) { $html = $prependErrors; } else { $html = \MUtil_Html::create('ul'); } foreach ($errors as $error) { $html->append($error); } $prologue .= $html->render($view); } } $result = $this->renderElement($htmlelement, $view); if (parent::APPEND == $this->getPlacement()) { return $prologue . $result . $content; } else { return $content . $prologue . $result; } }
/** * Returns a description of the translator errors. * * @return array of String messages */ public function getErrors() { $errorOutput = array(); foreach ($this->_errors as $row => $rowErrors) { $rowErrors = $this->getRowErrors($row); if ($rowErrors) { $errorOutput[] = $rowErrors; } } return \MUtil_Ra::flatten($errorOutput); }
/** * Add single code line * * @param mixed $line * @return \MUtil_Html_JavascriptArrayAttribute (continuation pattern) */ public function addLine($line_args) { $lines = \MUtil_Ra::flatten(func_get_args()); foreach ($lines as $line) { $this->add($line); } if (!(isset($line) && ';' == substr($line, -1))) { $this->add(';'); } return $this; }