From 0b966e696c6a99f825510d406008fc9b9936077e Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Mon, 13 Feb 2017 18:43:15 -0200 Subject: [#907] Convert login page to react with @anikarni --- service/pixelated/resources/login_resource.py | 12 ++++++------ service/pixelated/resources/root_resource.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'service/pixelated/resources') diff --git a/service/pixelated/resources/login_resource.py b/service/pixelated/resources/login_resource.py index 4bbceb89..3a886aa0 100644 --- a/service/pixelated/resources/login_resource.py +++ b/service/pixelated/resources/login_resource.py @@ -20,7 +20,7 @@ from xml.sax import SAXParseException from pixelated.authentication import Authenticator from pixelated.config.leap import BootstrapUserServices from pixelated.resources import BaseResource, UnAuthorizedResource, IPixelatedSession -from pixelated.resources import get_startup_folder, respond_json +from pixelated.resources import get_static_folder, respond_json from twisted.cred.error import UnauthorizedLogin from twisted.internet import defer from twisted.logger import Logger @@ -45,7 +45,7 @@ def parse_accept_language(all_headers): class DisclaimerElement(Element): - loader = XMLFile(FilePath(os.path.join(get_startup_folder(), '_login_disclaimer_banner.html'))) + loader = XMLFile(FilePath(os.path.join(get_static_folder(), '_login_disclaimer_banner.html'))) def __init__(self, banner): super(DisclaimerElement, self).__init__() @@ -68,7 +68,7 @@ class DisclaimerElement(Element): class LoginWebSite(Element): - loader = XMLFile(FilePath(os.path.join(get_startup_folder(), 'login.html'))) + loader = XMLFile(FilePath(os.path.join(get_static_folder(), 'login.html'))) def __init__(self, error_msg=None, disclaimer_banner_file=None): super(LoginWebSite, self).__init__() @@ -91,14 +91,14 @@ class LoginResource(BaseResource): def __init__(self, services_factory, provider=None, disclaimer_banner=None, authenticator=None): BaseResource.__init__(self, services_factory) - self._startup_folder = get_startup_folder() + self._assets_folder = get_static_folder() self._disclaimer_banner = disclaimer_banner self._provider = provider self._authenticator = authenticator or Authenticator(provider) self._bootstrap_user_services = BootstrapUserServices(services_factory, provider) - self.putChild('startup-assets', File(self._startup_folder)) - with open(os.path.join(self._startup_folder, 'Interstitial.html')) as f: + self.putChild('assets', File(self._assets_folder)) + with open(os.path.join(self._assets_folder, 'interstitial.html')) as f: self.interstitial = f.read() def getChild(self, path, request): diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index 206cb3be..be9c7458 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -20,7 +20,7 @@ from string import Template from pixelated.resources.users import UsersResource from pixelated.resources import BaseResource, UnAuthorizedResource, UnavailableResource -from pixelated.resources import get_startup_folder, get_static_folder +from pixelated.resources import get_static_folder from pixelated.resources.attachments_resource import AttachmentsResource from pixelated.resources.sandbox_resource import SandboxResource from pixelated.resources.backup_account_resource import BackupAccountResource @@ -51,7 +51,7 @@ MODE_RUNNING = 2 class RootResource(BaseResource): def __init__(self, services_factory): BaseResource.__init__(self, services_factory) - self._startup_assets_folder = get_startup_folder() + self._startup_assets_folder = get_static_folder() self._static_folder = get_static_folder() self._html_template = open(os.path.join(self._static_folder, 'index.html')).read() self._services_factory = services_factory -- cgit v1.2.3 From 560dc38a7994743fa15377f50451ebd9507f2c52 Mon Sep 17 00:00:00 2001 From: Anike Arni Date: Tue, 14 Feb 2017 11:15:04 -0200 Subject: [#907] Simplify static folder with @tuliocasagrande --- service/pixelated/resources/login_resource.py | 6 +++--- service/pixelated/resources/root_resource.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'service/pixelated/resources') diff --git a/service/pixelated/resources/login_resource.py b/service/pixelated/resources/login_resource.py index 3a886aa0..6c0b6cdd 100644 --- a/service/pixelated/resources/login_resource.py +++ b/service/pixelated/resources/login_resource.py @@ -91,14 +91,14 @@ class LoginResource(BaseResource): def __init__(self, services_factory, provider=None, disclaimer_banner=None, authenticator=None): BaseResource.__init__(self, services_factory) - self._assets_folder = get_static_folder() self._disclaimer_banner = disclaimer_banner self._provider = provider self._authenticator = authenticator or Authenticator(provider) self._bootstrap_user_services = BootstrapUserServices(services_factory, provider) - self.putChild('assets', File(self._assets_folder)) - with open(os.path.join(self._assets_folder, 'interstitial.html')) as f: + static_folder = get_static_folder() + self.putChild('assets', File(static_folder)) + with open(os.path.join(static_folder, 'interstitial.html')) as f: self.interstitial = f.read() def getChild(self, path, request): diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index be9c7458..beb40e88 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -51,17 +51,16 @@ MODE_RUNNING = 2 class RootResource(BaseResource): def __init__(self, services_factory): BaseResource.__init__(self, services_factory) - self._startup_assets_folder = get_static_folder() self._static_folder = get_static_folder() self._html_template = open(os.path.join(self._static_folder, 'index.html')).read() self._services_factory = services_factory self._child_resources = ChildResourcesMap() - with open(os.path.join(self._startup_assets_folder, 'Interstitial.html')) as f: + with open(os.path.join(self._static_folder, 'interstitial.html')) as f: self.interstitial = f.read() self._startup_mode() def _startup_mode(self): - self.putChild('startup-assets', File(self._startup_assets_folder)) + self.putChild('assets', File(self._static_folder)) self._mode = MODE_STARTUP def getChild(self, path, request): -- cgit v1.2.3 From c75cc8b57138cd8fc316d9371477b13e98f16d88 Mon Sep 17 00:00:00 2001 From: Anike Arni Date: Tue, 14 Feb 2017 11:16:24 -0200 Subject: [#907] Remove duplicate assets child resource with @tuliocasagrande --- service/pixelated/resources/root_resource.py | 1 - 1 file changed, 1 deletion(-) (limited to 'service/pixelated/resources') diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index beb40e88..77c7d950 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -90,7 +90,6 @@ class RootResource(BaseResource): def initialize(self, provider=None, disclaimer_banner=None, authenticator=None): self._child_resources.add('backup-account', BackupAccountResource(self._services_factory)) self._child_resources.add('sandbox', SandboxResource(self._static_folder)) - self._child_resources.add('assets', File(self._static_folder)) self._child_resources.add('keys', KeysResource(self._services_factory)) self._child_resources.add(AttachmentsResource.BASE_URL, AttachmentsResource(self._services_factory)) self._child_resources.add('contacts', ContactsResource(self._services_factory)) -- cgit v1.2.3 From 64780114ae90bb890d3ffa0a9aebe4686c6b74d3 Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Thu, 16 Feb 2017 13:42:50 -0200 Subject: [#907] Adapt login status to work with single user with @anikarni --- service/pixelated/resources/login_resource.py | 4 +++- service/pixelated/resources/root_resource.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'service/pixelated/resources') diff --git a/service/pixelated/resources/login_resource.py b/service/pixelated/resources/login_resource.py index 6c0b6cdd..160f12bf 100644 --- a/service/pixelated/resources/login_resource.py +++ b/service/pixelated/resources/login_resource.py @@ -176,5 +176,7 @@ class LoginStatusResource(BaseResource): def render_GET(self, request): session = IPixelatedSession(request.getSession()) - response = {'status': str(session.check_login_status())} + status = 'completed' if self._services_factory.mode.is_single_user else str(session.check_login_status()) + + response = {'status': status} return respond_json(response, request) diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index 77c7d950..37a0013e 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -27,7 +27,7 @@ from pixelated.resources.backup_account_resource import BackupAccountResource from pixelated.resources.contacts_resource import ContactsResource from pixelated.resources.features_resource import FeaturesResource from pixelated.resources.feedback_resource import FeedbackResource -from pixelated.resources.login_resource import LoginResource +from pixelated.resources.login_resource import LoginResource, LoginStatusResource from pixelated.resources.logout_resource import LogoutResource from pixelated.resources.user_settings_resource import UserSettingsResource from pixelated.resources.mail_resource import MailResource @@ -61,6 +61,7 @@ class RootResource(BaseResource): def _startup_mode(self): self.putChild('assets', File(self._static_folder)) + self.putChild('status', LoginStatusResource(self._services_factory)) self._mode = MODE_STARTUP def getChild(self, path, request): -- cgit v1.2.3 From 957599ae01687d6b3d02a3c34fdbe2ac6bd920f9 Mon Sep 17 00:00:00 2001 From: Anike Arni Date: Thu, 16 Feb 2017 18:51:26 -0200 Subject: [#907] Bundles login static files separately Due to conflicts with public and protected urls, login and interstitial files have to be on a different public url from inbox and resources that require login. Therefore, here, we delegate that logic to webpack. Now we have a '/public' url and a '/assets' url for those static assets. --- service/pixelated/resources/__init__.py | 11 +++++++---- service/pixelated/resources/backup_account_resource.py | 4 ++-- service/pixelated/resources/login_resource.py | 10 +++++----- service/pixelated/resources/root_resource.py | 14 ++++++++------ 4 files changed, 22 insertions(+), 17 deletions(-) (limited to 'service/pixelated/resources') diff --git a/service/pixelated/resources/__init__.py b/service/pixelated/resources/__init__.py index 6bac2f59..f5512644 100644 --- a/service/pixelated/resources/__init__.py +++ b/service/pixelated/resources/__init__.py @@ -57,12 +57,15 @@ def handle_error_deferred(e, request): request.finish() -def get_startup_folder(): - path = os.path.dirname(os.path.abspath(__file__)) - return os.path.join(path, '..', 'assets') +def get_protected_static_folder(): + return os.path.join(_get_static_folder(), 'protected') -def get_static_folder(): +def get_public_static_folder(): + return os.path.join(_get_static_folder(), 'public') + + +def _get_static_folder(): static_folder = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "..", "..", "web-ui", "dist")) if not os.path.exists(static_folder): static_folder = os.path.join('/', 'usr', 'share', 'pixelated-user-agent') diff --git a/service/pixelated/resources/backup_account_resource.py b/service/pixelated/resources/backup_account_resource.py index 5d9cb032..f1eeee53 100644 --- a/service/pixelated/resources/backup_account_resource.py +++ b/service/pixelated/resources/backup_account_resource.py @@ -19,13 +19,13 @@ from xml.sax import SAXParseException from pixelated.resources import BaseResource from twisted.python.filepath import FilePath -from pixelated.resources import get_static_folder +from pixelated.resources import get_protected_static_folder from twisted.web.http import OK from twisted.web.template import Element, XMLFile, renderElement class BackupAccountPage(Element): - loader = XMLFile(FilePath(os.path.join(get_static_folder(), 'backup_account.html'))) + loader = XMLFile(FilePath(os.path.join(get_protected_static_folder(), 'backup_account.html'))) def __init__(self): super(BackupAccountPage, self).__init__() diff --git a/service/pixelated/resources/login_resource.py b/service/pixelated/resources/login_resource.py index 160f12bf..bb05489e 100644 --- a/service/pixelated/resources/login_resource.py +++ b/service/pixelated/resources/login_resource.py @@ -20,7 +20,7 @@ from xml.sax import SAXParseException from pixelated.authentication import Authenticator from pixelated.config.leap import BootstrapUserServices from pixelated.resources import BaseResource, UnAuthorizedResource, IPixelatedSession -from pixelated.resources import get_static_folder, respond_json +from pixelated.resources import get_public_static_folder, respond_json from twisted.cred.error import UnauthorizedLogin from twisted.internet import defer from twisted.logger import Logger @@ -45,7 +45,7 @@ def parse_accept_language(all_headers): class DisclaimerElement(Element): - loader = XMLFile(FilePath(os.path.join(get_static_folder(), '_login_disclaimer_banner.html'))) + loader = XMLFile(FilePath(os.path.join(get_public_static_folder(), '_login_disclaimer_banner.html'))) def __init__(self, banner): super(DisclaimerElement, self).__init__() @@ -68,7 +68,7 @@ class DisclaimerElement(Element): class LoginWebSite(Element): - loader = XMLFile(FilePath(os.path.join(get_static_folder(), 'login.html'))) + loader = XMLFile(FilePath(os.path.join(get_public_static_folder(), 'login.html'))) def __init__(self, error_msg=None, disclaimer_banner_file=None): super(LoginWebSite, self).__init__() @@ -96,8 +96,8 @@ class LoginResource(BaseResource): self._authenticator = authenticator or Authenticator(provider) self._bootstrap_user_services = BootstrapUserServices(services_factory, provider) - static_folder = get_static_folder() - self.putChild('assets', File(static_folder)) + static_folder = get_public_static_folder() + self.putChild('public', File(static_folder)) with open(os.path.join(static_folder, 'interstitial.html')) as f: self.interstitial = f.read() diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index 37a0013e..320a1204 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -20,7 +20,7 @@ from string import Template from pixelated.resources.users import UsersResource from pixelated.resources import BaseResource, UnAuthorizedResource, UnavailableResource -from pixelated.resources import get_static_folder +from pixelated.resources import get_public_static_folder, get_protected_static_folder from pixelated.resources.attachments_resource import AttachmentsResource from pixelated.resources.sandbox_resource import SandboxResource from pixelated.resources.backup_account_resource import BackupAccountResource @@ -51,16 +51,17 @@ MODE_RUNNING = 2 class RootResource(BaseResource): def __init__(self, services_factory): BaseResource.__init__(self, services_factory) - self._static_folder = get_static_folder() - self._html_template = open(os.path.join(self._static_folder, 'index.html')).read() + self._public_static_folder = get_public_static_folder() + self._protected_static_folder = get_protected_static_folder() + self._html_template = open(os.path.join(self._protected_static_folder, 'index.html')).read() self._services_factory = services_factory self._child_resources = ChildResourcesMap() - with open(os.path.join(self._static_folder, 'interstitial.html')) as f: + with open(os.path.join(self._public_static_folder, 'interstitial.html')) as f: self.interstitial = f.read() self._startup_mode() def _startup_mode(self): - self.putChild('assets', File(self._static_folder)) + self.putChild('public', File(self._public_static_folder)) self.putChild('status', LoginStatusResource(self._services_factory)) self._mode = MODE_STARTUP @@ -89,8 +90,9 @@ class RootResource(BaseResource): return csrf_input and csrf_input == xsrf_token def initialize(self, provider=None, disclaimer_banner=None, authenticator=None): + self._child_resources.add('assets', File(self._protected_static_folder)) self._child_resources.add('backup-account', BackupAccountResource(self._services_factory)) - self._child_resources.add('sandbox', SandboxResource(self._static_folder)) + self._child_resources.add('sandbox', SandboxResource(self._protected_static_folder)) self._child_resources.add('keys', KeysResource(self._services_factory)) self._child_resources.add(AttachmentsResource.BASE_URL, AttachmentsResource(self._services_factory)) self._child_resources.add('contacts', ContactsResource(self._services_factory)) -- cgit v1.2.3