When disabling third-party deps, don't use Gravatar.

Fixes #2810
This commit is contained in:
James Brooks
2017-12-03 17:34:59 +00:00
parent beb0d42e9b
commit 8e1c9801fb
9 changed files with 254 additions and 18 deletions

View File

@@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Composers;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use McCool\LaravelAutoPresenter\Facades\AutoPresenter;
/**
* This is the current user composer class.
@@ -32,6 +33,6 @@ class CurrentUserComposer
*/
public function compose(View $view)
{
$view->withCurrentUser(Auth::user());
$view->withCurrentUser(AutoPresenter::decorate(Auth::user()));
}
}

View File

@@ -12,18 +12,20 @@
namespace CachetHQ\Cachet\Models;
use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Presenters\UserPresenter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use McCool\LaravelAutoPresenter\HasPresenter;
/**
* This is the user model.
*
* @author James Brooks <james@alt-three.com>
*/
class User extends Authenticatable
class User extends Authenticatable implements HasPresenter
{
use Notifiable, ValidatingTrait;
@@ -162,18 +164,6 @@ class User extends Authenticatable
return $this;
}
/**
* Returns a Gravatar URL for the users email address.
*
* @param int $size
*
* @return string
*/
public function getGravatarAttribute($size = 200)
{
return sprintf('https://www.gravatar.com/avatar/%s?size=%d', md5(strtolower($this->email)), $size);
}
/**
* Find by api_key, or throw an exception.
*
@@ -220,4 +210,14 @@ class User extends Authenticatable
{
return trim($this->google_2fa_secret) !== '';
}
/**
* Get the presenter class.
*
* @return string
*/
public function getPresenterClass()
{
return UserPresenter::class;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Presenters;
use Illuminate\Contracts\Support\Arrayable;
use Laravolt\Avatar\Facade as Avatar;
use McCool\LaravelAutoPresenter\BasePresenter;
/**
* This is the user presenter class.
*
* @author James Brooks <james@bluebaytravel.co.uk>
*/
class UserPresenter extends BasePresenter implements Arrayable
{
/**
* Returns the users avatar.
*
* @return string
*/
public function avatar()
{
if (setting('enable_external_dependencies')) {
return sprintf('https://www.gravatar.com/avatar/%s?size=%d', md5(strtolower($this->email)), 200);
}
return Avatar::create($this->username)->toBase64();
}
/**
* Convert the presenter instance to an array.
*
* @return string[]
*/
public function toArray()
{
return array_merge($this->wrappedObject->toArray(), [
'avatar' => $this->avatar(),
]);
}
}

View File

@@ -47,6 +47,7 @@
"jenssegers/date": "^3.2",
"laravel/framework": "^5.4",
"laravel/tinker": "^1.0",
"laravolt/avatar": "^1.8",
"mccool/laravel-auto-presenter": "^5.0",
"nexmo/client": "@beta",
"pragmarx/google2fa": "^0.7.1",

185
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "25204c32b5e7a97cfc7b64872b7e7299",
"content-hash": "70b2147b1fc8086bacd0dff2957d22a1",
"packages": [
{
"name": "alt-three/badger",
@@ -802,6 +802,62 @@
],
"time": "2016-05-05T11:49:03+00:00"
},
{
"name": "danielstjules/stringy",
"version": "2.4.0",
"source": {
"type": "git",
"url": "https://github.com/danielstjules/Stringy.git",
"reference": "edbda419cbe4bcc3cb200b7c9811cb6597bf058b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/danielstjules/Stringy/zipball/edbda419cbe4bcc3cb200b7c9811cb6597bf058b",
"reference": "edbda419cbe4bcc3cb200b7c9811cb6597bf058b",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"symfony/polyfill-mbstring": "~1.1"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Stringy\\": "src/"
},
"files": [
"src/Create.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniel St. Jules",
"email": "danielst.jules@gmail.com",
"homepage": "http://www.danielstjules.com"
}
],
"description": "A string manipulation library with multibyte support",
"homepage": "https://github.com/danielstjules/Stringy",
"keywords": [
"UTF",
"helpers",
"manipulation",
"methods",
"multibyte",
"string",
"utf-8",
"utility",
"utils"
],
"time": "2017-03-02T20:43:29+00:00"
},
{
"name": "dnoegel/php-xdg-base-dir",
"version": "0.1",
@@ -1900,6 +1956,76 @@
],
"time": "2017-03-20T17:10:46+00:00"
},
{
"name": "intervention/image",
"version": "2.4.1",
"source": {
"type": "git",
"url": "https://github.com/Intervention/image.git",
"reference": "3603dbcc9a17d307533473246a6c58c31cf17919"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Intervention/image/zipball/3603dbcc9a17d307533473246a6c58c31cf17919",
"reference": "3603dbcc9a17d307533473246a6c58c31cf17919",
"shasum": ""
},
"require": {
"ext-fileinfo": "*",
"guzzlehttp/psr7": "~1.1",
"php": ">=5.4.0"
},
"require-dev": {
"mockery/mockery": "~0.9.2",
"phpunit/phpunit": "^4.8 || ^5.7"
},
"suggest": {
"ext-gd": "to use GD library based image processing.",
"ext-imagick": "to use Imagick based image processing.",
"intervention/imagecache": "Caching extension for the Intervention Image library"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
},
"laravel": {
"providers": [
"Intervention\\Image\\ImageServiceProvider"
],
"aliases": {
"Image": "Intervention\\Image\\Facades\\Image"
}
}
},
"autoload": {
"psr-4": {
"Intervention\\Image\\": "src/Intervention/Image"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Oliver Vogel",
"email": "oliver@olivervogel.com",
"homepage": "http://olivervogel.com/"
}
],
"description": "Image handling and manipulation library with support for Laravel integration",
"homepage": "http://image.intervention.io/",
"keywords": [
"gd",
"image",
"imagick",
"laravel",
"thumbnail",
"watermark"
],
"time": "2017-09-21T16:29:17+00:00"
},
{
"name": "jakub-onderka/php-console-color",
"version": "0.1",
@@ -2244,6 +2370,63 @@
],
"time": "2017-07-13T13:11:05+00:00"
},
{
"name": "laravolt/avatar",
"version": "1.8.1",
"source": {
"type": "git",
"url": "https://github.com/laravolt/avatar.git",
"reference": "7ab8f07333410ddc6f833bd8460fc9bdcab67fb3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravolt/avatar/zipball/7ab8f07333410ddc6f833bd8460fc9bdcab67fb3",
"reference": "7ab8f07333410ddc6f833bd8460fc9bdcab67fb3",
"shasum": ""
},
"require": {
"danielstjules/stringy": "~2.2",
"illuminate/cache": "~5.2",
"illuminate/support": "~5.2",
"intervention/image": "^2.1",
"php": ">=5.5.0"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "4.*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Laravolt\\Avatar\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bayu Hendra Winata",
"email": "uyab.exe@gmail.com",
"homepage": "http://id-laravel.com",
"role": "Developer"
}
],
"description": "Display avatar as base64",
"homepage": "https://github.com/laravolt/avatar",
"keywords": [
"avatar",
"laravel",
"laravolt"
],
"time": "2017-06-02T16:39:53+00:00"
},
{
"name": "lcobucci/jwt",
"version": "3.2.2",

View File

@@ -187,6 +187,7 @@ return [
GrahamCampbell\Security\SecurityServiceProvider::class,
Jenssegers\Date\DateServiceProvider::class,
Laravel\Tinker\TinkerServiceProvider::class,
Laravolt\Avatar\ServiceProvider::class,
McCool\LaravelAutoPresenter\AutoPresenterServiceProvider::class,
PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider::class,
Roumen\Feed\FeedServiceProvider::class,

View File

@@ -2,7 +2,7 @@
<div class="sidebar-inner">
<div class="profile">
<a href="{{ cachet_route('dashboard.user') }}">
<span class="avatar"><img src="{{ $current_user->gravatar }}"></span>
<span class="avatar"><img src="{{ $current_user->avatar }}"></span>
</a>
<a href="{{ cachet_route('dashboard.user') }}">
<h4 class="username">{{ $current_user->username }}</h4>

View File

@@ -29,7 +29,7 @@
@foreach($team_members as $member)
<div class="user col-sm-3 col-xs-6">
<a href="@if($current_user->id == $member->id) {{ url('dashboard/user') }} @else /dashboard/team/{{ $member->id }} @endif">
<img src="{{ $member->gravatar }}">
<img src="{{ $member->avatar }}">
</a>
<div class="name">{{ $member->username }}</div>
<div class="email">{{ $member->email }}</div>

View File

@@ -19,7 +19,7 @@
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<a href="https://gravatar.com"><img src="{{ $current_user->gravatar }}" class="img-responsive img-thumbnail" title="{{ trans('forms.user.gravatar') }}" data-toggle="tooltip"></a>
<a href="https://gravatar.com"><img src="{{ $current_user->avatar }}" class="img-responsive img-thumbnail" title="{{ trans('forms.user.gravatar') }}" data-toggle="tooltip"></a>
</div>
<div class="form-group">
<label>{{ trans('forms.user.username') }}</label>