Refactor: unified username extraction from request and html generation