Skip to content

Commit

Permalink
Plugging-in the login component (for now mostly mock-up).
Browse files Browse the repository at this point in the history
  • Loading branch information
akoprow committed May 6, 2011
1 parent 7f2dbe0 commit f51a6cb
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 5 deletions.
71 changes: 71 additions & 0 deletions src/login.opa
Original file line number Diff line number Diff line change
@@ -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)

}}
9 changes: 8 additions & 1 deletion src/main.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
22 changes: 20 additions & 2 deletions src/pages.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/twopenny.opack
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ msg_factory.opa
user.opa
label.opa
utils.opa
login.opa
10 changes: 8 additions & 2 deletions src/user.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 **/
Expand All @@ -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 =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f51a6cb

Please sign in to comment.