Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avatar controller cleanup #1058

Merged
merged 2 commits into from
Aug 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@

use OC\AppFramework\Utility\SimpleContainer;
use OC\AppFramework\Utility\TimeFactory;
use OC\Core\Controller\AvatarController;
use OC\Core\Controller\LoginController;
use OC\Core\Controller\LostController;
use OC\Core\Controller\TokenController;
use OC\Core\Controller\TwoFactorChallengeController;
use OC\Core\Controller\UserController;
use OCP\Defaults;
use OCP\AppFramework\App;
use OCP\Util;

Expand Down Expand Up @@ -83,19 +81,6 @@ public function __construct(array $urlParams=array()){
$c->query('Defaults')
);
});
$container->registerService('AvatarController', function(SimpleContainer $c) {
return new AvatarController(
$c->query('AppName'),
$c->query('Request'),
$c->query('AvatarManager'),
$c->query('Cache'),
$c->query('L10N'),
$c->query('UserManager'),
$c->query('UserSession'),
$c->query('UserFolder'),
$c->query('Logger')
);
});
$container->registerService('LoginController', function(SimpleContainer $c) {
return new LoginController(
$c->query('AppName'),
Expand Down Expand Up @@ -150,33 +135,18 @@ public function __construct(array $urlParams=array()){
$container->registerService('SecureRandom', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getSecureRandom();
});
$container->registerService('AvatarManager', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getAvatarManager();
});
$container->registerService('Session', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getSession();
});
$container->registerService('UserSession', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getUserSession();
});
$container->registerService('Session', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getSession();
});
$container->registerService('Cache', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getCache();
});
$container->registerService('UserFolder', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getUserFolder();
});
$container->registerService('Defaults', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getThemingDefaults();
});
$container->registerService('Mailer', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getMailer();
});
$container->registerService('Logger', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getLogger();
});
$container->registerService('TimeFactory', function(SimpleContainer $c) {
return new TimeFactory();
});
Expand All @@ -186,9 +156,6 @@ public function __construct(array $urlParams=array()){
$container->registerService('TwoFactorAuthManager', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getTwoFactorAuthManager();
});
$container->registerService('OC\CapabilitiesManager', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getCapabilitiesManager();
});
}

}
44 changes: 23 additions & 21 deletions core/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IAvatarManager;
use OCP\ICache;
use OCP\ILogger;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Files\Folder;

/**
* Class AvatarController
Expand All @@ -50,7 +52,7 @@ class AvatarController extends Controller {
/** @var IAvatarManager */
protected $avatarManager;

/** @var \OC\Cache\File */
/** @var ICache */
protected $cache;

/** @var IL10N */
Expand All @@ -62,41 +64,44 @@ class AvatarController extends Controller {
/** @var IUserSession */
protected $userSession;

/** @var Folder */
protected $userFolder;
/** @var IRootFolder */
protected $rootFolder;

/** @var ILogger */
protected $logger;

/** @var string */
protected $userId;

/**
* @param string $appName
* @param IRequest $request
* @param IAvatarManager $avatarManager
* @param \OC\Cache\File $cache
* @param ICache $cache
* @param IL10N $l10n
* @param IUserManager $userManager
* @param IUserSession $userSession
* @param Folder $userFolder
* @param IRootFolder $rootFolder
* @param ILogger $logger
* @param string $userId
*/
public function __construct($appName,
IRequest $request,
IAvatarManager $avatarManager,
\OC\Cache\File $cache,
ICache $cache,
IL10N $l10n,
IUserManager $userManager,
IUserSession $userSession,
Folder $userFolder = null,
ILogger $logger) {
IRootFolder $rootFolder,
ILogger $logger,
$userId) {
parent::__construct($appName, $request);

$this->avatarManager = $avatarManager;
$this->cache = $cache;
$this->l = $l10n;
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->userFolder = $userFolder;
$this->rootFolder = $rootFolder;
$this->logger = $logger;
$this->userId = $userId;
}

/**
Expand Down Expand Up @@ -156,8 +161,9 @@ public function postAvatar($path) {

if (isset($path)) {
$path = stripslashes($path);
$node = $this->userFolder->get($path);
if (!($node instanceof \OCP\Files\File)) {
$userFolder = $this->rootFolder->getUserFolder($this->userId);
$node = $userFolder->get($path);
if (!($node instanceof File)) {
return new DataResponse(['data' => ['message' => $this->l->t('Please select a file.')]], Http::STATUS_OK, $headers);
}
if ($node->getSize() > 20*1024*1024) {
Expand Down Expand Up @@ -240,10 +246,8 @@ public function postAvatar($path) {
* @return DataResponse
*/
public function deleteAvatar() {
$userId = $this->userSession->getUser()->getUID();

try {
$avatar = $this->avatarManager->getAvatar($userId);
$avatar = $this->avatarManager->getAvatar($this->userId);
$avatar->remove();
return new DataResponse();
} catch (\Exception $e) {
Expand Down Expand Up @@ -285,8 +289,6 @@ public function getTmpAvatar() {
* @return DataResponse
*/
public function postCroppedAvatar($crop) {
$userId = $this->userSession->getUser()->getUID();

if (is_null($crop)) {
return new DataResponse(['data' => ['message' => $this->l->t("No crop data provided")]],
Http::STATUS_BAD_REQUEST);
Expand All @@ -308,7 +310,7 @@ public function postCroppedAvatar($crop) {
$image = new \OC_Image($tmpAvatar);
$image->crop($crop['x'], $crop['y'], round($crop['w']), round($crop['h']));
try {
$avatar = $this->avatarManager->getAvatar($userId);
$avatar = $this->avatarManager->getAvatar($this->userId);
$avatar->set($image);
// Clean up
$this->cache->remove('tmpAvatar');
Expand Down
Loading