Skip to content

Commit 7c9132d

Browse files
authored
Merge pull request #390 from pfitaxel/secret
Make secret field not visible on first connection
2 parents c406219 + 2a9f525 commit 7c9132d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/main/learnocaml_main.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ end
250250

251251
open Args
252252

253-
let process_html_file orig_file dest_file base_url =
253+
let process_html_file orig_file dest_file base_url no_secret =
254254
let transform_tag e tag attrs attr =
255255
let attr_pair = ("", attr) in
256256
match List.assoc_opt attr_pair attrs with
@@ -266,6 +266,9 @@ let process_html_file orig_file dest_file base_url =
266266
| `Start_element ((e, "script"), attrs) -> transform_tag e "script" attrs "src"
267267
| `Start_element ((e, "img"), attrs) -> transform_tag e "img" attrs "src"
268268
| `Start_element ((e, "a"), attrs) -> transform_tag e "a" attrs "href"
269+
| `Start_element ((e, "div"),attrs)
270+
when no_secret && List.mem (("", "id"), "secret-section") attrs ->
271+
`Start_element ((e, "div"), (("", "style"), "display:none")::attrs)
269272
| t -> t)
270273
|> Markup.pretty_print
271274
|> Markup.write_html
@@ -330,9 +333,10 @@ let main o =
330333
Printf.printf "Base URL: %s\n%!" o.builder.Builder.base_url;
331334
Lwt_unix.files_of_directory o.builder.Builder.contents_dir
332335
|> Lwt_stream.iter_s (fun file ->
336+
let config_secret = json_config.ServerData.secret in
333337
if Filename.extension file = ".html" then
334-
process_html_file (o.builder.Builder.contents_dir/file)
335-
(o.app_dir/file) o.builder.Builder.base_url
338+
process_html_file (o.builder.Builder.contents_dir/file)
339+
(o.app_dir/file) o.builder.Builder.base_url (config_secret = None)
336340
else
337341
Lwt.return_unit) >>= fun () ->
338342
let if_enabled opt dir f = (match opt with

static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h4 id="txt_first_connection"><!-- First connection --></h4>
7575
<input id="login-nickname-input" type="text" placeholder="Nickname"
7676
minlength="2" autocomplete="off"></input>
7777
</div>
78-
<div>
78+
<div id="secret-section">
7979
<div id="txt_first_connection_secret"><!-- Enter the secret --></div>
8080
<div class="filler_h"></div>
8181
<input id="login-secret-input" type="text" placeholder="Secret"

0 commit comments

Comments
 (0)