refactor authentication / authorization into a mixin
This commit is contained in:
parent
8422a33081
commit
17c20d12e0
@ -1,4 +1,3 @@
|
||||
from .template import WebpageController
|
||||
from .session import SessionStorage
|
||||
from owrx.config import Config
|
||||
from owrx.users import UserList
|
||||
@ -25,7 +24,7 @@ class Authentication(object):
|
||||
return None
|
||||
|
||||
|
||||
class AdminController(WebpageController):
|
||||
class AuthorizationMixin(object):
|
||||
def __init__(self, handler, request, options):
|
||||
self.authentication = Authentication()
|
||||
self.user = self.authentication.getUser(request)
|
||||
|
@ -1,9 +1,10 @@
|
||||
from owrx.controllers.admin import AdminController
|
||||
from owrx.controllers.template import WebpageController
|
||||
from owrx.controllers.admin import AuthorizationMixin
|
||||
from owrx.users import UserList, DefaultPasswordClass
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
|
||||
class ProfileController(AdminController):
|
||||
class ProfileController(AuthorizationMixin, WebpageController):
|
||||
def isAuthorized(self):
|
||||
return self.user is not None and self.user.is_enabled() and self.user.must_change_password
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from .admin import AdminController
|
||||
from owrx.controllers.template import WebpageController
|
||||
from owrx.controllers.admin import AuthorizationMixin
|
||||
from owrx.config import Config, CoreConfig
|
||||
from urllib.parse import parse_qs
|
||||
from owrx.form import (
|
||||
@ -54,12 +55,12 @@ class Section(object):
|
||||
return {k: v for i in self.inputs for k, v in i.parse(data).items()}
|
||||
|
||||
|
||||
class SettingsController(AdminController):
|
||||
class SettingsController(AuthorizationMixin, WebpageController):
|
||||
def indexAction(self):
|
||||
self.serve_template("settings.html", **self.template_variables())
|
||||
|
||||
|
||||
class SdrSettingsController(AdminController):
|
||||
class SdrSettingsController(AuthorizationMixin, WebpageController):
|
||||
def template_variables(self):
|
||||
variables = super().template_variables()
|
||||
variables["devices"] = self.render_devices()
|
||||
@ -93,7 +94,7 @@ class SdrSettingsController(AdminController):
|
||||
self.serve_template("sdrsettings.html", **self.template_variables())
|
||||
|
||||
|
||||
class GeneralSettingsController(AdminController):
|
||||
class GeneralSettingsController(AuthorizationMixin, WebpageController):
|
||||
sections = [
|
||||
Section(
|
||||
"Receiver information",
|
||||
|
Loading…
Reference in New Issue
Block a user