Skip to content

Commit b91050e

Browse files
authored
fix(learnocaml_common.ml): Ask token (not secret) when opening exercise url (#489)
1 parent 6cb82d6 commit b91050e

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/app/learnocaml_common.ml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,17 +1106,23 @@ let get_token ?(has_server = true) () =
11061106
try
11071107
Some Learnocaml_local_storage.(retrieve sync_token) |>
11081108
Lwt.return
1109-
with Not_found ->
1109+
with
1110+
Not_found ->
11101111
retrieve (Learnocaml_api.Nonce ())
11111112
>>= fun nonce ->
1112-
ask_string ~title:"Secret"
1113-
[H.txt [%i"Enter the secret"]]
1114-
>>= fun secret ->
1115-
retrieve
1116-
(Learnocaml_api.Create_token (Sha.sha512 (nonce ^ Sha.sha512 secret), None, None))
1117-
>|= fun token ->
1118-
Learnocaml_local_storage.(store sync_token) token;
1119-
Some token
1113+
ask_string ~title:"Token"
1114+
[H.txt [%i"Enter your token"]]
1115+
>>= fun input_tok ->
1116+
let token = Token.parse (input_tok) in
1117+
Server_caller.request (Learnocaml_api.Fetch_save token)
1118+
>>= function
1119+
| Ok save ->
1120+
set_state_from_save_file ~token save;
1121+
Lwt.return_some token
1122+
| _ ->
1123+
alert ~title:[%i"TOKEN NOT FOUND"]
1124+
[%i"The entered token couldn't be recognised."];
1125+
Lwt.return_none
11201126
11211127
module Display_exercise =
11221128
functor (

src/app/learnocaml_common.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ val setup_tab_text_prelude_pane : string -> unit
232232

233233
val setup_prelude_pane : 'a Ace.editor -> string -> unit
234234

235-
val get_token : ?has_server:bool -> unit -> Learnocaml_data.student Learnocaml_data.token option Lwt.t
235+
val get_token : ?has_server:bool -> unit -> Learnocaml_data.Token.t option Lwt.t
236236

237237
module Display_exercise :functor
238238
(_ : sig

0 commit comments

Comments
 (0)