Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move all posting stuff behind admin password, in prep for actually ma…

…king this a blog
  • Loading branch information...
commit e24d3f1eb465ff849bb50d549e09f830e9c41321 1 parent be7f1f4
Austin Seipp authored
Showing with 41 additions and 36 deletions.
  1. +37 −9 src/admin.opa
  2. +2 −2 src/layout.opa
  3. +2 −25 src/main.opa
View
46 src/admin.opa
@@ -1,7 +1,14 @@
package opaque.admin
import widgets.loginbox
+
import opaque.layout
+// plugins
+import opaque.bsl.native
+import opaque.bsl.mathjax
+import opaque.bsl.shjs
+import opaque.bsl.upskirt
+
// User types and user database
type Admin.user = { passwd: string }
type Admin.status = { loggedin: string } / { notloggedin }
@@ -24,12 +31,13 @@ Admin = {{
/* Main login page */
mainpage() =
- (t, p) = if is_logged_in() then ("Admin page", adminpage()) else ("Login page", loginbox())
- Layout.styled_page(t, p)
+ if is_logged_in() then adminpage() else loginbox()
/* Login box and login check */
loginbox() =
- <div id=#login_box>{WLoginbox.html(WLoginbox.default_config, "login_box", login, Option.none)}</div>
+ Layout.styled_page("Login page",
+ <div id=#login_box>{WLoginbox.html(WLoginbox.default_config, "login_box", login, Option.none)}</div>
+ )
login(username, pass) =
do match ?/users[username] with
| {some = u} -> if u.passwd == Crypto.Hash.sha2(pass) then
@@ -37,32 +45,52 @@ Admin = {{
| _ -> void
Client.reload()
-
/* Main administrative page */
adminpage() =
- <h3><a onclick={_ -> changepw()}>Change password</a></h3>
- <h3><a onclick={_ -> logout()}>Logout</a></h3>
+ Layout.styled_page("Admin page",
+ <h3><a onclick={_ -> changepw()}>Change password</a></h3>
+ <h3><a onclick={_ -> logout()}>Logout</a></h3>
+ <h3><a onclick={_ -> newpost()}>New post</a></h3>
+ )
/* Changing passwords */
changepw() =
update_db(p) =
username = get_logged_in()
do /users[username] <- { passwd = Crypto.Hash.sha2(p) }
- do Client.reload()
do Debug.jlog("Updated password for user '" ^ username ^ "'")
- Layout.transform_content(mainpage())
+ Client.reload()
update_form =
<h3>New password:</h3><br />
<input id=#newpasswd /><br />
<button type="button" onclick={_ -> update_db(Dom.get_value(#newpasswd))}>Submit</button>
Layout.transform_content(update_form)
+ /* New posts */
+ @private @publish update_preview() =
+ v = Upskirt.render_to_xhtml(Dom.get_value(#post_entry))
+ do Dom.transform([#preview_output <- v])
+ do MathJax.reload(#preview_output)
+ SHJS.highlight()
+
+ post_form() =
+ <div id=#inputarea>
+ <textarea rows=20 cols=80 id=#post_entry /><br/>
+ <button type="button" onclick={_ -> update_preview()}>Preview</button><br />
+ <button type="button" >Publish</button>
+ <h3><a href="/admin">Go back to admin page</a></h3>
+ </div>
+ <br/>
+ <p>Preview:</p><br/><div id=#preview_output></div>
+
+ newpost() =
+ Layout.transform_content(post_form())
+
/* Logout */
logout() =
do UserContext.change(( _ -> { notloggedin }), state)
Client.reload()
-
/* Initializes the admin user */
@server init_admin_user() =
match ?/users["admin"] with
View
4 src/layout.opa
@@ -13,7 +13,7 @@ Layout = {{
<div id=#post>{Post.to_xhtml(p)}</div>
@client transform_content(s) =
- Dom.transform([#content <- s])
+ Dom.transform([#page_content <- s])
@server default_layout(content) =
mem = get_mem_usage()
@@ -31,7 +31,7 @@ Layout = {{
<a href="/">{Config.author}</a>
<a class="extra" href="/">home</a>
</div>
- <div id=#content>{content}</div>
+ <div id=#page_content>{content}</div>
<div class="footer">
<div class="contact">
<p>
View
27 src/main.opa
@@ -3,32 +3,9 @@ import opaque.admin
import opaque.layout
import opaque.config
-// plugins
-import opaque.bsl.native
-import opaque.bsl.mathjax
-import opaque.bsl.shjs
-import opaque.bsl.upskirt
-
-room = Network.cloud("room"): Network.network(xhtml)
-
-@client broadcast(s) =
- do Dom.transform([#output <- s])
- do MathJax.reload(#output)
- SHJS.highlight()
-
-@publish update() =
- v = Upskirt.render_to_xhtml(Dom.get_value(#entry))
- do Network.broadcast(v, room)
- Dom.clear_value(#entry)
-
mainpage() = Layout.styled_page(Config.title,
- <p>Result:</p><br/><div id=#output onready={_ -> Network.add_callback(broadcast, room)}></div>
- <br/>
- <div id=#inputarea>
- <textarea rows=20 cols=80 id=#entry /><br/>
- <button type="button" onclick={_ -> update()}>Submit</button>
- </div>
- )
+ <h1>Hello world!</h1>
+)
start =
| {path = [] ... } -> mainpage()
Please sign in to comment.
Something went wrong with that request. Please try again.