mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 14:41:39 +08:00
Centralized IP Handler (#2624)
This commit is contained in:
parent
023871ef86
commit
8cc207b139
|
@ -54,7 +54,7 @@ class CreateDiscussionController extends AbstractCreateController
|
|||
protected function data(ServerRequestInterface $request, Document $document)
|
||||
{
|
||||
$actor = $request->getAttribute('actor');
|
||||
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
|
||||
$ipAddress = $request->getAttribute('ipAddress');
|
||||
|
||||
$discussion = $this->bus->dispatch(
|
||||
new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress)
|
||||
|
|
|
@ -55,7 +55,7 @@ class CreatePostController extends AbstractCreateController
|
|||
$actor = $request->getAttribute('actor');
|
||||
$data = Arr::get($request->getParsedBody(), 'data', []);
|
||||
$discussionId = Arr::get($data, 'relationships.discussion.data.id');
|
||||
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
|
||||
$ipAddress = $request->getAttribute('ipAddress');
|
||||
|
||||
$post = $this->bus->dispatch(
|
||||
new PostReply($discussionId, $actor, $data, $ipAddress)
|
||||
|
|
|
@ -55,6 +55,7 @@ class InstalledApp implements AppInterface
|
|||
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
$pipe->pipe(new HttpMiddleware\ProcessIp());
|
||||
$pipe->pipe(new BasePath($this->basePath()));
|
||||
$pipe->pipe(new OriginalMessages);
|
||||
$pipe->pipe(
|
||||
|
|
26
src/Http/Middleware/ProcessIp.php
Normal file
26
src/Http/Middleware/ProcessIp.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Http\Middleware;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface as Middleware;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
class ProcessIp implements Middleware
|
||||
{
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
|
||||
|
||||
return $handler->handle($request->withAttribute('ipAddress', $ipAddress));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user