Browse files

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

  • Loading branch information...
1 parent 7f2dbe0 commit f51a6cb8efc52f16131377219a552eafd12be01b @akoprow akoprow committed May 6, 2011
Showing with 108 additions and 5 deletions.
  1. +71 −0 src/login.opa
  2. +8 −1 src/main.opa
  3. +20 −2 src/pages.opa
  4. +1 −0 src/twopenny.opack
  5. +8 −2 src/user.opa
View
71 src/login.opa
@@ -0,0 +1,71 @@
+/*
+ * Twopenny. (C) MLstate - 2011
+ * @author Adam Koprowski
+**/
+
+package mlstate.twopenny
+
+import widgets.loginbox
+import components.login
+
+type Login.credentials =
+ { login : string
+ ; passwd : string
+ }
+
+type Login.private_state =
+ { user : option(User.ref)
+ }
+
+type Login.public_state = Login.private_state
+
+type Login.config = CLogin.config(Login.credentials, Login.private_state,
+ Login.public_state)
+
+type Login.component = CLogin.t(Login.credentials, Login.private_state,
+ Login.public_state)
+
+Login =
+
+ dom_id = "login"
+
+{{
+
+ @publish @server authenticate(cred : Login.credentials, state : Login.private_state)
+ : option(Login.private_state) =
+ do Log.debug("[LOGIN]", "authentication: [login:{cred.login}, passwd:{cred.passwd}]")
+ user_ref = User.mk_ref(cred.login)
+ match User.get(user_ref) with
+ | {none} -> none
+ | {some=user} ->
+ passwd = User.mk_passwd(cred.passwd)
+ if passwd == user.passwd then
+ some({user = some(user_ref)})
+ else
+ none
+
+ @private loginbox(onchange : Login.credentials -> void, state : Login.public_state)
+ : xhtml =
+ login_action(login, passwd) = onchange(~{login passwd})
+ user_opt = Option.map((user_ref -> <>{User.ref_to_string(user_ref)}</>), state.user)
+ WLoginbox.html(WLoginbox.default_config, dom_id, login_action, user_opt)
+
+ @private login_conf : Login.config =
+ { ~authenticate
+ ; get_credential(state : Login.private_state) : Login.public_state = state
+ ; ~loginbox
+ ; on_change(_, _) = void
+ ; dbpath = none
+ ; prelude = none
+ }
+
+ @private default_state : Login.private_state =
+ { user = none }
+
+ init() : Login.component =
+ CLogin.make(default_state, login_conf)
+
+ html(component : Login.component) : xhtml =
+ CLogin.html(component)
+
+}}
View
9 src/main.opa
@@ -10,13 +10,20 @@ package mlstate.twopenny
**/
twopenny_page((title, content, style))(_req) =
- body =
+ status =
+ <div id=#status>
+ <div id=#loginbox>
+ {Login.html(Login.init())}
+ </div>
+ </>
+ page =
<div id=#page>
<div id=#main>
{content}
</>
</>
|> apply_css(style, _)
+ body = <>{status}{page}</>
Resource.html(title, body)
resources = @static_include_directory("img")
View
22 src/pages.opa
@@ -67,15 +67,33 @@ page_css = css
body {
margin: 0px;
}
+ #status {
+ position: fixed;
+ top: 0px;
+ overflow: hidden;
+ width: 70%;
+ height: 30px;
+ margin: 0 15%;
+ z-index: 9999;
+ border: 1px dotted black;
+ border-top: none;
+ background: #666;
+ }
+ #page {
+ padding-top: 30px;
+ }
#main {
width: 800px;
margin: auto;
- height: 100%;
+ min-height: 500px;
padding: 15px;
border-left: 1px dotted black;
border-right: 1px dotted black;
background: #EEE;
- opacity: .7;
+ opacity: .8;
+ }
+ #loginbox {
+ float: right;
}
h2 {
color: #777;
View
1 src/twopenny.opack
@@ -7,3 +7,4 @@ msg_factory.opa
user.opa
label.opa
utils.opa
+login.opa
View
10 src/user.opa
@@ -11,6 +11,8 @@ type User.wallpaper =
; color : option(color)
}
+@abstract type passwd = string
+
type User.t =
/** Name of the user (this is not the login) **/
{ name : string
@@ -28,7 +30,7 @@ type User.t =
/** User's email **/
; email : Email.email
/** User's password (actually an MD5 hash of the password) **/
- ; passwd : string
+ ; passwd : passwd
/** User's profile photo **/
; photo : option(image)
/** User's wallpaper **/
@@ -50,7 +52,7 @@ User =
default_user_wallpaper : User.wallpaper =
{ img = some(default_user_wallpaper_img)
; tile = false
- ; color = some(Color.white)
+ ; color = Color.of_string("#155B9C")
}
max_profile_photo_size =
@@ -110,11 +112,15 @@ User =
url = some(Url.make("/img/user-bg/{user_ref}"))
repeat = if wallpaper.tile then none else some({css_none})
color = wallpaper.color
+ attached = some(void)
}
css {
background: {user_bg}
}
+ mk_passwd(pass : string) : passwd =
+ md5(pass)
+
}}
user_css = css

0 comments on commit f51a6cb

Please sign in to comment.