Ejemplo n.º 1
0
 /**
  * Method to render the user registration form.
  *
  * @return string
  *
  * @since 1.0
  */
 public function displayRegisterForm()
 {
     $config = ConfigProvider::getInstance();
     $request = new Request(array('method' => 'GET'));
     $html = '<p>In order to access this site, you will need to create a user account.  In order to do so, please provide a valid email address below and a password will be sent to your inbox shortly (you can change your password once you log in).</p>';
     $html .= '<table cols="2">';
     $html .= '<form action="' . $request->getURI() . '?reset=true" method="POST" accept-charset="UTF-8">';
     $html .= '<tr>';
     if ($config->get('security.encrypt.http.fieldnames')) {
         $fieldname = base64_encode(SecurityUtils::encrypt('displayname'));
     } else {
         $fieldname = 'displayname';
     }
     $html .= '  <td>Forum name</td> <td><input type="text" name="' . $fieldname . '" size="50" value="' . $request->getParam($fieldname, '') . '"/></td>';
     $html .= '</tr>';
     $html .= '<tr>';
     if ($config->get('security.encrypt.http.fieldnames')) {
         $fieldname = base64_encode(SecurityUtils::encrypt('email'));
     } else {
         $fieldname = 'email';
     }
     $html .= '  <td>E-mail Address</td> <td><input type="text" name="' . $fieldname . '" size="50" value="' . $request->getParam($fieldname, '') . '"/></td>';
     $html .= '</tr>';
     $html .= '<tr><td colspan="2">';
     $temp = new Button('submit', 'Register', 'registerBut');
     $html .= $temp->render();
     $html .= '&nbsp;&nbsp;';
     $temp = new Button("document.location.replace('" . $config->get('app.url') . "')", 'Cancel', 'cancelBut');
     $html .= $temp->render();
     $html .= '</td></tr>';
     $html .= $this->renderSecurityFields();
     $html .= '</form>';
     $html .= '</table>';
     return $html;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function renderDefaultField($name, $label, $mode, $value = '')
 {
     self::$logger->debug('>>renderDefaultField(name=[' . $name . '], label=[' . $label . '], mode=[' . $mode . '], value=[' . $value . '])');
     $config = ConfigProvider::getInstance();
     if ($config->get('security.encrypt.http.fieldnames')) {
         $fieldname = base64_encode(SecurityUtils::encrypt($name));
     } else {
         $fieldname = $name;
     }
     $html = '';
     $request = new Request(array('method' => 'GET'));
     if ($mode == 'create') {
         $html .= '<textarea cols="100" rows="3" name="' . $fieldname . '">' . $request->getParam($name, '') . '</textarea>';
     }
     if ($mode == 'edit') {
         $html .= '<textarea cols="100" rows="3" name="' . $fieldname . '">' . $value . '</textarea>';
     }
     if ($mode == 'view') {
         $html .= '<p><strong>' . $label . ':</strong> ' . $value . '</p>';
     }
     self::$logger->debug('<<renderDefaultField [' . $html . ']');
     return $html;
 }
Ejemplo n.º 3
0
 /**
  * Maps the supplied request with the appropiate method to run on this controller, for example
  * GET to doGET(), POST to doPOST() etc.  Returns the response generated by the method called.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 2.0
  */
 public function process($request)
 {
     if (!$request instanceof Request) {
         throw new IllegalArguementException('The request passed to process is not a valid Request object');
     }
     $config = ConfigProvider::getInstance();
     $method = $request->getMethod();
     if (in_array($method, array('POST', 'PUT', 'PATCH'))) {
         if ($config->get('security.encrypt.http.fieldnames')) {
             $decryptedParams = $this->decryptFieldNames($request->getParams());
             $request->addParams($decryptedParams);
             if ($request->getParam('_METHOD') != null) {
                 $request->setMethod($request->getParam('_METHOD'));
                 $method = $request->getMethod();
             }
         }
     }
     $ProviderClassName = $config->get('app.renderer.provider.name');
     if ($ProviderClassName == 'auto' && $request->getAccept() != null) {
         View::setProvider('auto', $request->getAccept());
     }
     $this->request = $request;
     // check the current user's rights on access to the page controller
     if (!$this->checkRights()) {
         return $this->accessError();
     }
     switch ($method) {
         case 'HEAD':
             $response = $this->doHEAD($request);
             break;
         case 'GET':
             $response = $this->doGET($request);
             break;
         case 'POST':
             $response = $this->doPOST($request);
             break;
         case 'PUT':
             $response = $this->doPUT($request);
             break;
         case 'PATCH':
             $response = $this->doPATCH($request);
             break;
         case 'DELETE':
             $response = $this->doDELETE($request);
             break;
         case 'OPTIONS':
             $response = $this->doOPTIONS($request);
             break;
         case 'TRACE':
             $response = $this->doTRACE($request);
             break;
     }
     return $response;
 }
Ejemplo n.º 4
0
 /**
  * Renders the HTML and javascript for the string box.
  *
  * @param bool $readOnly set to true to make the text box readonly (defaults to false)
  *
  * @return string
  *
  * @since 1.0
  */
 public function render($readOnly = false)
 {
     $request = new Request(array('method' => 'GET'));
     $html = '<div class="form-group">';
     $html .= '  <label for="' . $this->name . '">' . $this->label . '</label>';
     $html .= '  <input ' . ($this->stringObject->checkIsPassword() ? 'type="password"' : 'type="text"') . ($this->size == 0 ? ' style="width:100%;"' : ' size="' . $this->size . '"') . ' maxlength="' . String::MAX_SIZE . '" name="' . $this->name . '" id="' . $this->name . '" value="' . ($request->getParam($this->name, false) && $this->stringObject->getValue() == '' && !$this->stringObject->checkIsPassword() ? $request->getParam($this->name) : $this->stringObject->getValue()) . '" class="form-control"' . ($readOnly ? ' disabled="disabled"' : '') . '/>';
     if ($this->stringObject->getRule() != '') {
         $html .= '  <input type="hidden" id="' . $this->name . '_msg" value="' . $this->stringObject->getHelper() . '"/>';
         $html .= '  <input type="hidden" id="' . $this->name . '_rule" value="' . $this->stringObject->getRule() . '"/>';
     }
     $html .= '</div>';
     return $html;
 }
Ejemplo n.º 5
0
 /**
  * Testing that the HTTP params can be set from overrides or super-globals during object construction.
  */
 public function testSetHTTPParams()
 {
     $request = new Request(array('method' => 'GET', 'params' => array('username' => 'bob')));
     $this->assertEquals('bob', $request->getParam('username'), 'Testing that the HTTP params can be set from overrides or super-globals during object construction');
     $_GET['username'] = '******';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $request = new Request();
     $this->assertEquals('bob', $request->getParam('username'), 'Testing that the HTTP params can be set from overrides or super-globals during object construction');
     $_POST['username'] = '******';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $request = new Request();
     $this->assertEquals('bob', $request->getParam('username'), 'Testing that the HTTP params can be set from overrides or super-globals during object construction');
 }