View raw

1 open Dream_html 2 open Page_kit 3 open Page_shell 4 5 let auth_error = function None -> [] | Some message -> [ alert message ] 6 7 let credentials_form request ~submit ~action_path = 8 tag "form" 9 [ action action_path; post_form; Dream_html.attr "data-hito-app-form" ] 10 [ 11 Dream_html.csrf_tag request; 12 tag "div" 13 [ class_ "field" ] 14 [ 15 tag "label" 16 [ Dream_html.string_attr "for" "username" ] 17 [ txt "Username" ]; 18 void "input" 19 [ 20 type_ "text"; 21 name "username"; 22 Dream_html.string_attr "id" "username"; 23 Dream_html.string_attr "autocomplete" "username"; 24 required; 25 ]; 26 ]; 27 tag "div" 28 [ class_ "field" ] 29 [ 30 tag "label" 31 [ Dream_html.string_attr "for" "password" ] 32 [ txt "Password" ]; 33 void "input" 34 [ 35 type_ "password"; 36 name "password"; 37 Dream_html.string_attr "id" "password"; 38 Dream_html.string_attr "autocomplete" "current-password"; 39 required; 40 ]; 41 ]; 42 void "input" [ type_ "submit"; value submit ]; 43 ] 44 45 let login request ?error ?(registration_open = false) () = 46 let register_prompt = 47 if registration_open then 48 [ 49 tag "p" [] 50 [ 51 txt "No account yet? "; 52 tag "a" 53 [ href Routes.register; Dream_html.attr "data-hito-app-link" ] 54 [ txt "Register" ]; 55 ]; 56 ] 57 else [] 58 in 59 html_page ~active:"auth" ~show_footer:true "Sign in" 60 ([ 61 tag "h1" [] [ txt "Sign in" ]; 62 credentials_form request ~submit:"Sign in" ~action_path:Routes.login; 63 ] 64 @ register_prompt @ auth_error error) 65 66 let register request ?error () = 67 html_page ~active:"auth" ~show_footer:true "Register" 68 ([ 69 tag "h1" [] [ txt "Create an account" ]; 70 credentials_form request ~submit:"Register" ~action_path:Routes.register; 71 tag "p" [] 72 [ 73 txt "Already registered? "; 74 tag "a" 75 [ href Routes.login; Dream_html.attr "data-hito-app-link" ] 76 [ txt "Sign in" ]; 77 ]; 78 ] 79 @ auth_error error) 80