Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Login box, whose visibility is toggled with a 'Sing in' button.

  • Loading branch information...
commit e8a51e348a3f7a2b89f8dce4abb3ef6537bc92a7 1 parent 8a5a914
Adam Koprowski akoprow authored
Showing with 59 additions and 9 deletions.
  1. +1 −0  Makefile
  2. +46 −3 src/login.opa
  3. +6 −4 src/main.opa
  4. +6 −2 src/pages.opa
1  Makefile
View
@@ -13,6 +13,7 @@ SRC = $(addprefix src/, $(shell cat $(PACK)))
main.exe: $(PACK) $(SRC)
$(OPA) $< -o $@
+ notify-send -t 5000 "$@ compilation finished" &> /dev/null & beep &> /dev/null
run: main.exe
./main.exe
49 src/login.opa
View
@@ -5,7 +5,7 @@
package mlstate.twopenny
-import widgets.loginbox
+import widgets.{loginbox, switch}
import components.login
type Login.credentials = option((string, string))
@@ -20,6 +20,9 @@ Login =
dom_id = "login"
+ sign_in_switch_id = "{dom_id}_sis"
+ login_box_id = "{dom_id}_lb"
+
{{
@private guest_state : Login.state =
@@ -31,7 +34,9 @@ Login =
match cred with
| {none} -> none
| {some=(login, passwd)} ->
+ do jlog("Authenticating with [{login}, {passwd}]")
user_ref = User.mk_ref(login)
+ res =
match User.get(user_ref) with
| {none} -> none
| {some=user} ->
@@ -40,14 +45,52 @@ Login =
some(some(user_ref))
else
none
+ do jlog("Authenticating result: {res}")
+ res
@private login_conf : Login.config =
- CLogin.default_config(dom_id, authenticate)
+ CLogin.default_config(Random.string(8), authenticate)
login : Login.component =
CLogin.make(guest_state, login_conf)
+ login_box() =
+ <span id=#{login_box_id} class=loginbox>
+ {CLogin.html(login)}
+ </>
+
+ @client login_switch_btn(on, action) =
+ btn_cfg = WButton.default_config
+ btn_txt = "Sign in/up"
+ actions = [({click}, action)]
+ xhtml = WButton.html(btn_cfg, Random.string(8), actions, <>{btn_txt}</>)
+ update_dom = if on then Dom.show else Dom.hide
+ do update_dom(#{login_box_id})
+ { update_xhtml=xhtml }
+
+ login_switch() =
+ cfg : WSwitch.config =
+ {
+ get_switch_on(_, action, _) = login_switch_btn(true, action)
+ get_switch_off(_, action, _) = login_switch_btn(false, action)
+ }
+ WSwitch.edit(cfg, sign_in_switch_id, (_ -> void), false)
+
html() : xhtml =
- CLogin.html(login)
+ <>
+ {login_switch()}
+ {login_box()}
+ </>
}}
+
+login_css = css
+ td{}
+ .loginbox {
+ position: fixed;
+ top: 34px;
+ background: #666;
+ padding: 12px;
+ border-radius: 8px;
+ border: 1px dotted #CCC;
+ }
10 src/main.opa
View
@@ -11,10 +11,12 @@ package mlstate.twopenny
twopenny_page((title, content, style))(_req) =
status =
- <div id=#status>
- <div id=#loginbox>
- {Login.html()}
- </div>
+ <div id=#status_container>
+ <div id=#status>
+ <div id=#loginbox>
+ {Login.html()}
+ </>
+ </>
</>
page =
<div id=#page>
8 src/pages.opa
View
@@ -57,7 +57,7 @@ Pages = {{
}}
-css = [ page_css, msg_css, msg_box_css, user_css ]
+css = [ page_css, login_css, msg_css, msg_box_css, user_css ]
page_css = css
body, html, #page {
@@ -68,7 +68,7 @@ page_css = css
margin: 0px;
position: relative;
}
- #status {
+ #status_container {
position: fixed;
top: 0px;
overflow: hidden;
@@ -79,6 +79,10 @@ page_css = css
border-top: none;
background: #666;
}
+ #status {
+ width: 600px;
+ margin: auto;
+ }
#page {
padding-top: 30px;
}
Please sign in to comment.
Something went wrong with that request. Please try again.