Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor user module a bit, make it cleaner and prepare for an admin …

…interface
  • Loading branch information...
commit c854ebbaf352406374365e9714ffa47e3b54ef2d 1 parent edd884c
Austin Seipp authored
Showing with 15 additions and 15 deletions.
  1. +1 −5 src/main.opa
  2. +14 −10 src/user.opa
View
6 src/main.opa
@@ -41,12 +41,8 @@ mainpage() = Resource.styled_page("Opaque blog - Main page", ["res/sh_nedit.min.
start =
| {path = [] ... } -> mainpage()
- | {path = ["admin" | _] ...} -> User.loginpage()
+ | {path = ["admin" | _] ...} -> User.mainpage()
| {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
24 src/user.opa
@@ -12,27 +12,31 @@ User = {{
@private state = UserContext.make({ notloggedin } : User.status)
- /* Get the current user status 'logged in, or not' */
+ /* Get the current user status - 'logged in, or not' */
get_status() = UserContext.execute((a -> a), state)
+ is_logged_in() =
+ match get_status() with
+ | {loggedin = _} -> true
+ | _ -> false
/* Main login page */
- loginpage() = Resource.html("User page",<div id=#login_box>{loginbox()}</div>)
+ mainpage() =
+ (t, p) = if is_logged_in() then ("User page", userpage()) else ("Login page", loginbox())
+ Resource.html(t, p)
- /* Login and login box */
+ /* Login box and login check */
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)
-
+ <div id=#login_box>{WLoginbox.html(WLoginbox.default_config, "login_box", login, Option.none)}</div>
login(username, pass) =
- user = ?/users[username]
- do match user with
+ do match ?/users[username] with
| {some = u} -> if u.passwd == Crypto.Hash.sha2(pass) then
UserContext.change(( _ -> { loggedin = username }), state)
| _ -> void
Client.reload()
+ userpage() =
+ <h3><a onclick={_ -> logout()}>Logout</a></h3>
+
/* Logout */
logout() =
do UserContext.change(( _ -> { notloggedin }), state)
Please sign in to comment.
Something went wrong with that request. Please try again.