src/westferry/backend/__version__.py \
src/westferry/backend/base.py \
src/westferry/backend/graphs.py \
- src/westferry/backend/system.py
+ src/westferry/backend/system.py \
+ src/westferry/backend/users.py
westferry_backenddir = $(pythondir)/westferry/backend
</div>
<div class="top-bar-right">
- <ul class="menu">
+ <ul class="dropdown menu" data-dropdown-menu>
<li><input type="search" placeholder="{{ _("Search") }}"></li>
<li><button type="button" class="button">{{ _("Search") }}</button></li>
+
+ {% if current_user %}
+ <li>
+ <a href="#">{{ current_user }}</a>
+
+ <ul class="menu vertical">
+ <li>
+ <a href="#">{{ _("Logout") }}</a>
+ </li>
+ </ul>
+ </li>
+ {% end %}
</ul>
</div>
</div>
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2021 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import functools
+import pydbus
+
+from . import base
+
+class UsersBackend(base.BaseBackend):
+ """
+ This class manages and has access to all user objects
+ """
+ @functools.cached_property
+ def sssd(self):
+ """
+ Returns the SSSD d-bus proxy
+ """
+ return self.backend.system.bus.get(
+ "org.freedesktop.sssd.infopipe",
+ "/org/freedesktop/sssd/infopipe/Users",
+ )
+
+ def get_by_name(self, name):
+ try:
+ return User(self.backend, name)
+ except NotFoundError:
+ return
+
+
+class User(base.BaseBackend):
+ def initialize(self, name):
+ # Store the UID
+ self.name = name
+
+ # Search for the user's path in dbus
+ self.path = self.backend.users.sssd.FindByName(name)
+ if not self.path:
+ raise NotFoundError("Could not find user %s" % name)
+
+ def __repr__(self):
+ return "<%s uid=%s>" % (self.__class__.__name__, self.uid)
+
+ def __str__(self):
+ return self.gecos
+
+ @functools.cached_property
+ def sssd(self):
+ """
+ Returns the SSSD d-bus proxy
+ """
+ return self.backend.system.bus.get("org.freedesktop.sssd.infopipe", self.path)
+
+ @property
+ def gecos(self):
+ """
+ Return's the user's realname
+ """
+ return self.sssd.gecos