diff --git a/src/babillard.ml b/src/babillard.ml index b83c635..6ad58d5 100644 --- a/src/babillard.ml +++ b/src/babillard.ml @@ -12,6 +12,7 @@ type post = ; parent_id : string ; date : float ; nick : string + ; display_nick : string ; comment : string ; image_info : (string * string) option ; tags : string list @@ -241,7 +242,7 @@ let () = if Array.exists Result.is_error (Array.map (fun query -> Db.exec query ()) tables) - then Dream.error (fun log -> log "can't create table") + then Dream.error (fun log -> log "can't create babillard's tables") let parse_image image = match image with @@ -377,11 +378,13 @@ let build_reply ~comment ?image ~tags ?parent_id nick = in let date = Unix.time () in let comment, citations = parse_comment comment in + let* display_nick = User.get_display_nick nick in let reply = { id ; parent_id ; date ; nick + ; display_nick ; comment ; image_info ; tags = tag_list @@ -432,6 +435,7 @@ let post_exist id = Result.is_ok (Db.find Q.get_is_post id) let get_post id = let^ parent_id = Db.find Q.get_post_thread id in let^ nick = Db.find Q.get_post_nick id in + let* display_nick = User.get_display_nick nick in let^ comment = Db.find Q.get_post_comment id in let^ date = Db.find Q.get_post_date id in let^ image_info = Db.find_opt Q.get_post_image_info id in @@ -440,7 +444,17 @@ let get_post id = let^ replies = Db.collect_list Q.get_post_replies id in let^ citations = Db.collect_list Q.get_post_citations id in let reply = - { id; parent_id; date; nick; comment; image_info; tags; replies; citations } + { id + ; parent_id + ; date + ; nick + ; display_nick + ; comment + ; image_info + ; tags + ; replies + ; citations + } in Ok reply diff --git a/src/content/assets/css/style.css b/src/content/assets/css/style.css index 87a9198..a65e21c 100644 --- a/src/content/assets/css/style.css +++ b/src/content/assets/css/style.css @@ -40,7 +40,7 @@ blockquote.blockquote { width: 100%; } -.nick { +.display-nick { color: #FFB300; } diff --git a/src/permap.ml b/src/permap.ml index f20dfda..8b98fb2 100644 --- a/src/permap.ml +++ b/src/permap.ml @@ -186,10 +186,12 @@ let profile_get request = match Dream.session "nick" request with | None -> render_unsafe "Not logged in" request | Some nick -> - if User.exist nick then - let bio = match User.get_bio nick with Ok bio -> bio | Error e -> e in - render_unsafe (User_profile.f nick bio request) request - else Dream.respond ~status:`Not_Found "User does not exists" + let res = + match User.get_user nick with + | Error e -> e + | Ok user -> User_profile.f user request + in + render_unsafe res request let profile_post request = match Dream.session "nick" request with @@ -203,6 +205,13 @@ let profile_post request = ~headers:[ ("Location", "/profile") ] "Your bio was updated!" | Error e -> render_unsafe e request ) + | `Ok [ ("display-nick", display_nick) ] -> ( + match User.update_display_nick display_nick nick with + | Ok () -> + Dream.respond ~status:`See_Other + ~headers:[ ("Location", "/profile") ] + "Your display nick was updated!" + | Error e -> render_unsafe e request ) | `Ok _ | `Many_tokens _ | `Missing_token _ | `Invalid_token _ | `Wrong_session _ | `Expired _ | `Wrong_content_type -> ( match%lwt Dream.multipart request with diff --git a/src/pp_babillard.ml b/src/pp_babillard.ml index b937b41..0b6c69c 100644 --- a/src/pp_babillard.ml +++ b/src/pp_babillard.ml @@ -12,6 +12,7 @@ let pp_post fmt t = ; parent_id = _parent_id ; date ; nick + ; display_nick ; comment ; image_info ; tags @@ -79,7 +80,7 @@ let pp_post fmt t = Format.fprintf fmt {|
- %s + %s

public profile rendering.

+let f (user: User.t) request = +

<%s Format.sprintf "Hello %s !" user.nick %>

+

Check your public profile rendering.

Edit profile

+ <%s! Dream.form_tag ~action:"/profile" request %> +
+ + +
+ + +
+
<%s! Dream.form_tag ~action:"/profile" request %>
- +
Who are you?

- Your avatar picture + Your avatar picture

<%s! Dream.form_tag ~action:"/profile" ~enctype:`Multipart_form_data request %>