tangled
alpha
login
or
join now
8bit.lol
/
pegasus
forked from
futur.blue/pegasus
0
fork
atom
objective categorical abstract machine language personal data server
0
fork
atom
overview
issues
pulls
pipelines
Add log out button
futur.blue
2 months ago
29f75f3c
6a511b27
verified
This commit was signed with the committer's
known signature
.
futur.blue
SSH Key Fingerprint:
SHA256:QHGqHWNpqYyw9bt8KmPuJIyeZX9SZewBZ0PR1COtKQ0=
+42
-15
5 changed files
expand all
collapse all
unified
split
frontend
src
components
AccountSidebar.mlx
Sidebar.mlx
frontend.opam
pegasus
lib
api
account_
logout.ml
session.ml
+1
-1
frontend.opam
···
12
12
"melange"
13
13
"melange-json"
14
14
"melange-json-native"
15
15
-
"mlx"
15
15
+
"mlx" {>= "0.11"}
16
16
"reason-react" {>= "0.16.0"}
17
17
"reason-react-ppx" {>= "0.16.0"}
18
18
"server-reason-react"
+4
frontend/src/components/AccountSidebar.mlx
···
1
1
[@@@ocaml.warning "-26-27"]
2
2
+
open React
2
3
3
4
type actor = AccountSwitcher.actor
4
5
···
14
15
header=(<AccountSwitcher
15
16
current_user logged_in_users add_account_url="/account/login"
16
17
/>)
18
18
+
footer=(<a href=("/account/logout?did=" ^ (Js.Global.encodeURIComponent current_user.did))>
19
19
+
<Button kind=`Secondary className="mt-2 justify-start pl-0">(string "log out")</Button>
20
20
+
</a>)
17
21
/>
+2
-1
frontend/src/components/Sidebar.mlx
···
2
2
3
3
open React
4
4
5
5
-
let[@react.component] make ~pages ~active_page ?header () =
5
5
+
let[@react.component] make ~pages ~active_page ?header ?footer () =
6
6
let selected_class = "text-mana-100 font-medium" in
7
7
let unselected_class = "text-mist-100 hover:text-mana-100" in
8
8
<aside className="flex flex-col gap-y-2 w-auto min-w-32 max-w-64">
···
17
17
pages
18
18
|> Array.of_list |> array )
19
19
</nav>
20
20
+
(match footer with Some f -> f | None -> null)
20
21
</aside>
+9
-2
pegasus/lib/api/account_/logout.ml
···
1
1
let handler =
2
2
Xrpc.handler (fun ctx ->
3
3
-
let%lwt () = Session.Raw.clear_session ctx.req in
4
4
-
Dream.redirect ctx.req "/account/login" )
3
3
+
let did = Dream.query ctx.req "did" in
4
4
+
let%lwt () =
5
5
+
match did with
6
6
+
| Some did ->
7
7
+
Session.log_out_did ctx.req did
8
8
+
| None ->
9
9
+
Session.log_out_all_dids ctx.req
10
10
+
in
11
11
+
Dream.redirect ctx.req "/account" )
+26
-11
pegasus/lib/session.ml
···
68
68
in
69
69
Dream.set_session_field req "pegasus.session" ""
70
70
71
71
-
let get_current_did req =
72
72
-
match%lwt get_session req with
73
73
-
| Some {current_did; _} when current_did <> None ->
74
74
-
Lwt.return current_did
75
75
-
| _ ->
76
76
-
Lwt.return_none
77
77
-
78
71
let set_current_did req did =
79
72
match%lwt get_session req with
80
73
| Some {logged_in_dids; session_id; admin_authenticated; _} ->
···
88
81
Lwt.return_unit
89
82
| None ->
90
83
Lwt.return_unit
84
84
+
85
85
+
let get_current_did req =
86
86
+
match%lwt get_session req with
87
87
+
| Some {current_did= Some did; _} ->
88
88
+
Lwt.return_some did
89
89
+
| Some {logged_in_dids= first :: _; _} ->
90
90
+
let%lwt () = set_current_did req first in
91
91
+
Lwt.return_some first
92
92
+
| _ ->
93
93
+
Lwt.return_none
91
94
92
95
let get_logged_in_dids req =
93
96
match%lwt get_session req with
···
133
136
let log_out_did req did =
134
137
match%lwt get_session req with
135
138
| Some {current_did; logged_in_dids; session_id; admin_authenticated} ->
139
139
+
let logged_in_dids = List.filter (fun d -> d <> did) logged_in_dids in
140
140
+
let current_did =
141
141
+
if current_did = Some did then List.nth_opt logged_in_dids 0
142
142
+
else current_did
143
143
+
in
136
144
let%lwt () =
137
145
set_session req
138
138
-
{ current_did
139
139
-
; logged_in_dids= List.filter (fun d -> d <> did) logged_in_dids
140
140
-
; session_id
141
141
-
; admin_authenticated }
146
146
+
{current_did; logged_in_dids; session_id; admin_authenticated}
147
147
+
in
148
148
+
Lwt.return_unit
149
149
+
| None ->
150
150
+
Lwt.return_unit
151
151
+
152
152
+
let log_out_all_dids req =
153
153
+
match%lwt get_session req with
154
154
+
| Some session ->
155
155
+
let%lwt () =
156
156
+
set_session req {session with logged_in_dids= []; current_did= None}
142
157
in
143
158
Lwt.return_unit
144
159
| None ->