Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
proper demo issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Jul 23, 2018
1 parent 2d2904b commit 3a3b035
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 96 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Selami\\Auth\\Controller\\": "src/apps/www/middlewares/Auth/controllers",
"Selami\\Authentication\\Controller\\": "src/apps/www/middlewares/Authentication/controllers",
"Selami\\App\\Controller\\": "src/apps/www/middlewares/App/controllers",
"Selami\\Middleware\\": "src/apps/www/middlewares",
"Selami\\AppFactories\\": "src/factories",
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config/autoload/dependencies.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
use Selami\View\ViewInterface as SelamiView;
use Twig_Environment as TwigEnvironment;
use Selami\Factories;
use Selami\AppFactories;
use Selami\AppFactories;
use Selami\Foundation\App as SelamiApplication;

return [
'dependencies' => [
'factories' => [
ServerRequestInterface::class => Factories\ServerRequestFactory::class,
SelamiApplication::class => AppFactories\SelamiAppFactory::class,
SelamiAuth::class => AppFactories\SelamiAuthFactory::class,
Router::class => Factories\RouterFactory::class,
TwigEnvironment::class => Factories\TwigFactory::class,
SelamiView::class => Factories\SelamiViewTwigFactory::class
Expand Down
36 changes: 28 additions & 8 deletions src/apps/www/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
<?php
declare(strict_types=1);
define('APP_DIR', __DIR__);
$_appLang = 'en';
if (strpos($_SERVER['REQUEST_URI'], '/tr') === 0) {
$_appLang = 'tr';
}
define('RUNTIME_LANG', $_appLang);
require dirname(__DIR__) . '/bootstrap.php';

use Zend\Diactoros\Response;
use Zend\Diactoros\Server;
use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\Uri;

use Psr\Http\Message\ServerRequestInterface;

use Psr\Http\Message\ResponseInterface;
use function Zend\Stratigility\middleware;
use function Zend\Stratigility\path;
use function Zend\Stratigility\doublePassMiddleware;

use Selami\Middleware\Auth\Middleware as AuthMiddleware;
use Selami\Middleware\Authorization\Middleware as AuthorizationMiddleware;
use Selami\Middleware\Authentication\Middleware as AuthenticationMiddleware;
use Selami\Middleware\App\Middleware as ApplicationMiddleware;

use Symfony\Component\HttpFoundation\Session\Session;

$container = include SYS_DIR . '/config/container.php';

$app = new MiddlewarePipe();
$server = Server::createServer([$app, 'handle'], $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);

// AUTH
$app->pipe(doublePassMiddleware(function (ServerRequestInterface $request, $response, $next) {
$request = $request->withAttribute('selamiAuth', 'pass');
$response = $next($request, $response->withHeader('X-Auth', 'Pass'));
// Check Authorization
$app->pipe(doublePassMiddleware(function (ServerRequestInterface $request, ResponseInterface $response, $next) use ($container) {
/**
* @var $session Session
*/
$session = $container->get(Session::class);
$loggedUserId = $session->get('logged_user_id');
$urlPath = $request->getUri()->getPath();
if ($loggedUserId === null && strpos($urlPath, '/auth') !== 0) {
return $response->withHeader('Location', '/auth')->withStatus(301);
}
if ($loggedUserId !== null) {
$request = $request->withAttribute('loggedUserId', $loggedUserId);
}
$response = $next($request, $response);
return $response;
}, new Response()));

// Auth Middleware
$app->pipe(path('/auth', new AuthMiddleware($container)));
// Authentication Middleware
$app->pipe(path('/auth', new AuthenticationMiddleware($container)));

// APP
$app->pipe(new ApplicationMiddleware($container));
Expand Down
6 changes: 5 additions & 1 deletion src/apps/www/middlewares/App/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response;
use Psr\Container\ContainerInterface;
use Selami\Foundation\App as SelamiApplication;

class Middleware implements MiddlewareInterface
{
Expand All @@ -24,8 +25,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
{
$appRoutes = require __DIR__ . '/routes.php';
$this->container->setService('routes', $appRoutes);
//$config = $this->container->get('config');
//$config['app']['cache_file'] = './cache/application.fastroute.cache';
//$this->container->setService('config', $config);
$this->container->setService(ServerRequestInterface::class, $request);
$myApp = $this->container->get('SelamiApplication');
$myApp = $this->container->get(SelamiApplication::class);
return $myApp($request, new Response());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
declare(strict_types=1);


namespace SelamiApp\Controller\Contents;
namespace Selami\App\Controller\Contents;

use Psr\Container\ContainerInterface;
use Selami\Interfaces\Application;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class ContentsController extends Application

public function __construct(ServerRequestInterface $request, Session $session, ?array $args)
{

$this->session = $session;
$this->request = $request;
$this->args = $args;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace SelamiApp\Controller\Contents;
namespace Selami\App\Controller\Contents;

use Selami\Interfaces\Application;

Expand Down
2 changes: 1 addition & 1 deletion src/apps/www/middlewares/App/controllers/Contents/Post.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace SelamiApp\Controller\Contents;
namespace Selami\App\Controller\Contents;

use Selami\Interfaces\Application;

Expand Down
14 changes: 0 additions & 14 deletions src/apps/www/middlewares/Auth/controllers/Auth/NotFound.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/apps/www/middlewares/Auth/routes.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
declare(strict_types=1);

namespace Selami\Middleware\Auth;
use Selami\Foundation\App as SelamiAuth;
namespace Selami\Middleware\Authentication;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response;
use Psr\Container\ContainerInterface;
use Selami\Foundation\App as SelamiApplication;

class Middleware implements MiddlewareInterface
{
Expand All @@ -22,11 +22,20 @@ public function __construct(ContainerInterface $container)

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$urlPath = $request->getUri()->getPath();
//var_dump($urlPath .'<<<-');
$appRoutes = require __DIR__ . '/routes.php';
$config = $this->container->get('config');
$config['app']['cache_file'] = './cache/authentication.fastroute.cache';
$this->container->setAllowOverride(true);
$this->container->setService('config', $config);
$this->container->setService('routes', $appRoutes);
$this->container->setService(ServerRequestInterface::class, $request);
$myApp = $this->container->get('SelamiAuth');
return $myApp($request, new Response());
$this->container->setAllowOverride(false);

$myApp = $this->container->get(SelamiApplication::class);
$response = $myApp($request, new Response());
return $response;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
declare(strict_types=1);


namespace Selami\Auth\Controller;
namespace Selami\Authentication\Controller;

use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
use Selami\Helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
declare(strict_types=1);


namespace Selami\Auth\Controller\Auth;
namespace Selami\Authentication\Controller\Authentication;

use Selami\Auth\Controller\Application;
use Selami\Authentication\Controller\Application;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\HttpFoundation\Session\Session;

abstract class AuthController extends Application
abstract class AuthenticationController extends Application
{

public function __construct(ServerRequestInterface $request, Session $session, ?array $args)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);

namespace Selami\Authentication\Controller\Authentication;

use Selami\Interfaces\Application;
use Selami\Dispatcher;

class Check extends AuthenticationController implements Application
{
public function __invoke() : array
{

return [
'status' => 200,

'data' => $this->getParams()
];
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php
declare(strict_types=1);

namespace Selami\Auth\Controller\Auth;
namespace Selami\Authentication\Controller\Authentication;

use Selami\Interfaces\Application;

class Main extends AuthController implements Application
class Main extends AuthenticationController implements Application
{
public function __invoke() : array
{
return [
'status' => 200,
'meta' => [
'layout' => 'auth'
'layout' => 'authentication'
],
'data' => ['t' => self::class]
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace Selami\Authentication\Controller\Authentication;

use Selami\Interfaces\Application;

class NotFound extends AuthenticationController implements Application
{
public function __invoke() : array
{
var_dump('df');exit;
return [
'status' => 404, 'data' => []
];
}
}
12 changes: 12 additions & 0 deletions src/apps/www/middlewares/Authentication/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);

use Selami\Authentication\Controller;
use Selami\Router;

// Routes are /quth/:route
return [
[Router::GET, '/', Controller\Authentication\Main::class, Router::HTML],
[Router::POST, '/login', Controller\Authentication\Check::class, Router::JSON],
[Router::GET, '/{catchAnythingElse:.+}', Controller\Authentication\NotFound::class, Router::HTML, '404'],
];
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="container text-center">

<form class="form-signin" style="width:300px;margin:0 auto;">
<form class="form-signin" style="width:300px;margin:0 auto;" method="post" action="/auth/login">
<h1 class="h3 mb-3 font-weight-normal">Fake Login Form</h1>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me"> Remember me
Expand Down
Loading

0 comments on commit 3a3b035

Please sign in to comment.