Skip to content

Commit

Permalink
cleanup base app
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark4ne committed Feb 19, 2019
1 parent de983b5 commit f136a08
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .const.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ driver = file

[session]
id = nucleon-session-id
driver = files
driver = files
35 changes: 0 additions & 35 deletions app/Core/Models/Viewable.php

This file was deleted.

6 changes: 2 additions & 4 deletions app/Kernels/Cli/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ class Kernel extends CliKernel
];

/**
* Return the Middleware List to load.
* List of Global Middleware to attach onto the application.
*
* @var string[]
*/
protected $middlewares = [
// DebugMiddleware::class
];
protected $middlewares = [];
}
8 changes: 4 additions & 4 deletions app/Kernels/Http/Controllers/ErrorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class ErrorsController extends ControllerBase
{
public function indexAction()
{
$this->response->setStatusCode(500);
$this->response->setStatusCode(500, 'Internal Server Error');

return $this->view->render('errors', 'http5xx');
}

public function http404Action()
{
$this->response->setStatusCode(404);
$this->response->setStatusCode(404, 'Not Found');

return $this->view->render('errors', 'http404');
}
Expand All @@ -32,9 +32,9 @@ public function throwExceptionAction()
trigger_error('warning', E_USER_WARNING);

try {
throw new \Exception('A catched exception');
throw new \Phalcon\Exception('A catched exception', 159);
} catch (\Exception $e) {
throw new \Phalcon\Exception('An uncaught exception', $e->getCode(), $e);
throw new \RuntimeException("that's a white rabbit", 0, $e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
class AuthController extends ControllerBase
{

protected function onConstruct()
{
parent::onConstruct();

$this->middleware(RedirectIfAuthenticated::class)->except(['logout']);
$this->middleware(Csrf::class)->only(['postRegister', 'postLogin']);
}

/**
* Register view.
*
Expand Down
3 changes: 1 addition & 2 deletions app/Kernels/Micro/Controllers/MicroController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Kernels\Micro\Controllers;

//use Neutrino\Http\Controller;
use Phalcon\Mvc\Controller;

class MicroController extends Controller
Expand All @@ -15,4 +14,4 @@ public function indexAction()

return $this->response;
}
}
}
2 changes: 1 addition & 1 deletion resources/views/layouts/template.volt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{% do assets.outputCss('common.css') %}

{# Block for specific css #}
{% do assets.addCss('/css/app.css') %}
{% do assets.addCss('css/app.css') %}
{% block stylesheets %}
{% endblock %}
{# Output other css #}
Expand Down
16 changes: 15 additions & 1 deletion routes/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,35 @@
$frontend->addGet('/register', [
'controller' => 'auth',
'action' => 'register',
'middleware' => [
\App\Kernels\Http\Middleware\RedirectIfAuthenticated::class
]
]);

$frontend->addPost('/register', [
'controller' => 'auth',
'action' => 'postRegister',
'middleware' => [
\App\Kernels\Http\Middleware\RedirectIfAuthenticated::class,
\Neutrino\Http\Middleware\Csrf::class
]
]);

$frontend->addGet('/login', [
'controller' => 'auth',
'action' => 'login',
'middleware' => [
\App\Kernels\Http\Middleware\RedirectIfAuthenticated::class
]
]);

$frontend->addPost('/login', [
'controller' => 'auth',
'action' => 'postLogin',
'middleware' => [
\App\Kernels\Http\Middleware\RedirectIfAuthenticated::class,
\Neutrino\Http\Middleware\Csrf::class
]
]);

$frontend->addGet('/logout', [
Expand All @@ -96,4 +110,4 @@

$backend->addGet('/back/:controller/:action');

$router->mount($backend);
$router->mount($backend);
37 changes: 21 additions & 16 deletions routes/micro.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,34 @@
| Api - Routes
|--------------------------------------------------------------------------
*/
$router->addGet('/api/index', [
'controller' => \App\Kernels\Micro\Controllers\MicroController::class,
'action' => 'indexAction'
]);

$router->addGet('/api/test', function () {
/** @var \App\Kernels\Micro\Kernel $this */
$this->response->setStatusCode(200);

$this->response->setJsonContent(['status' => 'found', 'code' => 200]);

return $this->response;
return $this->response
->setStatusCode(200, 'OK')
->setJsonContent([
'status' => 'found',
'code' => 200
]);
});

$router->addGet('/api/index', [
'controller' => \App\Kernels\Micro\Controllers\MicroController::class,
'action' => 'indexAction'
]);

/*
|--------------------------------------------------------------------------
| Api - NotFound
|--------------------------------------------------------------------------
*/
$router->notFound(function () {
/** @var \App\Kernels\Micro\Kernel $this */
$this->response->setStatusCode(404);

$this->response->setJsonContent(['status' => 'not found', 'code' => 404]);

return $this->response;
return $this->response
->setStatusCode(404, 'Not Found')
->setJsonContent([
'status' => 'not found',
'code' => 404
]);
});

/*
Expand All @@ -81,6 +83,8 @@
return $this->response
->setStatusCode(401, 'Unauthorized')
->setJsonContent([
'status' => 'Unauthorized',
'code' => 401,
'error' => 'Token mismatch',
]);
}
Expand All @@ -92,6 +96,7 @@
return $this->response
->setStatusCode(500, 'Internal Server Error')
->setJsonContent([
'error' => 'Internal Server Error',
'status' => 'Internal Server Error',
'code' => 500,
]);
});

0 comments on commit f136a08

Please sign in to comment.