Warning: Reason support is experimental. We are looking for beta-tester and contributors.

Lightweight database using Ocsipersist

For maintaining the list of user and password, we do not need the full power of a SQL database, a key/value table is sufficient. Ocsigen has such a simple table mechanism directly integrated: Ocsipersist.

We first create a table holding ocaml values:

let user_table = Ocsipersist.open_table "user_table"

Then we can easily handle the user management code:

let check_pwd name pwd =
    lwt saved_password = Ocsipersist.find user_table name in
    Lwt.return (pwd = saved_password)
    Not_found -> Lwt.return false

let () = Eliom_registration.Action.register
  (fun () (name, pwd) -> Ocsipersist.add user_table name pwd)

let () = Eliom_registration.Action.register
  (fun () (name, password) ->
    match_lwt check_pwd name password with
      | true -> Eliom_reference.set username (Some name)
      | false -> Lwt.return ())

Ocsiperist and Eliom

Eliom has a higher level interface above Ocsiperist to store the server side state of an application, called Eliom references. For example persistent Eliom references of scope session group can be used to store information about a user (if the session group corresponds to the user).