From 820c929ab38273c80d0930e2e6140dd7676ba4df Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 26 Mar 2016 14:43:41 -0400 Subject: Added avatar image upload --- app/User/Avatar/AvatarFileProvider.php | 42 ++++++++++++++++++++++++++++++++ app/User/Avatar/GravatarProvider.php | 5 ++-- app/User/Avatar/LetterAvatarProvider.php | 5 ++-- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 app/User/Avatar/AvatarFileProvider.php (limited to 'app/User') diff --git a/app/User/Avatar/AvatarFileProvider.php b/app/User/Avatar/AvatarFileProvider.php new file mode 100644 index 00000000..87a42c07 --- /dev/null +++ b/app/User/Avatar/AvatarFileProvider.php @@ -0,0 +1,42 @@ +helper->url->href('AvatarFile', 'show', array('user_id' => $user['id'], 'size' => $size)); + $title = $this->helper->text->e($user['name'] ?: $user['username']); + return '' . $title . ''; + } + + /** + * Determine if the provider is active + * + * @access public + * @param array $user + * @return boolean + */ + public function isActive(array $user) + { + return !empty($user['avatar_path']); + } +} diff --git a/app/User/Avatar/GravatarProvider.php b/app/User/Avatar/GravatarProvider.php index 7a719734..87ca51b1 100644 --- a/app/User/Avatar/GravatarProvider.php +++ b/app/User/Avatar/GravatarProvider.php @@ -17,8 +17,9 @@ class GravatarProvider extends Base implements AvatarProviderInterface * Render avatar html * * @access public - * @param array $user - * @param int $size + * @param array $user + * @param int $size + * @return string */ public function render(array $user, $size) { diff --git a/app/User/Avatar/LetterAvatarProvider.php b/app/User/Avatar/LetterAvatarProvider.php index 81c4586d..cf04f2a7 100644 --- a/app/User/Avatar/LetterAvatarProvider.php +++ b/app/User/Avatar/LetterAvatarProvider.php @@ -24,8 +24,9 @@ class LetterAvatarProvider extends Base implements AvatarProviderInterface * Render avatar html * * @access public - * @param array $user - * @param int $size + * @param array $user + * @param int $size + * @return string */ public function render(array $user, $size) { -- cgit v1.2.3 From 4ca716ec47863f3eef6c851de7a4f37650f8ea6e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 26 Mar 2016 17:25:54 -0400 Subject: Move avatar actions to controller AvatarFile --- app/Controller/AvatarFile.php | 39 +++++++++++++++++++++++++++++++++- app/Controller/User.php | 37 -------------------------------- app/Model/File.php | 1 - app/Template/avatar_file/show.php | 20 +++++++++++++++++ app/Template/user/avatar.php | 20 ----------------- app/Template/user/sidebar.php | 4 ++-- app/User/Avatar/AvatarFileProvider.php | 2 +- 7 files changed, 61 insertions(+), 62 deletions(-) create mode 100644 app/Template/avatar_file/show.php delete mode 100644 app/Template/user/avatar.php (limited to 'app/User') diff --git a/app/Controller/AvatarFile.php b/app/Controller/AvatarFile.php index f8298e16..a47cca66 100644 --- a/app/Controller/AvatarFile.php +++ b/app/Controller/AvatarFile.php @@ -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); diff --git a/app/Controller/User.php b/app/Controller/User.php index 8c02ef7f..f7d7d2e0 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -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']))); - } } diff --git a/app/Model/File.php b/app/Model/File.php index 5e77060c..e383235c 100644 --- a/app/Model/File.php +++ b/app/Model/File.php @@ -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; /** diff --git a/app/Template/avatar_file/show.php b/app/Template/avatar_file/show.php new file mode 100644 index 00000000..266a2ccb --- /dev/null +++ b/app/Template/avatar_file/show.php @@ -0,0 +1,20 @@ + + +avatar->render($user['id'], $user['username'], $user['name'], $user['email'], $user['avatar_path'], '') ?> + +
+ form->csrf() ?> + form->label(t('Upload my avatar image'), 'avatar') ?> + form->file('avatar') ?> + +
+ + url->link(t('Remove my image'), 'AvatarFile', 'remove', array('user_id' => $user['id']), true, 'btn btn-red') ?> + + + + url->link(t('cancel'), 'user', 'show', array('user_id' => $user['id'])) ?> +
+
diff --git a/app/Template/user/avatar.php b/app/Template/user/avatar.php deleted file mode 100644 index c285f44d..00000000 --- a/app/Template/user/avatar.php +++ /dev/null @@ -1,20 +0,0 @@ - - -avatar->render($user['id'], $user['username'], $user['name'], $user['email'], $user['avatar_path'], '') ?> - -
- form->csrf() ?> - form->label(t('Upload my avatar image'), 'avatar') ?> - form->file('avatar') ?> - -
- - url->link(t('Remove my image'), 'User', 'removeAvatar', array('user_id' => $user['id']), true, 'btn btn-red') ?> - - - - url->link(t('cancel'), 'user', 'show', array('user_id' => $user['id'])) ?> -
-
diff --git a/app/Template/user/sidebar.php b/app/Template/user/sidebar.php index ecadc60d..5ea2e355 100644 --- a/app/Template/user/sidebar.php +++ b/app/Template/user/sidebar.php @@ -37,8 +37,8 @@
  • app->checkMenuSelection('user', 'edit') ?>> url->link(t('Edit profile'), 'user', 'edit', array('user_id' => $user['id'])) ?>
  • -
  • app->checkMenuSelection('user', 'avatar') ?>> - url->link(t('Avatar'), 'user', 'avatar', array('user_id' => $user['id'])) ?> +
  • app->checkMenuSelection('AvatarFile') ?>> + url->link(t('Avatar'), 'AvatarFile', 'show', array('user_id' => $user['id'])) ?>
  • diff --git a/app/User/Avatar/AvatarFileProvider.php b/app/User/Avatar/AvatarFileProvider.php index 87a42c07..eea565f0 100644 --- a/app/User/Avatar/AvatarFileProvider.php +++ b/app/User/Avatar/AvatarFileProvider.php @@ -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 '' . $title . ''; } -- cgit v1.2.3 From 41f753d02733aa3c2c879caf5d914feb76c54388 Mon Sep 17 00:00:00 2001 From: Maxime Corteel Date: Tue, 29 Mar 2016 16:16:12 +0200 Subject: Generate avatar color based on name instead of initials --- app/User/Avatar/LetterAvatarProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/User') diff --git a/app/User/Avatar/LetterAvatarProvider.php b/app/User/Avatar/LetterAvatarProvider.php index cf04f2a7..f9659e61 100644 --- a/app/User/Avatar/LetterAvatarProvider.php +++ b/app/User/Avatar/LetterAvatarProvider.php @@ -31,7 +31,7 @@ class LetterAvatarProvider extends Base implements AvatarProviderInterface public function render(array $user, $size) { $initials = $this->helper->user->getInitials($user['name'] ?: $user['username']); - $rgb = $this->getBackgroundColor($initials); + $rgb = $this->getBackgroundColor($user['name'] ?: $user['username']); return sprintf( '
    %s
    ', -- cgit v1.2.3