error pages
This commit is contained in:
parent
8811b863d8
commit
8f741b19b5
23
app/App.php
23
app/App.php
|
@ -84,7 +84,7 @@ class App extends Application
|
||||||
*/
|
*/
|
||||||
public function getResumeSchema()
|
public function getResumeSchema()
|
||||||
{
|
{
|
||||||
return $this->getDataDirectory() . '/resume.schema.json';
|
return $this->getDataDirectory() . '/schema/schema.v1.json';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogDirectory()
|
public function getLogDirectory()
|
||||||
|
@ -129,7 +129,18 @@ class App extends Application
|
||||||
} else {
|
} else {
|
||||||
$matches = 'Available methods are unknown.';
|
$matches = 'Available methods are unknown.';
|
||||||
}
|
}
|
||||||
$message = json_encode(['status' => 'error', 'message' => 'Method not allowed', 'allowedMethods' => $matches, 'requestedMethod' => $request->getMethod(), 'code' => $code]);
|
$message = [
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Method not allowed',
|
||||||
|
'allowedMethods' => $matches,
|
||||||
|
'requestedMethod' => $request->getMethod(),
|
||||||
|
'code' => $code,
|
||||||
|
];
|
||||||
|
if($request->isXmlHttpRequest()) {
|
||||||
|
$message = json_encode($message);
|
||||||
|
} else {
|
||||||
|
$message = $this->renderView('error.405.html.twig', $message);
|
||||||
|
}
|
||||||
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::WARNING);
|
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::WARNING);
|
||||||
break;
|
break;
|
||||||
case 500:
|
case 500:
|
||||||
|
@ -137,7 +148,13 @@ class App extends Application
|
||||||
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::CRITICAL);
|
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::CRITICAL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$message = json_encode(['status' => 'error', 'message' => $e->getMessage(), 'code' => $code]);
|
$message = ['status' => 'error', 'message' => $e->getMessage(), 'code' => $code, 'requestUri' => $request->getRequestUri()];
|
||||||
|
if($request->isXmlHttpRequest()) {
|
||||||
|
$message = json_decode($message);
|
||||||
|
} else {
|
||||||
|
$message = $this->renderView('error.html.twig', $message);
|
||||||
|
}
|
||||||
|
|
||||||
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::ERROR);
|
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::ERROR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,3 +14,4 @@ app:
|
||||||
smtp_port: 465
|
smtp_port: 465
|
||||||
smtp_user: eric@rewiv.com
|
smtp_user: eric@rewiv.com
|
||||||
smtp_password: 'P*8ic32!100023&p'
|
smtp_password: 'P*8ic32!100023&p'
|
||||||
|
from_email: no-reply@rewiv.com
|
||||||
|
|
|
@ -2,8 +2,9 @@ app:
|
||||||
debug: true
|
debug: true
|
||||||
environment: dev
|
environment: dev
|
||||||
title: R. Eric Wheeler | Resume
|
title: R. Eric Wheeler | Resume
|
||||||
email: eric@rewiv.com
|
email: email@example.com
|
||||||
phone: 510-646-2135
|
from_email: no-reply@example.com
|
||||||
|
phone: 510-555-5555
|
||||||
schema: https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json
|
schema: https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json
|
||||||
captcha: true
|
captcha: true
|
||||||
captcha_sitekey: 6LcvmSQTAAAAAMmf9w6mhCbpdLvknuD9SGVHT0q-
|
captcha_sitekey: 6LcvmSQTAAAAAMmf9w6mhCbpdLvknuD9SGVHT0q-
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}HTTP 405{% endblock %}
|
||||||
|
{% block body %}
|
||||||
|
<div class="uk-container uk-container-center">
|
||||||
|
|
||||||
|
<h1 class="uk-article-title">HTTP 405</h1>
|
||||||
|
<p class="uk-text-lead">{{ message }} [{{ requestedMethod }}]</p>
|
||||||
|
<img class="uk-img-preserve uk-thumbnail uk-thumbnail-medium" src="https://http.cat/405" alt="Error 405" />
|
||||||
|
<p>Return to the home <a href="/" title="Home page">page</a>.</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,13 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}HTTP {{ code }}{% endblock %}
|
||||||
|
{% block body %}
|
||||||
|
<div class="uk-container uk-container-center">
|
||||||
|
|
||||||
|
<h1 class="uk-article-title">HTTP {{ code }}</h1>
|
||||||
|
<p class="uk-text-lead">{{ message }} / {{ requestUri }}</p>
|
||||||
|
<img class="uk-img-preserve uk-thumbnail uk-thumbnail-medium" src="https://http.cat/{{ code }}" alt="HTTP Error {{ code }}" />
|
||||||
|
<p>Return to the home <a href="/" title="Home page">page</a>.</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -26,6 +26,7 @@ namespace Sikofitt\Controller;
|
||||||
|
|
||||||
|
|
||||||
use ReCaptcha\ReCaptcha;
|
use ReCaptcha\ReCaptcha;
|
||||||
|
use Sikofitt\Form\Type\ContactType;
|
||||||
use Silex\Api\ControllerProviderInterface;
|
use Silex\Api\ControllerProviderInterface;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
@ -36,6 +37,7 @@ use Symfony\Component\Validator\Constraints\Email;
|
||||||
use Symfony\Component\Validator\Constraints\EqualTo;
|
use Symfony\Component\Validator\Constraints\EqualTo;
|
||||||
use Symfony\Component\Validator\Constraints\Length;
|
use Symfony\Component\Validator\Constraints\Length;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
use Symfony\Component\Validator\Constraints\Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ApiControllerProvider
|
* Class ApiControllerProvider
|
||||||
|
@ -85,6 +87,7 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
||||||
'message' => 'Name must not be blank.',
|
'message' => 'Name must not be blank.',
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
new Type('string'),
|
||||||
],
|
],
|
||||||
'email' => [
|
'email' => [
|
||||||
new Email([
|
new Email([
|
||||||
|
@ -93,6 +96,7 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
||||||
new NotBlank([
|
new NotBlank([
|
||||||
'message' => 'Email must not be blank.',
|
'message' => 'Email must not be blank.',
|
||||||
]),
|
]),
|
||||||
|
new Type('string'),
|
||||||
],
|
],
|
||||||
'message' => [
|
'message' => [
|
||||||
new Length([
|
new Length([
|
||||||
|
@ -102,9 +106,11 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
||||||
new NotBlank([
|
new NotBlank([
|
||||||
'message' => 'Message must not be blank',
|
'message' => 'Message must not be blank',
|
||||||
]),
|
]),
|
||||||
|
new Type('string'),
|
||||||
],
|
],
|
||||||
'_token' => [
|
'_token' => [
|
||||||
new EqualTo(['value' => $csrf, 'message' => 'Invalid token.']),
|
new EqualTo(['value' => $csrf, 'message' => 'Invalid token.']),
|
||||||
|
new Type('string'),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
@ -136,34 +142,32 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
||||||
|
|
||||||
$contactFormName = $contactFormData['contact']['name'];
|
$contactFormName = $contactFormData['contact']['name'];
|
||||||
$contactFormEmail = $contactFormData['contact']['email'];
|
$contactFormEmail = $contactFormData['contact']['email'];
|
||||||
$contactFormMessage = $contactFormData['contact']['message'];
|
$contactFormMessage = sprintf("%s\n\nEmail : %s <%s>", $contactFormData['contact']['message'], $contactFormName, $contactFormEmail);
|
||||||
$message = sprintf("%s\n\nEmail : %s <%s>", $contactFormMessage, $contactFormName, $contactFormEmail);
|
|
||||||
$failures = '';
|
$failures = '';
|
||||||
|
$message = \Swift_Message::newInstance()
|
||||||
$sent = $app['mailer']->send(\Swift_Message::newInstance()
|
|
||||||
->setSubject('[Resume] Message')
|
->setSubject('[Resume] Message')
|
||||||
->setFrom(['no-reply@rewiv.com' => $contactFormName])
|
->setFrom([$app->config('app.from_email') => $contactFormName])
|
||||||
->setTo([$app->config('app.email') => 'No-Reply'])
|
->setTo([$app->config('app.email') => 'No-Reply'])
|
||||||
->setReplyTo([$contactFormEmail => $contactFormName])
|
->setReplyTo([$contactFormEmail => $contactFormName])
|
||||||
->setBody($message)
|
->setBody($contactFormMessage);
|
||||||
, $failures);
|
|
||||||
if($sent > 0) {
|
$sent = $app['mailer']->send($message, $failures);
|
||||||
|
if ($sent > 0) {
|
||||||
$request->getSession()->remove('_csrf/contact');
|
$request->getSession()->remove('_csrf/contact');
|
||||||
|
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'message' => 'Message successfully sent.',
|
'message' => 'Message successfully sent.',
|
||||||
'code' => 201,
|
'code' => 201,
|
||||||
'data' => $contactFormData,
|
'data' => $contactFormData,
|
||||||
'failed' => $failures,
|
|
||||||
'sent' => $sent,
|
'sent' => $sent,
|
||||||
], 200);
|
], 201);
|
||||||
|
}
|
||||||
} else {
|
else {
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'message' => 'There was an error sending the message.',
|
'message' => 'There was an error sending the message.',
|
||||||
'code' => 255,
|
'code' => 255,
|
||||||
'data' => $contactFormData,
|
|
||||||
'failed' => $failures,
|
'failed' => $failures,
|
||||||
'sent' => $sent,
|
'sent' => $sent,
|
||||||
], 255);
|
], 255);
|
||||||
|
@ -171,22 +175,11 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})->method('GET|POST')->bind('api_message');
|
})->method('POST')->bind('api_message');
|
||||||
|
$controllers->post('/v1/update', function(Request $request) use ($app) {
|
||||||
|
|
||||||
$controllers->get('/v1/emailTest', function (Request $request) use ($app) {
|
return new JsonResponse($app->decodeFile($app->getResumeSchema()));
|
||||||
try {
|
})->bind('api_update');
|
||||||
$app->mail(\Swift_Message::newInstance()
|
|
||||||
->setSubject('[Resume] Message')
|
|
||||||
->setFrom(['eric@rewiv.com' => 'Eric'])
|
|
||||||
->setTo('eric@ericwheeler.net')
|
|
||||||
->setBody('Testing message.')
|
|
||||||
);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
dump($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response('Hello');
|
|
||||||
});
|
|
||||||
|
|
||||||
$controllers->post('/v1/captcha', function (Request $request) use ($app) {
|
$controllers->post('/v1/captcha', function (Request $request) use ($app) {
|
||||||
$captcha = new ReCaptcha('6LcvmSQTAAAAAITkvYJjgLar1LqGGLz-ic0ZMiXo');
|
$captcha = new ReCaptcha('6LcvmSQTAAAAAITkvYJjgLar1LqGGLz-ic0ZMiXo');
|
||||||
|
|
|
@ -15,6 +15,7 @@ use ReCaptcha\ReCaptcha;
|
||||||
use Sikofitt\Form\Type\ContactType;
|
use Sikofitt\Form\Type\ContactType;
|
||||||
use Silex\Api\ControllerProviderInterface;
|
use Silex\Api\ControllerProviderInterface;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
|
use Symfony\Component\Form\Form;
|
||||||
use Symfony\Component\Form\FormFactory;
|
use Symfony\Component\Form\FormFactory;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
|
@ -34,6 +34,6 @@ trait JsonFileTrait
|
||||||
|
|
||||||
public function decodeFile($file, $schema = null)
|
public function decodeFile($file, $schema = null)
|
||||||
{
|
{
|
||||||
return $this['json.decode']->decodeFile($file, $file, $schema);
|
return $this['json.decode']->decodeFile($file, $schema);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,14 @@ jq(document).ready(function (jq) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}); // Phone form
|
}); // Phone form
|
||||||
jq('form[name=contact]').on('submit', function(event) {
|
jq('form[name=contact]').on('submit', function (event) {
|
||||||
contactModal = UIkit.modal('#spinner-modal', { modal:false, center:true, bgclose:false });
|
contactModal = UIkit.modal('#spinner-modal', {modal: false, center: true, bgclose: false});
|
||||||
contactModal.show();
|
contactModal.show();
|
||||||
jq.post(jq(this).attr('action'), jq(this).serialize(), function(response) {
|
jq.post(jq(this).attr('action'), jq(this).serialize(), function (response) {
|
||||||
if(response.status !== 'success') {
|
if (response.status !== 'success') {
|
||||||
resp = response;
|
resp = response;
|
||||||
jq('#' + response.id).addClass('uk-form-danger');
|
jq('#' + response.id).addClass('uk-form-danger');
|
||||||
UIkit.notify('<i class="uk-icon uk-icon-frown-o uk-icon-justify uk-margin-right"></i>' + response.message + ' ('+response.code+')</div>', {
|
UIkit.notify('<i class="uk-icon uk-icon-frown-o uk-icon-justify uk-margin-right"></i>' + response.message + ' (' + response.code + ')</div>', {
|
||||||
pos: 'top-center',
|
pos: 'top-center',
|
||||||
status: 'danger'
|
status: 'danger'
|
||||||
});
|
});
|
||||||
|
@ -58,22 +58,22 @@ jq(document).ready(function (jq) {
|
||||||
jq('a[href="#contact-form-wrapper"]').replaceWith('eric@ericwheeler.net');
|
jq('a[href="#contact-form-wrapper"]').replaceWith('eric@ericwheeler.net');
|
||||||
}
|
}
|
||||||
|
|
||||||
}).fail(function(response, code, resp) {
|
}).fail(function (response) {
|
||||||
contactModal.hide();
|
contactModal.hide();
|
||||||
resp = response;
|
UIkit.notify('<i class="uk-icon uk-icon-frown-o uk-icon-justify uk-margin-right"></i>' + response.message + ' (' + response.status + ')</div>', {
|
||||||
console.log(response);
|
|
||||||
UIkit.notify('<i class="uk-icon uk-icon-frown-o uk-icon-justify uk-margin-right"></i>'+ response.message + ' ('+response.status+')</div>', {
|
|
||||||
pos: 'top-center',
|
pos: 'top-center',
|
||||||
status: 'danger'
|
status: 'danger'
|
||||||
});
|
});
|
||||||
}).done(function () {
|
}).done(function () {
|
||||||
contactModal.hide();
|
contactModal.hide();
|
||||||
|
}).always(function () {
|
||||||
|
contactModal.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
jq('form[name=contact] input, form[name=contact] textarea').on('focus', function() {
|
jq('form[name=contact] input, form[name=contact] textarea').on('focus', function () {
|
||||||
if(jq(this).hasClass('uk-form-danger')) {
|
if (jq(this).hasClass('uk-form-danger')) {
|
||||||
jq(this).removeClass('uk-form-danger');
|
jq(this).removeClass('uk-form-danger');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue