Source file JSON.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(**This module contains responses for basic FPauth events in JSON format.*)

open Dream
open Base

(**[Make] creates responses for provided Variables*)
module Make (Variables : FPauth_core.Auth_sign.VARIABLES) : (FPauth_core.Auth_sign.RESPONSES) = struct
  
  let login_successful request = 
    let auth = Option.value_exn (field request Variables.authenticated) |> Bool.to_string in
    json ("{\"authenticated\" : "^ auth ^" }")
  
  
  let login_error request = 
    let err = field request (Variables.auth_error) |> Option.value ~default:(Error.of_string "Unknown error") |> Error.to_string_mach 
    and auth = Option.value_exn (field request Variables.authenticated) |> Bool.to_string in
    json ("{\"auth\" : "^ auth ^", \n
      \"error\" : "^ err ^"}")

  let logout request =
    match field request Variables.authenticated with
    | None -> json ("{\"error\" : \"No local\"}")
    | Some auth -> json ("{
      \"auth\" : "^( auth |> Bool.to_string)^"}")
end