+ fn get_user(env: *lmdb.Env, user_id: UserId) !User {
+ const txn = try env.txn();
+ defer txn.abort();
+
+ const users = try Db.users(txn);
+ return try users.get(user_id);
+ }
+};
+
+// }}}
+
+// html {{{
+fn html_form(res: *http.Response, comptime fmt_action: []const u8, args_action: anytype, inputs: anytype) !void {
+ try res.write("<form style=\"display: inline-block!important;\" action=\"", .{});
+ try res.write(fmt_action, args_action);
+ try res.write("\" method=\"post\">", .{});
+
+ inline for (inputs) |input| {
+ switch (@typeInfo(@TypeOf(input))) {
+ .Struct => {
+ try res.write("<input ", .{});
+ try res.write(input[0], input[1]);
+ try res.write(" />", .{});
+ },
+ else => {
+ try res.write("<input ", .{});
+ try res.write(input, .{});
+ try res.write(" />", .{});
+ },
+ }
+ }
+
+ try res.write("</form>", .{});
+}
+// }}}
+
+// write {{{
+fn write_header(res: *http.Response, logged_in: ?Login) !void {
+ if (logged_in) |login| {
+ try res.write(
+ \\<a href="/user/{s}">Home</a><br />
+ , .{login.user.name.constSlice()});
+ try html_form(res, "/logout", .{}, .{
+ \\type="submit" value="Logout"
+ });
+ try html_form(res, "/quit", .{}, .{
+ \\type="submit" value="Quit"
+ });
+ try res.write("<br />", .{});
+ try html_form(res, "/post", .{}, .{
+ \\type="text" name="text"
+ ,
+ \\type="submit" value="Post"
+ });