╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ UserSettings.zig ─────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
237 } 238 239 // update the user. this is the terminal path; the web posts the form to 240 // the user route. 241 fn submitForm(self: *View, allocator: std.mem.Allocator) !void { 242 if (comptime wasm) return; 243 const io = self.session.io orelse return; 244 const users_dir = self.session.users_dir orelse return; 245 const admin_repo = self.session.admin_repo orelse return; 246 const user_id = self.session.userId() orelse return; 247 248 const email = try (try self.formField("email")).text(allocator); 249 defer allocator.free(email); 250 const current_password = try (try self.formField("current_password")).text(allocator); 251 defer allocator.free(current_password); 252 const new_password = try (try self.formField("new_password")).text(allocator); 253 defer allocator.free(new_password); 254 const new_password_again = try (try self.formField("new_password_again")).text(allocator); 255 defer allocator.free(new_password_again); 256 257 evt.updateUser(io, allocator, users_dir, admin_repo, &user_id, email, current_password, new_password, new_password_again) catch |err| switch (err) { 258 // the account was removed under them 259 error.NotFound => return self.logOut(), 260 else => { 261 const failure = ui.Session.FormFeedback.UserFailure.fromError(err) orelse return err; 262 const aa = self.session.arena.allocator(); 263 self.session.data.form_feedback = .{ .user_settings = .{ .failure = failure, .fields = .{ .email = try aa.dupe(u8, email) } } }; 264 return; 265 }, 266 }; 267 268 // reload the page with the saved email and the password fields cleared 269 self.session.haxy_moment = try evt.currentMoment(evt.admin_repo_opts, admin_repo); 270 try self.session.loadUser(); 271 try self.session.navigate(self.session.data.current_page); 272 } 273 274 fn headerActive(self: *View) bool { 275 return self.box.getFocus().child_id == self.box.children.keys()[header_index]; 276 } 277 278 fn formScroll(self: *View) *wgt.Scroll(ui.Widget) { 279 return &self.box.children.values()[scroll_index].widget.scroll; 280 } 281 282 fn formBox(self: *View) *wgt.Box(ui.Widget) { 283 return &self.formScroll().child.center.child.box; 284 } 285 286 pub fn clearGrid(self: *View) void { 287 self.box.clearGrid(); 288 } 289 290 pub fn getGrid(self: View) ?Grid { 291 return self.box.getGrid(); 292 } 293 294 pub fn getFocus(self: *View) *Focus { 295 return self.box.getFocus(); 296 } 297 298 // up leaves the view from the logout button 299 pub fn atTop(self: *View) bool { 300 return self.headerActive(); 301 } 302 }; 303