Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 129 lines (107 sloc) 3.108 kB
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
1 /*
2 * Twopenny. (C) MLstate - 2011
3 * @author Adam Koprowski
4 **/
5
6 package mlstate.twopenny
7
87ea3af @Aqua-Ye [compilation-fix] replaced @wrap/@unwrap by @abstract + updated import
Aqua-Ye authored
8 import stdlib.widgets.{loginbox, switch}
9 import stdlib.components.login
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
10
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
11 type Toolbar.state = option(User.ref)
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
12
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
13 type Login.credentials = option((string, string))
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
14
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
15 type Login.config = CLogin.config(Login.credentials, Toolbar.state, Toolbar.state)
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
16
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
17 type Login.component = CLogin.t(Login.credentials, Toolbar.state, Toolbar.state)
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
18
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
19 Toolbar =
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
20
21 dom_id = "login"
22
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
23 sign_in_switch_id = "{dom_id}_sis"
24 login_box_id = "{dom_id}_lb"
25
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
26 {{
27
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
28 @private guest_state : Toolbar.state =
8a5a914 @akoprow Simplifying login logic & making it persistent...
akoprow authored
29 none
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
30
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
31 @publish @server authenticate(cred : Login.credentials, state : Toolbar.state)
32 : option(Toolbar.state) =
8a5a914 @akoprow Simplifying login logic & making it persistent...
akoprow authored
33 do Log.debug("[LOGIN]", "authentication: [{cred}]")
34 match cred with
35 | {none} -> none
36 | {some=(login, passwd)} ->
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
37 do jlog("Authenticating with [{login}, {passwd}]")
8a5a914 @akoprow Simplifying login logic & making it persistent...
akoprow authored
38 user_ref = User.mk_ref(login)
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
39 res =
8a5a914 @akoprow Simplifying login logic & making it persistent...
akoprow authored
40 match User.get(user_ref) with
41 | {none} -> none
42 | {some=user} ->
43 passwd = User.mk_passwd(passwd)
44 if passwd == user.passwd then
45 some(some(user_ref))
46 else
47 none
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
48 do jlog("Authenticating result: {res}")
49 res
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
50
51 @private login_conf : Login.config =
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
52 CLogin.default_config(Random.string(8), authenticate)
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
53
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
54 login_btn_cfg = WButton.default_config
55
8a5a914 @akoprow Simplifying login logic & making it persistent...
akoprow authored
56 login : Login.component =
57 CLogin.make(guest_state, login_conf)
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
58
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
59 login_box() =
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
60 btn_txt = "Register"
61 onclick = ({click}, (_ -> void))
62 signup = WButton.html(login_btn_cfg, Random.string(8), [onclick], <>{btn_txt}</>)
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
63 <span id=#{login_box_id} class=loginbox>
64 {CLogin.html(login)}
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
65 <span class="signup">
66 Don't have an account yet? {signup}
67 </>
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
68 </>
69
70 @client login_switch_btn(on, action) =
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
71 control = if on then "↑" else "↓"
72 btn_txt = "Sign in/up {control}"
73 onclick = ({click}, action)
74 xhtml = WButton.html(login_btn_cfg, Random.string(8), [onclick], <>{btn_txt}</>)
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
75 update_dom = if on then Dom.show else Dom.hide
76 do update_dom(#{login_box_id})
77 { update_xhtml=xhtml }
78
79 login_switch() =
80 cfg : WSwitch.config =
81 {
82 get_switch_on(_, action, _) = login_switch_btn(true, action)
83 get_switch_off(_, action, _) = login_switch_btn(false, action)
84 }
85 WSwitch.edit(cfg, sign_in_switch_id, (_ -> void), false)
86
8a5a914 @akoprow Simplifying login logic & making it persistent...
akoprow authored
87 html() : xhtml =
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
88 <div id=#toolbar_container>
89 <div id=#toolbar>
90 <div id=#signin>
91 {login_switch()}
92 {login_box()}
93 </>
94 </>
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
95 </>
f51a6cb @akoprow Plugging-in the login component (for now mostly mock-up).
akoprow authored
96
97 }}
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
98
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
99 toolbar_css = css
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
100 td{}
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
101 #toolbar_container {
102 position: fixed;
103 top: 0px;
104 overflow: hidden;
105 width: 100%;
106 height: 30px;
107 z-index: 9999;
108 border: 1px dotted ;
109 border-top: none;
110 background: #666;
111 }
112 #toolbar {
113 width: 600px;
114 margin: auto;
115 }
116 #signin {
117 float: right;
118 }
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
119 .loginbox {
120 position: fixed;
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
121 top: 30px;
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
122 background: #666;
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
123 border: 1px dotted black;
124 border-top: none;
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
125 padding: 12px;
ff2db73 @akoprow New module Toolbar (mostly taking over previous Login).
akoprow authored
126 border-bottom-left-radius: 8px;
127 border-bottom-right-radius: 8px;
e8a51e3 @akoprow Login box, whose visibility is toggled with a 'Sing in' button.
akoprow authored
128 }
Something went wrong with that request. Please try again.