Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Plugging-in the login component (for now mostly mock-up).

  • Loading branch information...
commit f51a6cb8efc52f16131377219a552eafd12be01b 1 parent 7f2dbe0
Adam Koprowski akoprow authored
71 src/login.opa
... ... @@ -0,0 +1,71 @@
  1 +/*
  2 + * Twopenny. (C) MLstate - 2011
  3 + * @author Adam Koprowski
  4 +**/
  5 +
  6 +package mlstate.twopenny
  7 +
  8 +import widgets.loginbox
  9 +import components.login
  10 +
  11 +type Login.credentials =
  12 + { login : string
  13 + ; passwd : string
  14 + }
  15 +
  16 +type Login.private_state =
  17 + { user : option(User.ref)
  18 + }
  19 +
  20 +type Login.public_state = Login.private_state
  21 +
  22 +type Login.config = CLogin.config(Login.credentials, Login.private_state,
  23 + Login.public_state)
  24 +
  25 +type Login.component = CLogin.t(Login.credentials, Login.private_state,
  26 + Login.public_state)
  27 +
  28 +Login =
  29 +
  30 + dom_id = "login"
  31 +
  32 +{{
  33 +
  34 + @publish @server authenticate(cred : Login.credentials, state : Login.private_state)
  35 + : option(Login.private_state) =
  36 + do Log.debug("[LOGIN]", "authentication: [login:{cred.login}, passwd:{cred.passwd}]")
  37 + user_ref = User.mk_ref(cred.login)
  38 + match User.get(user_ref) with
  39 + | {none} -> none
  40 + | {some=user} ->
  41 + passwd = User.mk_passwd(cred.passwd)
  42 + if passwd == user.passwd then
  43 + some({user = some(user_ref)})
  44 + else
  45 + none
  46 +
  47 + @private loginbox(onchange : Login.credentials -> void, state : Login.public_state)
  48 + : xhtml =
  49 + login_action(login, passwd) = onchange(~{login passwd})
  50 + user_opt = Option.map((user_ref -> <>{User.ref_to_string(user_ref)}</>), state.user)
  51 + WLoginbox.html(WLoginbox.default_config, dom_id, login_action, user_opt)
  52 +
  53 + @private login_conf : Login.config =
  54 + { ~authenticate
  55 + ; get_credential(state : Login.private_state) : Login.public_state = state
  56 + ; ~loginbox
  57 + ; on_change(_, _) = void
  58 + ; dbpath = none
  59 + ; prelude = none
  60 + }
  61 +
  62 + @private default_state : Login.private_state =
  63 + { user = none }
  64 +
  65 + init() : Login.component =
  66 + CLogin.make(default_state, login_conf)
  67 +
  68 + html(component : Login.component) : xhtml =
  69 + CLogin.html(component)
  70 +
  71 +}}
9 src/main.opa
@@ -10,13 +10,20 @@ package mlstate.twopenny
10 10 **/
11 11
12 12 twopenny_page((title, content, style))(_req) =
13   - body =
  13 + status =
  14 + <div id=#status>
  15 + <div id=#loginbox>
  16 + {Login.html(Login.init())}
  17 + </div>
  18 + </>
  19 + page =
14 20 <div id=#page>
15 21 <div id=#main>
16 22 {content}
17 23 </>
18 24 </>
19 25 |> apply_css(style, _)
  26 + body = <>{status}{page}</>
20 27 Resource.html(title, body)
21 28
22 29 resources = @static_include_directory("img")
22 src/pages.opa
@@ -67,15 +67,33 @@ page_css = css
67 67 body {
68 68 margin: 0px;
69 69 }
  70 + #status {
  71 + position: fixed;
  72 + top: 0px;
  73 + overflow: hidden;
  74 + width: 70%;
  75 + height: 30px;
  76 + margin: 0 15%;
  77 + z-index: 9999;
  78 + border: 1px dotted black;
  79 + border-top: none;
  80 + background: #666;
  81 + }
  82 + #page {
  83 + padding-top: 30px;
  84 + }
70 85 #main {
71 86 width: 800px;
72 87 margin: auto;
73   - height: 100%;
  88 + min-height: 500px;
74 89 padding: 15px;
75 90 border-left: 1px dotted black;
76 91 border-right: 1px dotted black;
77 92 background: #EEE;
78   - opacity: .7;
  93 + opacity: .8;
  94 + }
  95 + #loginbox {
  96 + float: right;
79 97 }
80 98 h2 {
81 99 color: #777;
1  src/twopenny.opack
@@ -7,3 +7,4 @@ msg_factory.opa
7 7 user.opa
8 8 label.opa
9 9 utils.opa
  10 +login.opa
10 src/user.opa
@@ -11,6 +11,8 @@ type User.wallpaper =
11 11 ; color : option(color)
12 12 }
13 13
  14 +@abstract type passwd = string
  15 +
14 16 type User.t =
15 17 /** Name of the user (this is not the login) **/
16 18 { name : string
@@ -28,7 +30,7 @@ type User.t =
28 30 /** User's email **/
29 31 ; email : Email.email
30 32 /** User's password (actually an MD5 hash of the password) **/
31   - ; passwd : string
  33 + ; passwd : passwd
32 34 /** User's profile photo **/
33 35 ; photo : option(image)
34 36 /** User's wallpaper **/
@@ -50,7 +52,7 @@ User =
50 52 default_user_wallpaper : User.wallpaper =
51 53 { img = some(default_user_wallpaper_img)
52 54 ; tile = false
53   - ; color = some(Color.white)
  55 + ; color = Color.of_string("#155B9C")
54 56 }
55 57
56 58 max_profile_photo_size =
@@ -110,11 +112,15 @@ User =
110 112 url = some(Url.make("/img/user-bg/{user_ref}"))
111 113 repeat = if wallpaper.tile then none else some({css_none})
112 114 color = wallpaper.color
  115 + attached = some(void)
113 116 }
114 117 css {
115 118 background: {user_bg}
116 119 }
117 120
  121 + mk_passwd(pass : string) : passwd =
  122 + md5(pass)
  123 +
118 124 }}
119 125
120 126 user_css = css

0 comments on commit f51a6cb

Please sign in to comment.
Something went wrong with that request. Please try again.