feat(api): accept recovery codes as second factor and let users regenerate them

Enabling TOTP returns ten codes that are shown once. Disabling TOTP and
regenerating codes require the password plus a current code.

Closes #40

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 00:35:20 +01:00
1 parent dbea42e7a5
commit 7b063d2cd8
12 files changed
+510 -123

No files matched your search

+7 -2
View File
@@ -167,12 +167,17 @@ func (s *Server) login(c *gin.Context) {
s.finishLogin(c, user.ID)
}
// secondFactorRequest carries a TOTP code or a recovery code.
type secondFactorRequest struct {
Code string `json:"code" binding:"required,max=32"`
}
type totpRequest struct {
Code string `json:"code" binding:"required,len=6,numeric"`
}
func (s *Server) loginTOTP(c *gin.Context) {
var req totpRequest
var req secondFactorRequest
if !bind(c, &req) {
return
}
@@ -195,7 +200,7 @@ func (s *Server) loginTOTP(c *gin.Context) {
internalError(c, err)
return
}
ok, err := s.verifyUserTOTP(ctx, userID, req.Code)
ok, err := s.verifySecondFactor(ctx, userID, req.Code)
if err != nil {
internalError(c, err)
return