From 287c6c19abf12b8c9de6f3609cc181e36ba42473 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Wed, 16 Mar 2022 11:53:05 +0100 Subject: [PATCH] #75 - fix data leak to ui-avatars (#79) * #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 --- app/Eloquent/Helpers/ColorGenerator.php | 33 ++++++++++++++++++ app/Eloquent/Models/User.php | 9 +++-- config/colors.php | 46 +++++++++++++++++-------- config/ui-avatars.php | 4 +-- 4 files changed, 70 insertions(+), 22 deletions(-) create mode 100644 app/Eloquent/Helpers/ColorGenerator.php diff --git a/app/Eloquent/Helpers/ColorGenerator.php b/app/Eloquent/Helpers/ColorGenerator.php new file mode 100644 index 0000000..b8930f3 --- /dev/null +++ b/app/Eloquent/Helpers/ColorGenerator.php @@ -0,0 +1,33 @@ +getAvatarGenerator() - ->backgroundColor($colors[strlen($this->fullname) % count($colors)]) + ->backgroundColor(ColorGenerator::generate($this->fullName)) ->image(); } @@ -101,9 +100,9 @@ class User extends Authenticatable 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 diff --git a/config/colors.php b/config/colors.php index 0b8a3ad..bd4dc04 100644 --- a/config/colors.php +++ b/config/colors.php @@ -3,19 +3,35 @@ declare(strict_types=1); return [ - "#475569", - "#EA580C", - "#EAB308", - "#CA8A04", - "#84CC16", - "#4D7C0F", - "#10B981", - "#06B6D4", - "#4338CA", - "#A855F7", - "#86198F", - "#FB7185", - "#EC4899", - "#9D174D", - "#F43F5E", + "#f43f5e", + "#e11d48", + "#ec4899", + "#db2777", + "#d946ef", + "#c026d3", + "#a855f7", + "#9333ea", + "#527aba", + "#3c5f97", + "#6366f1", + "#4f46e5", + "#3b82f6", + "#2563eb", + "#0ea5e9", + "#0284c7", + "#06b6d4", + "#0891b2", + "#14b8a6", + "#0d9488", + "#22c55e", + "#16a34a", + "#84cc16", + "#65a30d", + "#eab308", + "#ca8a04", + "#f97316", + "#ea580c", + "#ef4444", + "#dc2626", + "#4b5563", ]; diff --git a/config/ui-avatars.php b/config/ui-avatars.php index 68cbd82..7a4c76d 100644 --- a/config/ui-avatars.php +++ b/config/ui-avatars.php @@ -11,8 +11,8 @@ return [ "rounded" => true, "smooth_rounding" => true, "uppercase" => true, - "background_color" => "#a0a0a0", - "font_color" => "#F4F8FD", + "background_color" => "#A0A0A0", + "font_color" => "#FFFFFF", "font_bold" => true, "providers" => [ "api" => Rackbeat\UIAvatars\Generators\ApiGenerator::class,