* #75 - fix data leak to ui-avatars * #75 - ecs fix * #75 - new colors * #75 - change font color * #75 - ecs fix * #75 - change colors order * #75 - fix * #75 - fix * #75 - ecs fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
parent
8a54403318
commit
287c6c19ab
33
app/Eloquent/Helpers/ColorGenerator.php
Normal file
33
app/Eloquent/Helpers/ColorGenerator.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Toby\Eloquent\Helpers;
|
||||||
|
|
||||||
|
class ColorGenerator
|
||||||
|
{
|
||||||
|
public static function generate(string $text): string
|
||||||
|
{
|
||||||
|
$colors = config("colors");
|
||||||
|
$hash = static::calculateHash($text);
|
||||||
|
|
||||||
|
$index = $hash - count($colors) * floor($hash / count($colors));
|
||||||
|
|
||||||
|
return $colors[$index];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function calculateHash(string $text): int
|
||||||
|
{
|
||||||
|
$hash = 0;
|
||||||
|
|
||||||
|
if (empty($text)) {
|
||||||
|
return $hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 0; $i < mb_strlen($text); $i++) {
|
||||||
|
$hash = abs((int)(($hash << 2) - $hash) + mb_ord($text[$i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $hash;
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@ use Illuminate\Support\Collection;
|
|||||||
use Rackbeat\UIAvatars\HasAvatar;
|
use Rackbeat\UIAvatars\HasAvatar;
|
||||||
use Toby\Domain\Enums\EmploymentForm;
|
use Toby\Domain\Enums\EmploymentForm;
|
||||||
use Toby\Domain\Enums\Role;
|
use Toby\Domain\Enums\Role;
|
||||||
|
use Toby\Eloquent\Helpers\ColorGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
@ -84,10 +85,8 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
public function getAvatar(): string
|
public function getAvatar(): string
|
||||||
{
|
{
|
||||||
$colors = config("colors");
|
|
||||||
|
|
||||||
return $this->getAvatarGenerator()
|
return $this->getAvatarGenerator()
|
||||||
->backgroundColor($colors[strlen($this->fullname) % count($colors)])
|
->backgroundColor(ColorGenerator::generate($this->fullName))
|
||||||
->image();
|
->image();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,9 +100,9 @@ class User extends Authenticatable
|
|||||||
return $this->role === $role;
|
return $this->role === $role;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAvatarNameKey(): string
|
protected function getAvatarName(): string
|
||||||
{
|
{
|
||||||
return "fullName";
|
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function newFactory(): UserFactory
|
protected static function newFactory(): UserFactory
|
||||||
|
@ -3,19 +3,35 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"#475569",
|
"#f43f5e",
|
||||||
"#EA580C",
|
"#e11d48",
|
||||||
"#EAB308",
|
"#ec4899",
|
||||||
"#CA8A04",
|
"#db2777",
|
||||||
"#84CC16",
|
"#d946ef",
|
||||||
"#4D7C0F",
|
"#c026d3",
|
||||||
"#10B981",
|
"#a855f7",
|
||||||
"#06B6D4",
|
"#9333ea",
|
||||||
"#4338CA",
|
"#527aba",
|
||||||
"#A855F7",
|
"#3c5f97",
|
||||||
"#86198F",
|
"#6366f1",
|
||||||
"#FB7185",
|
"#4f46e5",
|
||||||
"#EC4899",
|
"#3b82f6",
|
||||||
"#9D174D",
|
"#2563eb",
|
||||||
"#F43F5E",
|
"#0ea5e9",
|
||||||
|
"#0284c7",
|
||||||
|
"#06b6d4",
|
||||||
|
"#0891b2",
|
||||||
|
"#14b8a6",
|
||||||
|
"#0d9488",
|
||||||
|
"#22c55e",
|
||||||
|
"#16a34a",
|
||||||
|
"#84cc16",
|
||||||
|
"#65a30d",
|
||||||
|
"#eab308",
|
||||||
|
"#ca8a04",
|
||||||
|
"#f97316",
|
||||||
|
"#ea580c",
|
||||||
|
"#ef4444",
|
||||||
|
"#dc2626",
|
||||||
|
"#4b5563",
|
||||||
];
|
];
|
||||||
|
@ -11,8 +11,8 @@ return [
|
|||||||
"rounded" => true,
|
"rounded" => true,
|
||||||
"smooth_rounding" => true,
|
"smooth_rounding" => true,
|
||||||
"uppercase" => true,
|
"uppercase" => true,
|
||||||
"background_color" => "#a0a0a0",
|
"background_color" => "#A0A0A0",
|
||||||
"font_color" => "#F4F8FD",
|
"font_color" => "#FFFFFF",
|
||||||
"font_bold" => true,
|
"font_bold" => true,
|
||||||
"providers" => [
|
"providers" => [
|
||||||
"api" => Rackbeat\UIAvatars\Generators\ApiGenerator::class,
|
"api" => Rackbeat\UIAvatars\Generators\ApiGenerator::class,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user