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
+2 -1
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()));
}
}
+13 -13
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;
}
}
+50
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(),
]);
}
}