Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 6d6056d50ce8aaa4451e4c1c2ae7d9ec57cf927a 1 parent 9fc4702
Austin Seipp authored
View
16 src/main.opa
@@ -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
4 src/mathjax.opa
@@ -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
5 src/shjs.opa
@@ -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
4 src/upskirt.opa
@@ -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
35 src/user.opa
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.