open Dream_html
open Page_kit
open Page_shell
let auth_error = function None -> [] | Some message -> [ alert message ]
let credentials_form request ~submit ~action_path =
tag "form"
[ action action_path; post_form; Dream_html.attr "data-hito-app-form" ]
[
Dream_html.csrf_tag request;
tag "div"
[ class_ "field" ]
[
tag "label"
[ Dream_html.string_attr "for" "username" ]
[ txt "Username" ];
void "input"
[
type_ "text";
name "username";
Dream_html.string_attr "id" "username";
Dream_html.string_attr "autocomplete" "username";
required;
];
];
tag "div"
[ class_ "field" ]
[
tag "label"
[ Dream_html.string_attr "for" "password" ]
[ txt "Password" ];
void "input"
[
type_ "password";
name "password";
Dream_html.string_attr "id" "password";
Dream_html.string_attr "autocomplete" "current-password";
required;
];
];
void "input" [ type_ "submit"; value submit ];
]
let login request ?error ?(registration_open = false) () =
let register_prompt =
if registration_open then
[
tag "p" []
[
txt "No account yet? ";
tag "a"
[ href Routes.register; Dream_html.attr "data-hito-app-link" ]
[ txt "Register" ];
];
]
else []
in
html_page ~active:"auth" ~show_footer:true "Sign in"
([
tag "h1" [] [ txt "Sign in" ];
credentials_form request ~submit:"Sign in" ~action_path:Routes.login;
]
@ register_prompt @ auth_error error)
let register request ?error () =
html_page ~active:"auth" ~show_footer:true "Register"
([
tag "h1" [] [ txt "Create an account" ];
credentials_form request ~submit:"Register" ~action_path:Routes.register;
tag "p" []
[
txt "Already registered? ";
tag "a"
[ href Routes.login; Dream_html.attr "data-hito-app-link" ]
[ txt "Sign in" ];
];
]
@ auth_error error)