first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace Common\Auth\Traits;
use Common\Auth\BaseUser;
use Storage;
use Str;
trait HasAvatarAttribute
{
public function getAvatarAttribute(?string $value)
{
// absolute link
if ($value && Str::contains($value, '//')) {
// change google/twitter avatar imported via social login size
$value = str_replace(
'.jpg?sz=50',
".jpg?sz=$this->gravatarSize",
$value,
);
if ($this->gravatarSize > 50) {
// twitter
$value = str_replace('_normal.jpg', '.jpg', $value);
}
return $value;
}
// relative link (for new and legacy urls)
if ($value) {
return Storage::disk('public')->url(
str_replace('storage/', '', $value),
);
}
// gravatar
$hash = md5(trim(strtolower($this->email)));
return "https://www.gravatar.com/avatar/$hash?s={$this->gravatarSize}&d=retro";
}
/**
* @param number $size
* @return BaseUser
*/
public function setGravatarSize($size)
{
$this->gravatarSize = $size;
return $this;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Common\Auth\Traits;
trait HasDisplayNameAttribute
{
/**
* Compile user display name from available attributes.
*
* @return string
*/
public function getDisplayNameAttribute()
{
if ($this->username) {
return $this->username;
} else if ($this->first_name && $this->last_name) {
return $this->first_name.' '.$this->last_name;
} else if ($this->first_name) {
return $this->first_name;
} else if ($this->last_name) {
return $this->last_name;
} else {
return explode('@', $this->email)[0];
}
}
}