]> git.ipfire.org Git - people/ms/westferry.git/commitdiff
backend: Add some basic user backend
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 6 Dec 2021 18:04:42 +0000 (18:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 6 Dec 2021 18:04:42 +0000 (18:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/base.html
src/westferry/backend/__init__.py
src/westferry/backend/users.py [new file with mode: 0644]
src/westferry/handlers/base.py

index 5d2d4d3f8beeb04df4d412cc17434a97b775607c..a9999b11deae64b4ec972baa84656aa2f18fc1d8 100644 (file)
@@ -102,7 +102,8 @@ westferry_backend_PYTHON = \
        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
 
index a8618fe2c7b7f6458935595f57b461b433ad7a42..a1b1840c3a066f3affc6909ff9137551c6d097dc 100644 (file)
                                </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>
index 3e998363f543c85b470d31516116c9737a449087..2c094b259604a0de7a91ba687ec8b78f8ca1bfb7 100644 (file)
@@ -23,6 +23,7 @@ from .__version__ import VERSION
 
 from . import graphs
 from . import system
+from . import users
 
 class Backend(object):
        version = VERSION
@@ -32,3 +33,4 @@ class Backend(object):
 
                self.graphs = graphs.GraphsBackend(self)
                self.system = system.SystemBackend(self)
+               self.users  = users.UsersBackend(self)
diff --git a/src/westferry/backend/users.py b/src/westferry/backend/users.py
new file mode 100644 (file)
index 0000000..81ba5cf
--- /dev/null
@@ -0,0 +1,76 @@
+#!/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
index 9f134df1c699f9b667eae497cfc039d1b8e094a5..abbe1a70333ddbb7ad894f6ae38e992c6ab4a3ba 100644 (file)
@@ -61,6 +61,13 @@ class BaseHandler(tornado.web.RequestHandler, metaclass=HandlerRegistration):
                """
                return self.application.backend
 
+       def get_current_user(self):
+               """
+                       This function returns the currently logged-in user.
+               """
+               # XXX This is just a demo
+               return self.backend.users.get_by_name("ms")
+
        @property
        def topmenu(self):
                """