Permalink
Browse files

add ability to change admin password

  • Loading branch information...
1 parent 7321424 commit be7f1f4bd79bb735a7e5cc2a33bdd699e35fae83 Austin Seipp committed Jun 13, 2011
Showing with 29 additions and 6 deletions.
  1. +25 −5 src/admin.opa
  2. +4 −1 src/layout.opa
View
@@ -15,14 +15,16 @@ Admin = {{
/* Get the current user status - 'logged in, or not' */
get_status() = UserContext.execute((a -> a), state)
- is_logged_in() =
+ get_status_option() =
match get_status() with
- | {loggedin = _} -> true
- | _ -> false
+ | {loggedin = n} -> Option.some(n)
+ | _ -> Option.none
+ is_logged_in() = Option.is_some(get_status_option())
+ get_logged_in() = Option.get(get_status_option())
/* Main login page */
mainpage() =
- (t, p) = if is_logged_in() then ("User page", adminpage()) else ("Login page", loginbox())
+ (t, p) = if is_logged_in() then ("Admin page", adminpage()) else ("Login page", loginbox())
Layout.styled_page(t, p)
/* Login box and login check */
@@ -35,15 +37,33 @@ Admin = {{
| _ -> void
Client.reload()
+
+ /* Main administrative page */
adminpage() =
+ <h3><a onclick={_ -> changepw()}>Change password</a></h3>
<h3><a onclick={_ -> logout()}>Logout</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())
+ 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)
+
/* Logout */
logout() =
do UserContext.change(( _ -> { notloggedin }), state)
Client.reload()
- // Initializes the admin user
+
+ /* Initializes the admin user */
@server init_admin_user() =
match ?/users["admin"] with
| {none} -> // NOTE: remove when done
View
@@ -12,6 +12,9 @@ Layout = {{
post_layout(p) =
<div id=#post>{Post.to_xhtml(p)}</div>
+ @client transform_content(s) =
+ Dom.transform([#content <- s])
+
@server default_layout(content) =
mem = get_mem_usage()
sysname = get_sys_sysname()
@@ -28,7 +31,7 @@ Layout = {{
<a href="/">{Config.author}</a>
<a class="extra" href="/">home</a>
</div>
- <>{content}</>
+ <div id=#content>{content}</div>
<div class="footer">
<div class="contact">
<p>

0 comments on commit be7f1f4

Please sign in to comment.