From f0fdf75251dc95f712276fbee09adacd6ced8700 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 18 Jun 2023 02:36:30 +0200 Subject: [PATCH] ErrorUserNotLogged --- src/requests/admin.cr | 3 +++ src/requests/login.cr | 1 + src/requests/zone.cr | 16 ++++++++-------- src/responses/error.cr | 8 +++++++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/requests/admin.cr b/src/requests/admin.cr index c80ef81..76e3fc4 100644 --- a/src/requests/admin.cr +++ b/src/requests/admin.cr @@ -13,6 +13,9 @@ class DNSManager::Request end def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON + user = dnsmanagerd.get_logged_user event + return Response::ErrorUserNotLogged.new unless user + # This request means serious business. # TODO: check for admin. diff --git a/src/requests/login.cr b/src/requests/login.cr index 5e9ef53..ec011eb 100644 --- a/src/requests/login.cr +++ b/src/requests/login.cr @@ -20,6 +20,7 @@ class DNSManager::Request end rescue e # FIXME: Should those be logged? + Baguette::Log.error "Error: #{e}" Response::Error.new "unauthorized" end end diff --git a/src/requests/zone.cr b/src/requests/zone.cr index f7748c2..51e62ae 100644 --- a/src/requests/zone.cr +++ b/src/requests/zone.cr @@ -11,7 +11,7 @@ class DNSManager::Request def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON user = dnsmanagerd.get_logged_user event - raise NotLoggedException.new if user.nil? + return Response::ErrorUserNotLogged.new unless user dnsmanagerd.storage.new_domain user.uid, @domain end end @@ -25,7 +25,7 @@ class DNSManager::Request def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON user = dnsmanagerd.get_logged_user event - raise NotLoggedException.new if user.nil? + return Response::ErrorUserNotLogged.new unless user dnsmanagerd.storage.add_or_update_zone user.uid, zone end end @@ -39,7 +39,7 @@ class DNSManager::Request def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON user = dnsmanagerd.get_logged_user event - raise NotLoggedException.new if user.nil? + return Response::ErrorUserNotLogged.new unless user dnsmanagerd.storage.delete_domain user.uid, @domain end end @@ -53,7 +53,7 @@ class DNSManager::Request def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON user = dnsmanagerd.get_logged_user event - raise NotLoggedException.new if user.nil? + return Response::ErrorUserNotLogged.new unless user dnsmanagerd.storage.get_zone user.uid, @domain end end @@ -65,7 +65,7 @@ class DNSManager::Request def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON user = dnsmanagerd.get_logged_user event - raise NotLoggedException.new if user.nil? + return Response::ErrorUserNotLogged.new unless user dnsmanagerd.storage.user_domains user.uid end end @@ -80,7 +80,7 @@ class DNSManager::Request def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON user = dnsmanagerd.get_logged_user event - raise NotLoggedException.new if user.nil? + return Response::ErrorUserNotLogged.new unless user dnsmanagerd.storage.add_rr user.uid, @domain, @rr end end @@ -95,7 +95,7 @@ class DNSManager::Request def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON user = dnsmanagerd.get_logged_user event - raise NotLoggedException.new if user.nil? + return Response::ErrorUserNotLogged.new unless user dnsmanagerd.storage.update_rr user.uid, @domain, @rr end end @@ -110,7 +110,7 @@ class DNSManager::Request def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON user = dnsmanagerd.get_logged_user event - raise NotLoggedException.new if user.nil? + return Response::ErrorUserNotLogged.new unless user dnsmanagerd.storage.delete_rr user.uid, @domain, @rrid end end diff --git a/src/responses/error.cr b/src/responses/error.cr index 05d4ea8..1b1e666 100644 --- a/src/responses/error.cr +++ b/src/responses/error.cr @@ -17,5 +17,11 @@ class DNSManager::Response def initialize() end end - DNSManager.responses << ErrorInvalidToken + DNSManager.responses << DomainAlreadyExists + + IPC::JSON.message ErrorUserNotLogged, 4 do + def initialize() + end + end + DNSManager.responses << ErrorUserNotLogged end