Skip to content

A free open source IT asset/license management system

Fixes #15239 and #17259 - better handle external avatars

snipe951aee8292fe
diff --git a/app/Models/User.php b/app/Models/User.php
index f6bbcfaded..55d79808ca 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -18,6 +18,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Gate;
+use Illuminate\Support\Str;
use Laravel\Passport\HasApiTokens;
use Watson\Validating\ValidatingTrait;
use Illuminate\Database\Eloquent\Casts\Attribute;
@@ -168,6 +169,15 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
}
+ public function isAvatarExternal() {
+ // Check if it's a google avatar or some external avatar
+ if (Str::startsWith($this->avatar, ['http://', 'https://'])) {
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Internally check the user permission for the given section
*
diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php
index b701a23805..fe88c1a1e2 100644
--- a/app/Presenters/UserPresenter.php
+++ b/app/Presenters/UserPresenter.php
@@ -453,6 +453,8 @@ class UserPresenter extends Presenter
return $this->fullName();
}
+
+
/**
* Returns the user Gravatar image url.
*
@@ -465,7 +467,7 @@ class UserPresenter extends Presenter
if ($this->avatar) {
// Check if it's a google avatar or some external avatar
- if (Str::startsWith($this->avatar, ['http://', 'https://'])) {
+ if ($this->isAvatarExternal()) {
return $this->avatar;
}
diff --git a/resources/views/account/profile.blade.php b/resources/views/account/profile.blade.php
index cb8769b663..abf463ad94 100755
--- a/resources/views/account/profile.blade.php
+++ b/resources/views/account/profile.blade.php
@@ -107,39 +107,44 @@
</div>
</div>
- <!-- Gravatar Email -->
- <div class="form-group {{ $errors->has('gravatar') ? ' has-error' : '' }}">
- <label for="gravatar" class="col-md-3 control-label">{{ trans('general.gravatar_email') }}
- <small>(Private)</small>
- </label>
- <div class="col-md-8">
- <input class="form-control" type="text" name="gravatar" id="gravatar" value="{{ old('gravatar', $user->gravatar) }}" />
- {!! $errors->first('gravatar', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
- <p style="padding-top: 3px;">
- <img src="//secure.gravatar.com/avatar/{{ md5(strtolower(trim($user->gravatar))) }}" width="30" height="30" alt="{{ $user->present()->fullName() }} avatar image">
- {!! trans('general.gravatar_url') !!}
- </p>
- </div>
- </div>
- <!-- Avatar -->
+ <!-- Avatar -->
@if (($user->avatar) && ($user->avatar!=''))
<div class="form-group{{ $errors->has('image_delete') ? ' has-error' : '' }}">
<div class="col-md-9 col-md-offset-3">
+ @if (!$user->isAvatarExternal())
<label for="image_delete" class="form-control">
<input type="checkbox" name="image_delete" id="image_delete" value="1" @checked(old('image_delete')) aria-label="image_delete">
{{ trans('general.image_delete') }}
</label>
{!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
+ @endif
</div>
</div>
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
- <img src="{{ Storage::disk('public')->url(app('users_upload_path').e($user->avatar)) }}" class="img-responsive">
+ <img src="{{ (($user->isAvatarExternal()) ? $user->avatar : Storage::disk('public')->url(app('users_upload_path').e($user->avatar))) }}" class="img-responsive">
{!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
+
+ @else
+ <!-- Gravatar Email -->
+ <div class="form-group {{ $errors->has('gravatar') ? ' has-error' : '' }}">
+ <label for="gravatar" class="col-md-3 control-label">{{ trans('general.gravatar_email') }}
+ <small>(Private)</small>
+ </label>
+ <div class="col-md-8">
+ <input class="form-control" type="text" name="gravatar" id="gravatar" value="{{ old('gravatar', $user->gravatar) }}" />
+ {!! $errors->first('gravatar', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
+ <p style="padding-top: 3px;">
+ <img src="//secure.gravatar.com/avatar/{{ md5(strtolower(trim($user->gravatar))) }}" width="30" height="30" alt="{{ $user->present()->fullName() }} avatar image">
+ {!! trans('general.gravatar_url') !!}
+ </p>
+ </div>
+ </div>
+
@endif