コード例 #1
0
 /**
  * Build and return a new form.
  *
  * @param  array|\ArrayAccess $options The form build options.
  * @return DashboardInterface
  */
 public function build($options)
 {
     $objType = isset($options['type']) ? $options['type'] : self::DEFAULT_TYPE;
     $obj = $this->factory->create($objType);
     $obj->setData($options);
     return $obj;
 }
コード例 #2
0
 /**
  * @param ServerRequestInterface $request  PSR7 Request.
  * @param ResponseInterface      $response PSR7 Response.
  * @return ResponseInterface
  */
 public function run(RequestInterface $request, ResponseInterface $response)
 {
     $widgetType = $request->getParam('widget_type');
     $widgetOptions = $request->getParam('widget_options');
     if (!$widgetType) {
         $this->setSuccess(false);
         return $response->withStatus(400);
     }
     try {
         $widget = $this->widgetFactory->create($widgetType);
         $widget->setView($this->widgetView);
         if (is_array($widgetOptions)) {
             $widget->setData($widgetOptions);
         }
         $widgetHtml = $widget->renderTemplate($widgetType);
         $widgetId = $widget->widgetId();
         $this->setWidgetHtml($widgetHtml);
         $this->setWidgetId($widgetId);
         $this->setSuccess(true);
         return $response;
     } catch (Exception $e) {
         $this->addFeedback('error', sprintf('An error occured reloading the widget: "%s"', $e->getMessage()));
         $this->addFeedback('error', $e->getMessage());
         $this->setSuccess(false);
         return $response->withStatus(500);
     }
 }
コード例 #3
0
 /**
  * Build and return a new menu item.
  *
  * @param  array|\ArrayAccess $options The menu item build options.
  * @return MenuItemInterface
  */
 public function build($options)
 {
     $container = $this->container;
     $objType = isset($options['type']) ? $options['type'] : self::DEFAULT_TYPE;
     $obj = $this->factory->create($objType, ['menu' => $options['menu'], 'logger' => $container['logger'], 'view' => $container['view'], 'menu_item_builder' => $container['menu/item/builder']]);
     $obj->setData($options);
     return $obj;
 }
コード例 #4
0
 /**
  * @param array|\ArrayAccess $options The form group build options / config.
  * @return WidgetInterface The "built" widget object.
  */
 public function build($options)
 {
     if (isset($options['controller'])) {
         $objType = $options['controller'];
     } elseif (isset($options['type'])) {
         $objType = $options['type'];
     } else {
         $objType = self::DEFAULT_TYPE;
     }
     $obj = $this->factory->create($objType);
     $obj->setData($options);
     return $obj;
 }
コード例 #5
0
 /**
  * Load an objet from soure
  *
  * @param mixed $ident The object ident to load.
  * @return \Charcoal\Model\ModelInterface
  */
 private function loadFromSource($ident)
 {
     $obj = $this->factory->create($this->objType);
     if ($this->objKey) {
         $obj->loadFrom($this->objKey, $ident);
     } else {
         $obj->load($ident);
     }
     return $obj;
 }
コード例 #6
0
 /**
  *
  * @param User   $user  The user to send the lost-password email to.
  * @param string $token The lost-password token, as string.
  * @return void
  */
 private function sendLostPasswordEmail(User $user, $token)
 {
     $userEmail = $user->email();
     $subject = 'Charcoal lost password';
     $from = '*****@*****.**';
     // Create email
     $emailObj = $this->emailFactory->create('email');
     $emailObj->setData(['campaign' => 'admin.lost-password', 'to' => $userEmail, 'subject' => $subject, 'from' => $from, 'log' => true, 'template_ident' => 'charcoal/admin/email/user.lost-password', 'template_data' => ['user' => $user, 'token' => $token->id(), 'urlResetPassword' => $this->adminUrl() . 'account/reset-password/' . $token->id(), 'expiry' => $token->expiry()->format('Y-m-d H:i:s'), 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '']]);
     $emailObj->send();
 }
コード例 #7
0
 /**
  * @param ModelMetadata $metadata    The object metadata, where to find the object's
  *     source configuration.
  * @param string|null   $sourceIdent Optional. Custom source ident to load.
  *     If NULL, the default (from metadata) will be used.
  * @throws Exception If the source is not defined in the model's metadata.
  * @return SourceInterface
  */
 private function createSource(ModelMetadata $metadata, $sourceIdent = null)
 {
     if ($sourceIdent === null) {
         $sourceIdent = $metadata->defaultSource();
     }
     $sourceConfig = $metadata->source($sourceIdent);
     if (!$sourceConfig) {
         throw new Exception(sprintf('Can not create %s source: "%s" is not defined in metadata.', get_class($this), $sourceIdent));
     }
     $sourceType = isset($sourceConfig['type']) ? $sourceConfig['type'] : self::DEFAULT_SOURCE_TYPE;
     $source = $this->sourceFactory->create($sourceType);
     $source->setData($sourceConfig);
     return $source;
 }
コード例 #8
0
 /**
  * Get the currently authenticated user (from session)
  *
  * Return null if there is no current user in logged into
  *
  * @param FactoryInterface $factory The factory to create the user object with.
  * @throws Exception If the user from session is invalid.
  * @return UserInterface|null
  */
 public static function getAuthenticated(FactoryInterface $factory)
 {
     if (isset(static::$authenticatedUser[static::sessionKey()])) {
         return static::$authenticatedUser[static::sessionKey()];
     }
     if (!isset($_SESSION[static::sessionKey()])) {
         return null;
     }
     $userId = $_SESSION[static::sessionKey()];
     if (!$userId) {
         return null;
     }
     $userClass = get_called_class();
     $user = $factory->create($userClass);
     $user->load($userId);
     // Inactive users can not authenticate
     if (!$user->id() || !$user->username() || !$user->active()) {
         // @todo log error
         return null;
     }
     static::$authenticatedUser[static::sessionKey()] = $user;
     return $user;
 }