mirror of
https://github.com/flarum/core.git
synced 2025-07-30 13:10:24 +02:00
merges 5.5 and master into next-back
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
namespace Flarum\User\Command;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Core\AvatarUploader;
|
||||
use Flarum\Foundation\DispatchEventsTrait;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
@@ -23,13 +23,8 @@ use Flarum\User\User;
|
||||
use Flarum\User\UserValidator;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Contracts\Validation\ValidationException;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Intervention\Image\ImageManager;
|
||||
use League\Flysystem\Adapter\Local;
|
||||
use League\Flysystem\Filesystem;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
use League\Flysystem\MountManager;
|
||||
|
||||
class RegisterUserHandler
|
||||
{
|
||||
@@ -47,14 +42,9 @@ class RegisterUserHandler
|
||||
protected $validator;
|
||||
|
||||
/**
|
||||
* @var Application
|
||||
* @var AvatarUploader
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @var FilesystemInterface
|
||||
*/
|
||||
protected $uploadDir;
|
||||
protected $avatarUploader;
|
||||
|
||||
/**
|
||||
* @var Factory
|
||||
@@ -65,17 +55,15 @@ class RegisterUserHandler
|
||||
* @param Dispatcher $events
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
* @param UserValidator $validator
|
||||
* @param Application $app
|
||||
* @param FilesystemInterface $uploadDir
|
||||
* @param AvatarUploader $avatarUploader
|
||||
* @param Factory $validatorFactory
|
||||
*/
|
||||
public function __construct(Dispatcher $events, SettingsRepositoryInterface $settings, UserValidator $validator, Application $app, FilesystemInterface $uploadDir, Factory $validatorFactory)
|
||||
public function __construct(Dispatcher $events, SettingsRepositoryInterface $settings, UserValidator $validator, AvatarUploader $avatarUploader, Factory $validatorFactory)
|
||||
{
|
||||
$this->events = $events;
|
||||
$this->settings = $settings;
|
||||
$this->validator = $validator;
|
||||
$this->app = $app;
|
||||
$this->uploadDir = $uploadDir;
|
||||
$this->avatarUploader = $avatarUploader;
|
||||
$this->validatorFactory = $validatorFactory;
|
||||
}
|
||||
|
||||
@@ -144,7 +132,9 @@ class RegisterUserHandler
|
||||
}
|
||||
|
||||
try {
|
||||
$this->saveAvatarFromUrl($user, $avatarUrl);
|
||||
$image = (new ImageManager)->make($avatarUrl);
|
||||
|
||||
$this->avatarUploader->upload($user, $image);
|
||||
} catch (Exception $e) {
|
||||
//
|
||||
}
|
||||
@@ -160,23 +150,4 @@ class RegisterUserHandler
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function saveAvatarFromUrl(User $user, $url)
|
||||
{
|
||||
$tmpFile = tempnam($this->app->storagePath().'/tmp', 'avatar');
|
||||
|
||||
$manager = new ImageManager;
|
||||
$manager->make($url)->fit(100, 100)->save($tmpFile);
|
||||
|
||||
$mount = new MountManager([
|
||||
'source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))),
|
||||
'target' => $this->uploadDir,
|
||||
]);
|
||||
|
||||
$uploadName = Str::lower(Str::quickRandom()).'.png';
|
||||
|
||||
$user->changeAvatarPath($uploadName);
|
||||
|
||||
$mount->move('source://'.pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user