error pages
This commit is contained in:
parent
8811b863d8
commit
8f741b19b5
25
app/App.php
25
app/App.php
|
@ -84,7 +84,7 @@ class App extends Application
|
|||
*/
|
||||
public function getResumeSchema()
|
||||
{
|
||||
return $this->getDataDirectory() . '/resume.schema.json';
|
||||
return $this->getDataDirectory() . '/schema/schema.v1.json';
|
||||
}
|
||||
|
||||
public function getLogDirectory()
|
||||
|
@ -129,15 +129,32 @@ class App extends Application
|
|||
} else {
|
||||
$matches = 'Available methods are unknown.';
|
||||
}
|
||||
$message = json_encode(['status' => 'error', 'message' => 'Method not allowed', 'allowedMethods' => $matches, 'requestedMethod' => $request->getMethod(), 'code' => $code]);
|
||||
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::WARNING);
|
||||
$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);
|
||||
break;
|
||||
case 500:
|
||||
$message = json_encode(['status' => 'error', 'message' => 'Critical Error', 'code' => $code]);
|
||||
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::CRITICAL);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -14,3 +14,4 @@ app:
|
|||
smtp_port: 465
|
||||
smtp_user: eric@rewiv.com
|
||||
smtp_password: 'P*8ic32!100023&p'
|
||||
from_email: no-reply@rewiv.com
|
||||
|
|
|
@ -2,8 +2,9 @@ app:
|
|||
debug: true
|
||||
environment: dev
|
||||
title: R. Eric Wheeler | Resume
|
||||
email: eric@rewiv.com
|
||||
phone: 510-646-2135
|
||||
email: email@example.com
|
||||
from_email: no-reply@example.com
|
||||
phone: 510-555-5555
|
||||
schema: https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json
|
||||
captcha: true
|
||||
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 Sikofitt\Form\Type\ContactType;
|
||||
use Silex\Api\ControllerProviderInterface;
|
||||
use Silex\Application;
|
||||
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\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Type;
|
||||
|
||||
/**
|
||||
* Class ApiControllerProvider
|
||||
|
@ -85,6 +87,7 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
|||
'message' => 'Name must not be blank.',
|
||||
]
|
||||
),
|
||||
new Type('string'),
|
||||
],
|
||||
'email' => [
|
||||
new Email([
|
||||
|
@ -93,6 +96,7 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
|||
new NotBlank([
|
||||
'message' => 'Email must not be blank.',
|
||||
]),
|
||||
new Type('string'),
|
||||
],
|
||||
'message' => [
|
||||
new Length([
|
||||
|
@ -102,9 +106,11 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
|||
new NotBlank([
|
||||
'message' => 'Message must not be blank',
|
||||
]),
|
||||
new Type('string'),
|
||||
],
|
||||
'_token' => [
|
||||
new EqualTo(['value' => $csrf, 'message' => 'Invalid token.']),
|
||||
new Type('string'),
|
||||
],
|
||||
]
|
||||
),
|
||||
|
@ -136,57 +142,44 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
|||
|
||||
$contactFormName = $contactFormData['contact']['name'];
|
||||
$contactFormEmail = $contactFormData['contact']['email'];
|
||||
$contactFormMessage = $contactFormData['contact']['message'];
|
||||
$message = sprintf("%s\n\nEmail : %s <%s>", $contactFormMessage, $contactFormName, $contactFormEmail);
|
||||
$contactFormMessage = sprintf("%s\n\nEmail : %s <%s>", $contactFormData['contact']['message'], $contactFormName, $contactFormEmail);
|
||||
$failures = '';
|
||||
|
||||
$sent = $app['mailer']->send(\Swift_Message::newInstance()
|
||||
->setSubject('[Resume] Message')
|
||||
->setFrom(['no-reply@rewiv.com' => $contactFormName])
|
||||
->setTo([$app->config('app.email') => 'No-Reply'])
|
||||
->setReplyTo([$contactFormEmail => $contactFormName])
|
||||
->setBody($message)
|
||||
, $failures);
|
||||
if($sent > 0) {
|
||||
$request->getSession()->remove('_csrf/contact');
|
||||
return new JsonResponse([
|
||||
'status' => 'success',
|
||||
'message' => 'Message successfully sent.',
|
||||
'code' => 201,
|
||||
'data' => $contactFormData,
|
||||
'failed' => $failures,
|
||||
'sent' => $sent,
|
||||
], 200);
|
||||
|
||||
} else {
|
||||
return new JsonResponse([
|
||||
'status' => 'error',
|
||||
'message' => 'There was an error sending the message.',
|
||||
'code' => 255,
|
||||
'data' => $contactFormData,
|
||||
'failed' => $failures,
|
||||
'sent' => $sent,
|
||||
], 255);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
})->method('GET|POST')->bind('api_message');
|
||||
|
||||
$controllers->get('/v1/emailTest', function (Request $request) use ($app) {
|
||||
try {
|
||||
$app->mail(\Swift_Message::newInstance()
|
||||
$message = \Swift_Message::newInstance()
|
||||
->setSubject('[Resume] Message')
|
||||
->setFrom(['eric@rewiv.com' => 'Eric'])
|
||||
->setTo('eric@ericwheeler.net')
|
||||
->setBody('Testing message.')
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
dump($e->getMessage());
|
||||
->setFrom([$app->config('app.from_email') => $contactFormName])
|
||||
->setTo([$app->config('app.email') => 'No-Reply'])
|
||||
->setReplyTo([$contactFormEmail => $contactFormName])
|
||||
->setBody($contactFormMessage);
|
||||
|
||||
$sent = $app['mailer']->send($message, $failures);
|
||||
if ($sent > 0) {
|
||||
$request->getSession()->remove('_csrf/contact');
|
||||
|
||||
return new JsonResponse([
|
||||
'status' => 'success',
|
||||
'message' => 'Message successfully sent.',
|
||||
'code' => 201,
|
||||
'data' => $contactFormData,
|
||||
'sent' => $sent,
|
||||
], 201);
|
||||
}
|
||||
else {
|
||||
return new JsonResponse([
|
||||
'status' => 'error',
|
||||
'message' => 'There was an error sending the message.',
|
||||
'code' => 255,
|
||||
'failed' => $failures,
|
||||
'sent' => $sent,
|
||||
], 255);
|
||||
}
|
||||
}
|
||||
|
||||
return new Response('Hello');
|
||||
});
|
||||
|
||||
})->method('POST')->bind('api_message');
|
||||
$controllers->post('/v1/update', function(Request $request) use ($app) {
|
||||
|
||||
return new JsonResponse($app->decodeFile($app->getResumeSchema()));
|
||||
})->bind('api_update');
|
||||
|
||||
$controllers->post('/v1/captcha', function (Request $request) use ($app) {
|
||||
$captcha = new ReCaptcha('6LcvmSQTAAAAAITkvYJjgLar1LqGGLz-ic0ZMiXo');
|
||||
|
|
|
@ -15,6 +15,7 @@ use ReCaptcha\ReCaptcha;
|
|||
use Sikofitt\Form\Type\ContactType;
|
||||
use Silex\Api\ControllerProviderInterface;
|
||||
use Silex\Application;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\Form\FormFactory;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
|
|
@ -34,6 +34,6 @@ trait JsonFileTrait
|
|||
|
||||
public function decodeFile($file, $schema = null)
|
||||
{
|
||||
return $this['json.decode']->decodeFile($file, $file, $schema);
|
||||
return $this['json.decode']->decodeFile($file, $schema);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ jq(document).ready(function (jq) {
|
|||
});
|
||||
} else if (true === data.valid) {
|
||||
var divRoot = jq('<div />'),
|
||||
h1 = jq('<h1 />'),
|
||||
href = jq('<a />'),
|
||||
phone = jq('.hidden-phone');
|
||||
href
|
||||
h1 = jq('<h1 />'),
|
||||
href = jq('<a />'),
|
||||
phone = jq('.hidden-phone');
|
||||
href
|
||||
.attr('href', 'tel:' + data.message.phone)
|
||||
.text(data.message.phone);
|
||||
|
||||
|
@ -33,14 +33,14 @@ jq(document).ready(function (jq) {
|
|||
}
|
||||
});
|
||||
}); // Phone form
|
||||
jq('form[name=contact]').on('submit', function(event) {
|
||||
contactModal = UIkit.modal('#spinner-modal', { modal:false, center:true, bgclose:false });
|
||||
jq('form[name=contact]').on('submit', function (event) {
|
||||
contactModal = UIkit.modal('#spinner-modal', {modal: false, center: true, bgclose: false});
|
||||
contactModal.show();
|
||||
jq.post(jq(this).attr('action'), jq(this).serialize(), function(response) {
|
||||
if(response.status !== 'success') {
|
||||
jq.post(jq(this).attr('action'), jq(this).serialize(), function (response) {
|
||||
if (response.status !== 'success') {
|
||||
resp = response;
|
||||
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',
|
||||
status: 'danger'
|
||||
});
|
||||
|
@ -52,28 +52,28 @@ jq(document).ready(function (jq) {
|
|||
status: 'success'
|
||||
});
|
||||
var $wrapper = jq('#contact-form'),
|
||||
$button = jq('<button class="uk-modal-close uk-button uk-button-massive uk-button-primary uk-align-center" type="button">Close</button>'),
|
||||
$thankYouText = jq('<p class="uk-text-lead uk-text-center">Thank you for your message.</p><p class="uk-text-center">I will get back to you as soon as possible.</p>');
|
||||
$button = jq('<button class="uk-modal-close uk-button uk-button-massive uk-button-primary uk-align-center" type="button">Close</button>'),
|
||||
$thankYouText = jq('<p class="uk-text-lead uk-text-center">Thank you for your message.</p><p class="uk-text-center">I will get back to you as soon as possible.</p>');
|
||||
$wrapper.empty().append($thankYouText).append($button);
|
||||
jq('a[href="#contact-form-wrapper"]').replaceWith('eric@ericwheeler.net');
|
||||
}
|
||||
|
||||
}).fail(function(response, code, resp) {
|
||||
}).fail(function (response) {
|
||||
contactModal.hide();
|
||||
resp = response;
|
||||
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>', {
|
||||
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',
|
||||
status: 'danger'
|
||||
});
|
||||
}).done(function () {
|
||||
}).done(function () {
|
||||
contactModal.hide();
|
||||
}).always(function () {
|
||||
contactModal.hide();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
jq('form[name=contact] input, form[name=contact] textarea').on('focus', function() {
|
||||
if(jq(this).hasClass('uk-form-danger')) {
|
||||
jq('form[name=contact] input, form[name=contact] textarea').on('focus', function () {
|
||||
if (jq(this).hasClass('uk-form-danger')) {
|
||||
jq(this).removeClass('uk-form-danger');
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue