╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Login.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
204 fn indexOf(self: View, child_id: usize) ?usize { 205 for (self.nav_ids, 0..) |id, i| { 206 if (id == child_id) return i; 207 } 208 return null; 209 } 210 211 fn submit(self: *View, allocator: std.mem.Allocator, root_focus: *Focus) !void { 212 if (comptime wasm) { 213 // no DB cursor available on the wasm render path 214 self.session.data.login_failure = .unknown_user; 215 return; 216 } 217 218 const box = &self.center.child.box; 219 const username_input = &box.children.values()[username_index].widget.text_input; 220 const password_input = &box.children.values()[password_index].widget.text_input; 221 222 const username = try username_input.text(allocator); 223 defer allocator.free(username); 224 225 const password = try password_input.text(allocator); 226 defer allocator.free(password); 227 228 const haxy_moment = self.session.haxy_moment orelse { 229 // no DB context (e.g. wasm/web rendering path); treat as unknown. 230 self.session.data.login_failure = .unknown_user; 231 return; 232 }; 233 234 const result = try evt.User.verifyCredentials(evt.AdminDB, evt.admin_repo_opts.hash, haxy_moment, self.session.arena, username, password); 235 switch (result) { 236 .unknown_user => { 237 self.session.data.login_failure = .unknown_user; 238 return; 239 }, 240 .wrong_password => { 241 self.session.data.login_failure = .wrong_password; 242 return; 243 }, 244 .success => |user_id| { 245 // dupe user_id into the arena so the session can hold a stable slice 246 const user_id_stable = try self.session.arena.allocator().dupe(u8, &user_id); 247 self.session.data.user_id = user_id_stable; 248 self.session.data.login_failure = null; 249 250 // adopt the user's persisted prefs 251 try self.session.loadUserPrefs(); 252 253 // wipe the entered credentials so they don't linger if the 254 // user returns to this page after logging out 255 username_input.clear(allocator); 256 password_input.clear(allocator); 257 258 // jump focus back to the users tab — the login button we 259 // just pressed is about to be hidden by the tab-label swap 260 try root_focus.setFocus(self.users_tab_id); 261 }, 262 } 263 } 264 }; 265