diff --git a/config/services.yaml b/config/services.yaml index 73dc2984..b5471e22 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -8,6 +8,7 @@ parameters: locale: 'en' # Set the default language to use her partdb_title: 'Part-DB' # The title shown inside of Part-DB (e.g. in the navbar and on homepage) banner: '' # The info text shown in the homepage + use_gravatar: true # Set to false, if no Gravatar images should be used for user profiles. services: # default configuration for services in *this* file diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php new file mode 100644 index 00000000..6819a285 --- /dev/null +++ b/src/Controller/UserController.php @@ -0,0 +1,96 @@ +getUser(); + } + + if($this->getParameter("use_gravatar")) { + $avatar = $this->getGravatar($user->getEmail(), 200, 'identicon'); + } else { + $avatar = $packages->getUrl("/img/default_avatar.png"); + } + + + return $this->render('Users/user_info.html.twig', [ + 'user' => $user, + 'avatar' => $avatar + ]); + } + + + /** + * Get either a Gravatar URL or complete image tag for a specified email address. + * + * @param string $email The email address + * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] + * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] + * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] + * @param bool $img True to return a complete IMG tag False for just the URL + * @param array $atts Optional, additional key/value attributes to include in the IMG tag + * @return String containing either just a URL or a complete image tag + * @source https://gravatar.com/site/implement/images/php/ + */ + public function getGravatar(string $email, int $s = 80, string $d = 'mm', string $r = 'g', bool $img = false, array $atts = array()) + { + $url = 'https://www.gravatar.com/avatar/'; + $url .= md5(strtolower(trim($email))); + $url .= "?s=$s&d=$d&r=$r"; + if ($img) { + $url = ' $val) { + $url .= ' ' . $key . '="' . $val . '"'; + } + $url .= ' />'; + } + return $url; + } + +} \ No newline at end of file diff --git a/templates/Users/user_info.html.twig b/templates/Users/user_info.html.twig new file mode 100644 index 00000000..56505d71 --- /dev/null +++ b/templates/Users/user_info.html.twig @@ -0,0 +1,61 @@ +{% extends "main_card.html.twig" %} + +{% block title %}{% trans %}user.info.label{% endtrans %}{% endblock %} + +{% block card_title %} + {% trans %}user.info.label{% endtrans %}{% endblock %} + +{% block card_content %} +
+
+
+ +
+
+
+
+
+ +
+

{{ user.firstName }}

+
+
+
+ +
+

{{ user.lastName }}

+
+
+
+ +
+ {#

{{ user.email }}

#} + {{ user.email }} +
+
+
+ +
+

{{ user.department }}

+
+
+
+
+
+
+
+ +
+

{{ user.name }}

+
+
+
+ +
+

TODO

+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/base.html.twig b/templates/base.html.twig index ee3cb7fb..f08df66c 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -86,7 +86,7 @@ {% if app.user %} {% trans %}user.loggedin.label{% endtrans %} {{ app.user.firstName }} {{app.user.lastName}} ({{app.user.name}}) {% trans %}user.settings.label{% endtrans %} - {% trans %}user.info.label{% endtrans %} + {% trans %}user.info.label{% endtrans %} {% trans %}user.logout{% endtrans %} {% else %} diff --git a/translations/messages.de.xlf b/translations/messages.de.xlf index cc2ae456..ec5d6de3 100644 --- a/translations/messages.de.xlf +++ b/translations/messages.de.xlf @@ -565,5 +565,41 @@ Eingeloggt bleiben (nicht empfohlen auf geteilten Computern) + + + user.firstName.label + Vorname + + + + + user.lastName.label + Nachname + + + + + user.email.label + Email + + + + + user.department.label + Abteilung + + + + + user.username.label + Benutzername + + + + + group.label + Group + + diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 5a82c489..71a6a1ea 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -523,5 +523,41 @@ Remember me (should not be used on shared computers) + + + user.firstName.label + First name + + + + + user.lastName.label + Last name + + + + + user.email.label + Email + + + + + user.department.label + Department + + + + + user.username.label + User name + + + + + group.label + Gruppe: + +