Move avatar actions to controller AvatarFile

This commit is contained in:
Frederic Guillot 2016-03-26 17:25:54 -04:00
parent 820c929ab3
commit 4ca716ec47
6 changed files with 43 additions and 44 deletions

View File

@ -14,9 +14,46 @@ use Kanboard\Core\Thumbnail;
class AvatarFile extends Base
{
/**
* Show Avatar image and send aggressive caching headers
* Display avatar page
*/
public function show()
{
$user = $this->getUser();
$this->response->html($this->helper->layout->user('avatar_file/show', array(
'user' => $user,
)));
}
/**
* Upload Avatar
*/
public function upload()
{
$user = $this->getUser();
if (! $this->avatarFile->uploadFile($user['id'], $this->request->getFileInfo('avatar'))) {
$this->flash->failure(t('Unable to upload the file.'));
}
$this->response->redirect($this->helper->url->to('AvatarFile', 'show', array('user_id' => $user['id'])));
}
/**
* Remove Avatar image
*/
public function remove()
{
$this->checkCSRFParam();
$user = $this->getUser();
$this->avatarFile->remove($user['id']);
$this->response->redirect($this->helper->url->to('AvatarFile', 'show', array('user_id' => $user['id'])));
}
/**
* Show Avatar image (public)
*/
public function image()
{
$user_id = $this->request->getIntegerParam('user_id');
$size = $this->request->getStringParam('size', 48);

View File

@ -405,41 +405,4 @@ class User extends Base
'user' => $user,
)));
}
/**
* Display avatar page
*/
public function avatar()
{
$user = $this->getUser();
$this->response->html($this->helper->layout->user('user/avatar', array(
'user' => $user,
)));
}
/**
* Upload Avatar
*/
public function uploadAvatar()
{
$user = $this->getUser();
if (! $this->avatarFile->uploadFile($user['id'], $this->request->getFileInfo('avatar'))) {
$this->flash->failure(t('Unable to upload the file.'));
}
$this->response->redirect($this->helper->url->to('user', 'avatar', array('user_id' => $user['id'])));
}
/**
* Remove Avatar image
*/
public function removeAvatar()
{
$this->checkCSRFParam();
$user = $this->getUser();
$this->avatarFile->remove($user['id']);
$this->response->redirect($this->helper->url->to('user', 'avatar', array('user_id' => $user['id'])));
}
}

View File

@ -5,7 +5,6 @@ namespace Kanboard\Model;
use Exception;
use Kanboard\Core\Thumbnail;
use Kanboard\Event\FileEvent;
use Kanboard\Core\Tool;
use Kanboard\Core\ObjectStorage\ObjectStorageException;
/**

View File

@ -4,14 +4,14 @@
<?= $this->avatar->render($user['id'], $user['username'], $user['name'], $user['email'], $user['avatar_path'], '') ?>
<form method="post" enctype="multipart/form-data" action="<?= $this->url->href('user', 'uploadAvatar', array('user_id' => $user['id'])) ?>">
<form method="post" enctype="multipart/form-data" action="<?= $this->url->href('AvatarFile', 'upload', array('user_id' => $user['id'])) ?>">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Upload my avatar image'), 'avatar') ?>
<?= $this->form->file('avatar') ?>
<div class="form-actions">
<?php if (! empty($user['avatar_path'])): ?>
<?= $this->url->link(t('Remove my image'), 'User', 'removeAvatar', array('user_id' => $user['id']), true, 'btn btn-red') ?>
<?= $this->url->link(t('Remove my image'), 'AvatarFile', 'remove', array('user_id' => $user['id']), true, 'btn btn-red') ?>
<?php endif ?>
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?>

View File

@ -37,8 +37,8 @@
<li <?= $this->app->checkMenuSelection('user', 'edit') ?>>
<?= $this->url->link(t('Edit profile'), 'user', 'edit', array('user_id' => $user['id'])) ?>
</li>
<li <?= $this->app->checkMenuSelection('user', 'avatar') ?>>
<?= $this->url->link(t('Avatar'), 'user', 'avatar', array('user_id' => $user['id'])) ?>
<li <?= $this->app->checkMenuSelection('AvatarFile') ?>>
<?= $this->url->link(t('Avatar'), 'AvatarFile', 'show', array('user_id' => $user['id'])) ?>
</li>
<?php endif ?>

View File

@ -23,7 +23,7 @@ class AvatarFileProvider extends Base implements AvatarProviderInterface
*/
public function render(array $user, $size)
{
$url = $this->helper->url->href('AvatarFile', 'show', array('user_id' => $user['id'], 'size' => $size));
$url = $this->helper->url->href('AvatarFile', 'image', array('user_id' => $user['id'], 'size' => $size));
$title = $this->helper->text->e($user['name'] ?: $user['username']);
return '<img src="' . $url . '" alt="' . $title . '" title="' . $title . '">';
}