Permalink
Browse files

reorganization, and add an actual login page (mostly lifted from opacms)

  • Loading branch information...
1 parent 9fc4702 commit 6d6056d50ce8aaa4451e4c1c2ae7d9ec57cf927a Austin Seipp committed Jun 6, 2011
Showing with 56 additions and 8 deletions.
  1. +12 −4 src/main.opa
  2. +3 −1 src/mathjax.opa
  3. +4 −1 src/shjs.opa
  4. +3 −1 src/upskirt.opa
  5. +34 −1 src/user.opa
View
@@ -9,17 +9,15 @@ room = Network.cloud("room"): Network.network(xhtml)
@client broadcast(s) =
do Dom.transform([#output <- s])
- do Debug.jlog("Now reloading mathjax and rehighlighting...")
do MathJax.reload(#output)
SHJS.highlight()
update() =
- do Debug.jlog("Upskirting entry...")
v = Upskirt.render_to_xhtml(Dom.get_value(#entry))
do Network.broadcast(v, room)
Dom.clear_value(#entry)
-start() =
+mainpage() = Resource.styled_page("Opaque blog - Main page", ["res/sh_nedit.min.css", "res/style.css"],
mem = get_mem_usage()
sysname = get_sys_sysname()
nodename = get_sys_nodename()
@@ -39,6 +37,16 @@ start() =
<textarea rows=50 cols=80 id=#entry /><br/>
<button type="button" onclick={_ -> update()}>Submit</button>
</div>
+ )
-server = Server.one_page_bundle("Opaque blog", [@static_resource_directory("res")],
+start =
+ | {path = [] ... } -> mainpage()
+ | {path = ["admin" | _] ...} -> User.loginpage()
+ | {path = _ ...} -> mainpage()
+
+server = Server.of_bundle([@static_resource_directory("res")])
+server = Server.simple_dispatch(start)
+/*
+server = Server.one_page_bundle("Opaque blog",[@static_resource_directory("res")],
["res/sh_nedit.min.css", "res/style.css"], start)
+*/
View
@@ -2,5 +2,7 @@ package opaque.mathjax
@client MathJax = {{
reload_id = %%mathjax.mj_reload_dom%%
- reload(elem) = reload_id(Dom.get_id(elem))
+ reload(elem) =
+ do Debug.jlog("Now reloading mathjax")
+ reload_id(Dom.get_id(elem))
}}
View
@@ -1,5 +1,8 @@
package opaque.shjs
@client SHJS = {{
- highlight = %%shjs.shjs_highlight_doc%%
+ highlight_page = %%shjs.shjs_highlight_doc%%
+ highlight() =
+ do Debug.jlog("Rehighlighting page")
+ highlight_page()
}}
View
@@ -2,5 +2,7 @@ package opaque.upskirt
@server Upskirt = {{
render = %%upskirt.render_str%%
- render_to_xhtml(s) = Xhtml.to_xhtml({content_unsafe = render(s)})
+ render_to_xhtml(s) =
+ do Debug.jlog("Upskirt'd an entry")
+ Xhtml.of_string_unsafe(render(s))
}}
View
@@ -1,10 +1,43 @@
package opaque.user
+import widgets.loginbox
// User types and user database
-type User.user = { passwd: string }
+type User.user = { passwd: string }
+type User.status = { loggedin: string } / { notloggedin }
+type User.info = UserContext.t(User.status)
+
db /users : stringmap(User.user)
User = {{
+
+ @private state = UserContext.make({ notloggedin } : User.status)
+
+ /* Get the current user status 'logged in, or not' */
+ get_status() = UserContext.execute((a -> a), state)
+
+ /* Main login page */
+ loginpage() = Resource.html("User page",<div id=#login_box>{loginbox()}</div>)
+
+ /* Login and login box */
+ loginbox() =
+ opt = match get_status() with
+ | {loggedin = _} -> Option.some(<><a onclick={_ -> logout()}>Logout</a></>)
+ | _ -> Option.none
+ WLoginbox.html(WLoginbox.default_config, "login_box", login, opt)
+
+ login(username, pass) =
+ user = ?/users[username]
+ do match user with
+ | {some = u} -> if u.passwd == Crypto.Hash.sha2(pass) then
+ UserContext.change(( _ -> { loggedin = username }), state)
+ | _ -> void
+ Client.reload()
+
+ /* Logout */
+ logout() =
+ do UserContext.change(( _ -> { notloggedin }), state)
+ Client.reload()
+
// Initializes the admin user
@server init_admin_user() =
match ?/users["admin"] with

0 comments on commit 6d6056d

Please sign in to comment.