Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[feature] WLoginbox: Added support for HTTPS in loginbox and correspo…

…nding option in CLogin
  • Loading branch information...
commit f75600266140cc326af7629d097827e1869bdf87 1 parent 07b3240
Nicolas Glondu authored
View
52 stdlib/components/login/login.opa
@@ -138,6 +138,24 @@ CLogin = {{
/**
* {1 Some configurations}
*/
+
+ @private default_config_builder(id, authenticate, https_host) : CLogin.config(option((string, string)), option('a), option('a)) =
+ logout(dochange) = <a onclick={_ -> do (dochange(none):void)
+ WLoginbox.set_logged_out(id, <></>)}>Logout</a>
+ get_credential(x) = x
+ loginbox(dochange, credential) =
+ box_config = { WLoginbox.default_config with ~https_host } : WLoginbox.config
+ make_html = WLoginbox.html(box_config, id, (n, p -> dochange(some((n,p)))), _)
+ match credential
+ | {none} -> make_html(none)
+ | {some=_credential} -> make_html(some(logout(dochange)))
+ on_change(dochange, credential) =
+ match credential
+ | {some=_} -> WLoginbox.set_logged_in(id, logout(dochange))
+ | _ -> WLoginbox.set_logged_out(id, <>Invalid password</>)
+ prelude = none
+ { ~authenticate ~get_credential ~loginbox ~on_change ~prelude }
+
/**
* The default configuration using widget login box (@see
* WLoginbox). Data used for logged ([`login_data]) is the [(name,
@@ -153,23 +171,25 @@ CLogin = {{
* - when logged : 1 unlog button
*/
default_config(id, authenticate) : CLogin.config(option((string, string)), option('a), option('a)) =
- logout(dochange) = <a onclick={_ -> do (dochange(none):void)
- WLoginbox.set_logged_out(id, <></>)}>Logout</a>
- get_credential(x) = x
- loginbox(dochange, credential) =
- make_html = WLoginbox.html_default(id, (n, p -> dochange(some((n,p)))), _)
- match credential
- | {none} -> make_html(none)
- | {some=_credential} -> make_html(some(logout(dochange)))
- on_change(dochange, credential) =
- match credential
- | {some=_} -> WLoginbox.set_logged_in(id, logout(dochange))
- | _ -> WLoginbox.set_logged_out(id, <>Invalid password</>)
- prelude = none
- { ~authenticate ~get_credential ~loginbox ~on_change ~prelude }
-
-
+ default_config_builder(id, authenticate, none)
+ /**
+ * The default configuration using widget login box (@see
+ * WLoginbox). Data used for logged ([`login_data]) is the [(name,
+ * password)] couple. The state is an option [none] means not logged
+ * and some means logged with a custom encapsulated state. [`state]
+ * is strictely equals to [`credential] for this version
+ * ([get_credential = identity]).
+ * In this version the POST is made through HTTPS
+ *
+ * If you use this [default_config] you should certainly overwrite
+ * [loginbox] and [on_change] fields. Indeed that configuration just
+ * switch beetween two views :
+ * - when not logged : 2 inputs (name, password) + 1 log button
+ * - when logged : 1 unlog button
+ */
+ default_config_ssl_post(id, authenticate, https_addr) : CLogin.config(option((string, string)), option('a), option('a)) =
+ default_config_builder(id, authenticate, some(https_addr))
/**
* {1 Actions on login component}
View
35 stdlib/widgets/loginbox/loginbox.opa
@@ -38,14 +38,15 @@ type WLoginbox.stylers = {
}
type WLoginbox.config = {
- login_text : string
- login_label : option(string)
- password_label : option(string)
- login_placeholder : option(string)
+ https_host : option(string)
+ login_text : string
+ login_label : option(string)
+ password_label : option(string)
+ login_placeholder : option(string)
password_placeholder : option(string)
- password_help : option(xhtml)
- fading_time : int // in ms
- stylers : WLoginbox.stylers
+ password_help : option(xhtml)
+ fading_time : int // in ms
+ stylers : WLoginbox.stylers
}
/** Display a login or the logged user if there is one. */
@@ -61,13 +62,14 @@ WLoginbox =
{{
default_config = {
- login_text = "Login"
- login_label = none
- password_label = none
- login_placeholder = some("username")
+ https_host = none
+ login_text = "Login"
+ login_label = none
+ password_label = none
+ login_placeholder = some("username")
password_placeholder = some("password")
- password_help = none
- fading_time = 0
+ password_help = none
+ fading_time = 0
stylers = {
login_box = WStyler.empty
logged_box = WStyler.empty
@@ -139,6 +141,9 @@ WLoginbox =
login_action: (string, string -> void),
usr_opt: option(xhtml))
: xhtml =
+ prepend = match config.https_host with
+ | {none} -> ""
+ | {some=h} -> h
form_id = "{id}__form"
iframe_id = "{id}__iframe"
_button_id = "{id}__button" //TODO use widgets button when fixed
@@ -151,8 +156,8 @@ WLoginbox =
([], css{display: none;}), usr_opt)
login_form(init_username: string, init_password: string) =
/* ugly hack : needs iframe to be the fake target of the submit form */
- <iframe src="{fake_url_1}" id="{iframe_id}" name="{iframe_id}" style="display:none;with:0px;height:0px;"></iframe>
- <form target="{iframe_id}" method="post" action="{fake_url_2}" name="{form_id}" id="{form_id}" autocomplete="on" onsubmit={on_login(id, login_action)} >
+ <iframe src="{prepend}{fake_url_1}" id="{iframe_id}" name="{iframe_id}" style="display:none;with:0px;height:0px;"></iframe>
+ <form target="{iframe_id}" method="post" action="{prepend}{fake_url_2}" name="{form_id}" id="{form_id}" autocomplete="on" onsubmit={on_login(id, login_action)} >
<span id={get_not_logged_id(id)} style={login_css}>
{match config.login_label
{some=s} -> <label for={username_id}>{s}</label>
Please sign in to comment.
Something went wrong with that request. Please try again.