id: UserId,
name: Username,
display_name: DisplayName,
+ description: UserDescription,
password_hash: PasswordHash,
+
posts: PostList,
+
following: UserList,
followers: UserList,
const Timestamp = i64;
const Username = std.BoundedArray(u8, 32);
const DisplayName = std.BoundedArray(u8, 64);
+const UserDescription = std.BoundedArray(u8, 1024);
const PasswordHash = std.BoundedArray(u8, 128);
const SessionToken = u64;
const CookieValue = std.BoundedArray(u8, 128);
.id = user_id,
.name = username_array,
.display_name = display_name,
+ .description = try UserDescription.init(0),
.password_hash = try hash_password(password),
.posts = try PostList.init(txn),
.following = try UserList.init(txn),
, .{});
}
+ if (user.description.len > 0) {
+ try res.write(
+ \\<div style="padding-left: 5px; border-left: 1px solid grey;">
+ // \\« {s} »
+ \\<i>{s}</i>
+ \\</div>
+ , .{user.description.constSlice()});
+ }
+
try res.write("<br />", .{});
}
fn write_posts(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, post_list: PostList, options: struct {
.{ "type=\"text\" name=\"display_name\" placeholder=\"{s}\"", .{login.user.display_name.constSlice()} },
"type=\"submit\" value=\"Change\"",
});
+ try self.res.write("<br />Description: ", .{});
+ try html_form(self.res, "/set_description", .{
+ .{ "type=\"text\" name=\"description\" placeholder=\"{s}\"", .{login.user.description.constSlice()} },
+ "type=\"submit\" value=\"Change\"",
+ });
try self.res.write("<br />Password: ", .{});
try html_form(self.res, "/set_password", .{
"type=\"text\" name=\"password\"",
user.display_name = display_name;
try users.put(login.user.id, user);
}
+ pub fn @"/set_description"(self: Self, args: struct { description: []const u8 }) !void {
+ const login = self.logged_in orelse return error.NotLoggedIn;
+ const description = try reencode(UserDescription, args.description);
+
+ const txn = try self.env.txn();
+ defer txn.commit() catch {};
+
+ const users = try Db.users(txn);
+ var user = login.user;
+ user.description = description;
+ try users.put(login.user.id, user);
+ }
pub fn @"/set_password"(self: Self, args: struct { password: []const u8 }) !void {
const login = self.logged_in orelse return error.NotLoggedIn;