mirror of
https://github.com/flarum/core.git
synced 2025-10-22 04:06:37 +02:00
Refactor Flarum\Web and Flarum\Admin
- In order to be consistent with the Ember/LESS naming scheme, renamed Flarum\Web to Flarum\Forum. - Moved common classes into Flarum\Support so that Flarum\Admin doesn’t depend on Flarum\Forum. Also moved Actor into Flarum\Support as it doesn’t belong in the domain.
This commit is contained in:
13
src/Forum/Actions/BaseAction.php
Normal file
13
src/Forum/Actions/BaseAction.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php namespace Flarum\Forum\Actions;
|
||||
|
||||
use Flarum\Support\Action;
|
||||
use Flarum\Forum\Events\CommandWillBeDispatched;
|
||||
|
||||
abstract class BaseAction extends Action
|
||||
{
|
||||
protected function dispatch($command, $params = [])
|
||||
{
|
||||
event(new CommandWillBeDispatched($command, $params));
|
||||
return $this->bus->dispatch($command);
|
||||
}
|
||||
}
|
30
src/Forum/Actions/ConfirmAction.php
Normal file
30
src/Forum/Actions/ConfirmAction.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php namespace Flarum\Forum\Actions;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Flarum\Core\Commands\ConfirmEmailCommand;
|
||||
use Flarum\Core\Commands\GenerateAccessTokenCommand;
|
||||
use Flarum\Core\Exceptions\InvalidConfirmationTokenException;
|
||||
|
||||
class ConfirmAction extends BaseAction
|
||||
{
|
||||
use MakesRememberCookie;
|
||||
|
||||
public function handle(Request $request, $routeParams = [])
|
||||
{
|
||||
try {
|
||||
$userId = array_get($routeParams, 'id');
|
||||
$token = array_get($routeParams, 'token');
|
||||
$command = new ConfirmEmailCommand($userId, $token);
|
||||
$user = $this->dispatch($command);
|
||||
} catch (InvalidConfirmationTokenException $e) {
|
||||
return 'Invalid confirmation token';
|
||||
}
|
||||
|
||||
$command = new GenerateAccessTokenCommand($user->id);
|
||||
$token = $this->dispatch($command);
|
||||
|
||||
return redirect('/')
|
||||
->withCookie($this->makeRememberCookie($token->id))
|
||||
->with('alert', ['type' => 'success', 'message' => 'Thanks for confirming!']);
|
||||
}
|
||||
}
|
56
src/Forum/Actions/IndexAction.php
Normal file
56
src/Forum/Actions/IndexAction.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php namespace Flarum\Forum\Actions;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Session;
|
||||
use Auth;
|
||||
use Cookie;
|
||||
use Config;
|
||||
use View;
|
||||
|
||||
class IndexAction extends BaseAction
|
||||
{
|
||||
public function handle(Request $request, $params = [])
|
||||
{
|
||||
$config = [
|
||||
'modulePrefix' => 'flarum-forum',
|
||||
'environment' => 'production',
|
||||
'baseURL' => '/',
|
||||
'apiURL' => '/api',
|
||||
'locationType' => 'hash',
|
||||
'EmberENV' => [],
|
||||
'APP' => [],
|
||||
'forumTitle' => Config::get('flarum::forum_title', 'Flarum Demo Forum'),
|
||||
'welcomeDescription' => 'Flarum is now at a point where you can have basic conversations, so here is a little demo for you to break. <a href="http://demo.flarum.org/#/1/welcome-to-the-first-public-demo-of-flarum">Learn more »</a>'
|
||||
];
|
||||
$data = [];
|
||||
$session = [];
|
||||
$alert = Session::get('alert');
|
||||
|
||||
if (($user = $this->actor->getUser()) && $user->exists) {
|
||||
$session = [
|
||||
'userId' => $user->id,
|
||||
'token' => Cookie::get('flarum_remember')
|
||||
];
|
||||
|
||||
$response = $this->callAction('Flarum\Api\Actions\Users\ShowAction', ['id' => $user->id]);
|
||||
$response = $response->getData();
|
||||
|
||||
$data = [$response->data];
|
||||
if (isset($response->included)) {
|
||||
$data = array_merge($data, $response->included);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return View::make('flarum.forum::index')
|
||||
->with('title', Config::get('flarum::forum_title', 'Flarum Demo Forum'))
|
||||
->with('styles', app('flarum.forum.assetManager')->getCSSFiles())
|
||||
->with('scripts', app('flarum.forum.assetManager')->getJSFiles())
|
||||
->with('config', $config)
|
||||
->with('content', '')
|
||||
->with('data', $data)
|
||||
->with('session', $session)
|
||||
->with('alert', $alert);
|
||||
}
|
||||
}
|
31
src/Forum/Actions/LoginAction.php
Normal file
31
src/Forum/Actions/LoginAction.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php namespace Flarum\Forum\Actions;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Flarum\Forum\Events\UserLoggedIn;
|
||||
use Flarum\Core\Repositories\UserRepositoryInterface;
|
||||
|
||||
class LoginAction extends BaseAction
|
||||
{
|
||||
use MakesRememberCookie;
|
||||
|
||||
protected $users;
|
||||
|
||||
public function __construct(UserRepositoryInterface $users)
|
||||
{
|
||||
$this->users = $users;
|
||||
}
|
||||
|
||||
public function handle(Request $request, $routeParams = [])
|
||||
{
|
||||
$response = $this->callAction('Flarum\Api\Actions\TokenAction', $request->only('identification', 'password'));
|
||||
|
||||
$data = $response->getData();
|
||||
if (! empty($data->token)) {
|
||||
$response->withCookie($this->makeRememberCookie($data->token));
|
||||
|
||||
event(new UserLoggedIn($this->users->findOrFail($data->userId), $data->token));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
26
src/Forum/Actions/LogoutAction.php
Normal file
26
src/Forum/Actions/LogoutAction.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php namespace Flarum\Forum\Actions;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Flarum\Forum\Events\UserLoggedOut;
|
||||
use Cookie;
|
||||
|
||||
class LogoutAction extends BaseAction
|
||||
{
|
||||
public function handle(Request $request, $params = [])
|
||||
{
|
||||
$user = $this->actor->getUser();
|
||||
|
||||
if ($user->exists) {
|
||||
$user->accessTokens()->delete();
|
||||
|
||||
event(new UserLoggedOut($user));
|
||||
}
|
||||
|
||||
return redirect('')->withCookie($this->makeForgetCookie());
|
||||
}
|
||||
|
||||
public function makeForgetCookie()
|
||||
{
|
||||
return Cookie::forget('flarum_remember');
|
||||
}
|
||||
}
|
11
src/Forum/Actions/MakesRememberCookie.php
Normal file
11
src/Forum/Actions/MakesRememberCookie.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php namespace Flarum\Forum\Actions;
|
||||
|
||||
use Cookie;
|
||||
|
||||
trait MakesRememberCookie
|
||||
{
|
||||
protected function makeRememberCookie($token)
|
||||
{
|
||||
return Cookie::forever('flarum_remember', $token);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user