Skip to content

Commit

Permalink
feat: add message on contact page when mail not configured (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud authored Dec 15, 2023
1 parent 4e4dffa commit c751cc7
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/controllers/www/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ protected function setTemplateProperties(array $data = []): void
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$to = (string) Application::getConfig()->get('MAIL_CONTACT_TO');
$posArobase = \mb_strpos($to, '@');
if (!$posArobase || ($posArobase < 1 || $posArobase === \mb_strlen($to) - 1)) {
$this->setTemplateProperties();

$this->data += [$this->inputs['CSRF'] => Session::get('csrf')];

$formContact = new FormHelper();
$formContact->setErrorMessage('Error, could not use this form, "MAIL_CONTACT_TO" env variable is invalid.');
$this->data += ['form-contact' => $formContact];

return $this->sendPage();
}

if ($this->hasSentForm($request, 'POST', $this->inputs, 'error-form-contact')) {
$cleanedParams = $this->treatFormContact($request);
$this->doProcessContact($request, $cleanedParams);
Expand Down
67 changes: 67 additions & 0 deletions tests/tests-invalid-mail-contact-to.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# setup timezone, by default use timezone from php.ini (valid timezones are checked with DateTimeZone::listIdentifiers())
TIMEZONE="UTC"

# specific files to load for setting router, if null it will load all files in folder given in Application constructor
ROUTES=null

# for enabling DEBUG_* parameters
DEBUG=true

# enable error_reporting: show php errors
DEBUG_PHP=true

# keep PSR-7 request object
DEBUG_REQUEST=false

# keep PSR-7 response object
DEBUG_RESPONSE=false

# return saved queries
DEBUG_DATABASE=false

# return all values in Session object
DEBUG_SESSION=false

# return memory usage/limit/percentage
DEBUG_MEMORY=false

# return elapsed time of each Application->run()
DEBUG_RUN_ELAPSED_TIMES=false

# return all files included
DEBUG_INCLUDED_FILES=false

# database
DATABASE_DRIVER=mysql
DATABASE_HOST=127.0.0.1
DATABASE_USER=blueprintue-self-hosted-edition
DATABASE_PASSWORD=blueprintue-self-hosted-edition
DATABASE_NAME=blueprintue-self-hosted-edition
DATABASE_PERSISTENT_CONNECTION=true

# session
SESSION_DRIVER=database
SESSION_ENCRYPT_KEY="1+XaQLUMfd/l6g1pdc/t+K1UiWJSuUY7k8GEjr+MLagmlgilqG8lcHrHc59ad9fo"
SESSION_REMEMBER_NAME="remember_token"
SESSION_REMEMBER_LIFETIME=2592000
SESSION_REMEMBER_PATH="/"
SESSION_REMEMBER_HTTPS=false
SESSION_SAMESITE=Strict

# host
HOST=blueprintue.test
HTTPS=true

# site
SITE_NAME=this_site_name
SITE_BASE_TITLE="This is a base title"
SITE_DESCRIPTION="This is a description"

# anonymous
ANONYMOUS_ID=2

# mail
MAIL_FROM_ADDRESS=[email protected]
MAIL_FROM_NAME=blueprintUE_from_name
MAIL_CONTACT_TO=
MAIL_HEADER_LOGO_PATH="full-logo.png"
19 changes: 19 additions & 0 deletions tests/www/Contact/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ public function testContactGET(): void
$this->doTestNavBarHasNoLinkActive($response);
}

/**
* @throws ApplicationException
* @throws EnvironmentException
* @throws RouterException
*/
public function testContactGETInvalidConfigurationEmail(): void
{
$response = $this->getResponseFromApplication('GET', '/contact/', [], [], [], [], [], [], [], 'tests-invalid-mail-contact-to.env');
$this->doTestHasResponseWithStatusCode($response, 200);
$this->doTestHtmlHead($response, [
'title' => 'Contact us | This is a base title',
'description' => 'Contact&#x20;us'
]);
$this->doTestHtmlBody($response, '<h2 class="block__title">Contact</h2>');
$this->doTestHtmlBody($response, '<div class="block__info block__info--error" data-flash-error-for="form-contact" role="alert">Error, could not use this form, &quot;MAIL_CONTACT_TO&quot; env variable is invalid.</div>');
$this->doTestNavBarIsComplete($response);
$this->doTestNavBarHasNoLinkActive($response);
}

public function dataCases(): array
{
return [
Expand Down

0 comments on commit c751cc7

Please sign in to comment.