Skip to content

Commit

Permalink
Merge pull request #28 from robur-coop/improve
Browse files Browse the repository at this point in the history
Improve things
  • Loading branch information
hannesm authored Sep 4, 2024
2 parents 4da3fb2 + 0e404c4 commit 54baf33
Show file tree
Hide file tree
Showing 11 changed files with 430 additions and 79 deletions.
18 changes: 16 additions & 2 deletions albatross.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,23 @@ module Make (P : Mirage_clock.PCLOCK) (S : Tcpip.Stack.V4V6) = struct
(Vmm_core.Name.create_of_path path)
t.policies)
in
let cmd = Option.map (fun p -> `Policy_cmd (`Policy_add p)) policy in
let policy =
Option.value
~default:
Vmm_core.(
Policy.
{
vms = 0;
cpuids = IS.empty;
memory = 0;
block = None;
bridges = String_set.empty;
})
policy
in
let cmd = `Policy_cmd (`Policy_add policy) in
let* key, cert =
key_cert ~is_ca:true ?cmd t.key domain
key_cert ~is_ca:true ~cmd t.key domain
(X509.Certificate.subject t.cert)
in
Ok (key, cert, [ cert ])
Expand Down
18 changes: 17 additions & 1 deletion assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,20 @@ function buttonLoading(btn, load, text) {
}
}


async function toggleUserStatus(uuid) {
try {
const response = await fetch("/api/admin/user/status/toggle", {
method: 'POST',
body: JSON.stringify({"uuid":uuid})
})
const data = await response.json();
if(data.status === 200) {
postAlert("bg-primary-300", data.data);
setTimeout(function () { window.location.reload()}, 1000);
} else {
postAlert("bg-secondary-300", data.data);
}
} catch (error) {
postAlert("bg-secondary-300", error);
}
}
32 changes: 5 additions & 27 deletions dashboard.ml
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
open Tyxml

let display_banner message =
if message != "" then
Tyxml_html.(
section
~a:
[
a_class
[
"w-full bg-primary-200 py-4 text-center text-gray-200 border \
border-primary-400 font-semibold flex justify-center px-5 \
space-x-5";
];
a_id "banner-message";
]
[
p [ txt message ];
button
~a:[ a_id "close-banner-btn"; a_onclick "closeBanner()" ]
[ i ~a:[ a_class [ "fa-solid fa-x text-sm" ] ] [] ];
])
else Tyxml_html.div []

let dashboard_layout ~icon ?(page_title = "Dashboard | Mollymawk")
?(message = "") ~content () =
let dashboard_layout (user : User_model.user) ~icon
?(page_title = "Dashboard | Mollymawk") ?message ~content () =
let page =
Html.(
html
Expand Down Expand Up @@ -152,17 +130,17 @@ let dashboard_layout ~icon ?(page_title = "Dashboard | Mollymawk")
a_class
[
"flex space-x-1 items-center \
cursor-pointer \
cursor-pointer uppercase \
hover:text-primary-500";
];
]
[ span [ txt "Account" ] ];
[ span [ txt user.name ] ];
];
];
];
];
];
display_banner message;
Utils.display_banner message;
section
~a:[ a_class [ "grid grid-cols-12 bg-gray-100 min-h-screen" ] ]
[
Expand Down
4 changes: 3 additions & 1 deletion middleware.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ let user_of_cookie users now reqd =

let auth_middleware now users handler reqd =
match user_of_cookie users now reqd with
| Ok _user -> handler reqd
| Ok user ->
if user.User_model.active then handler reqd
else redirect_to_login ~msg:"User account is deactivated." reqd ()
| Error (`Msg msg) ->
Logs.err (fun m ->
m "auth-middleware: No molly-session in cookie header.");
Expand Down
19 changes: 16 additions & 3 deletions sign_up.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ let register_page ~icon () =
div
~a:[ a_class [ "w-full max-w-lg mt-16 pb-16 mx-auto" ] ]
[
div
~a:
[
a_id "alert-container";
a_class
[
"absolute top-1/4 rounded-md right-4 z-50 \
w-fit space-y-2 p-4 shadow border \
text-wrap hidden";
];
]
[];
h1
~a:
[
Expand Down Expand Up @@ -296,21 +308,22 @@ let register_page ~icon () =
\ })\n\
\ const data = await response.json();\n\
\ if (data.status === 200) {\n\
\ window.location.replace('/dashboard')\n\
\ postAlert('bg-primary-300', \
'Account created. Waiting for activation by an administrator.')\n\
\ setTimeout(function () \
{window.location.replace('/dashboard')}, 3000);\n\
\ } else {\n\
\ \
form_alert.classList.remove('hidden')\n\
\ \
form_alert.classList.add('text-secondary-500', 'block')\n\
\ form_alert.textContent = data.data\n\
\ console.log(data);\n\
\ }\n\
\ } catch (error) {\n\
\ form_alert.classList.remove('hidden')\n\
\ \
form_alert.classList.add('text-secondary-500', 'block')\n\
\ form_alert.textContent = error\n\
\ return;\n\
\ }\n\
\ })\n\
\ </script>";
Expand Down
26 changes: 10 additions & 16 deletions storage.ml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
open Utils.Json

type t = {
version : int;
users : User_model.user list;
configuration : Configuration.t;
}
type t = { users : User_model.user list; configuration : Configuration.t }

let current_version = 1
let current_version = 2

let t_to_json t =
`Assoc
[
("version", `Int t.version);
("version", `Int current_version);
("users", `List (List.map User_model.user_to_json t.users));
("configuration", Configuration.to_json t.configuration);
]
Expand All @@ -24,6 +20,7 @@ let t_of_json json =
| Some (`Int v), Some (`List users), Some configuration ->
let* () =
if v = current_version then Ok ()
else if v = 1 then Ok ()
else
Error
(`Msg
Expand All @@ -34,12 +31,15 @@ let t_of_json json =
List.fold_left
(fun acc js ->
let* acc = acc in
let* user = User_model.user_of_json js in
let* user =
if v = 1 then User_model.user_v1_of_json js
else User_model.user_of_json js
in
Ok (user :: acc))
(Ok []) users
in
let* configuration = Configuration.of_json configuration in
Ok { version = v; users; configuration }
Ok { users; configuration }
| _ -> Error (`Msg "invalid data: no version and users field"))
| _ -> Error (`Msg "invalid data: not an assoc")

Expand All @@ -66,13 +66,7 @@ module Make (BLOCK : Mirage_block.S) = struct
let* t = t_of_json json in
Ok (disk, t)
| Ok None ->
Ok
( disk,
{
version = current_version;
users = [];
configuration = Configuration.empty ();
} )
Ok (disk, { users = []; configuration = Configuration.empty () })
| Error e ->
error_msgf "error while reading storage: %a" Stored_data.pp_error e

Expand Down
Loading

0 comments on commit 54baf33

Please sign in to comment.