Abstracted user avatar fetching away from gravatar

Still uses gravatar as a default.
Updated URL placeholders to follow LDAP format.
Potential breaking config change: `GRAVATAR=false` replaced by `AVATAR_URL=false`
Builds upon #1111
This commit is contained in:
Dan Brown
2018-12-22 19:29:19 +00:00
parent d673bf61c2
commit b56fc21aaf
6 changed files with 55 additions and 32 deletions

View File

@ -85,9 +85,7 @@ class UserRepo
{
$user = $this->create($data, $verifyEmail);
$this->attachDefaultRole($user);
// Get avatar from gravatar and save
$this->downloadGravatarToUserAvatar($user);
$this->downloadAndAssignUserAvatar($user);
return $user;
}
@ -238,25 +236,24 @@ class UserRepo
}
/**
* Get a gravatar image for a user and set it as their avatar.
* Does not run if gravatar disabled in config.
* Get an avatar image for a user and set it as their avatar.
* Returns early if avatars disabled or not set in config.
* @param User $user
* @return bool
*/
public function downloadGravatarToUserAvatar(User $user)
public function downloadAndAssignUserAvatar(User $user)
{
// Get avatar from gravatar and save
if (!config('services.gravatar')) {
if (!Images::avatarFetchEnabled()) {
return false;
}
try {
$avatar = Images::saveUserGravatar($user, config('services.gravatar_url'));
$avatar = Images::saveUserAvatar($user);
$user->avatar()->associate($avatar);
$user->save();
return true;
} catch (Exception $e) {
\Log::error('Failed to save user gravatar image');
\Log::error('Failed to save user avatar image');
return false;
}
}