Redirect to two-factor auth page after creating the first admin

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2024-02-04 20:58:29 +01:00
parent e5836c8118
commit 8385acd0e3
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF
3 changed files with 8 additions and 2 deletions

View file

@ -18086,7 +18086,7 @@ func TestWebAdminSetupMock(t *testing.T) {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rr = executeRequest(req)
checkResponseCode(t, http.StatusFound, rr)
assert.Equal(t, webUsersPath, rr.Header().Get("Location"))
assert.Equal(t, webAdminMFAPath, rr.Header().Get("Location"))
// if we resubmit the form we get a bad request, an admin already exists
req, err = http.NewRequest(http.MethodPost, webAdminSetupPath, bytes.NewBuffer([]byte(form.Encode())))
assert.NoError(t, err)

View file

@ -3124,6 +3124,7 @@ func TestWebAdminSetupWithInstallCode(t *testing.T) {
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
server.router.ServeHTTP(rr, r)
assert.Equal(t, http.StatusFound, rr.Code)
assert.Equal(t, webAdminMFAPath, rr.Header().Get("Location"))
_, err = dataprovider.AdminExists(defaultAdminUsername)
assert.NoError(t, err)
@ -3180,6 +3181,7 @@ func TestWebAdminSetupWithInstallCode(t *testing.T) {
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
server.router.ServeHTTP(rr, r)
assert.Equal(t, http.StatusFound, rr.Code)
assert.Equal(t, webAdminMFAPath, rr.Header().Get("Location"))
_, err = dataprovider.AdminExists(defaultAdminUsername)
assert.NoError(t, err)

View file

@ -817,7 +817,11 @@ func (s *httpdServer) loginAdmin(
return
}
dataprovider.UpdateAdminLastLogin(admin)
http.Redirect(w, r, webUsersPath, http.StatusFound)
redirectURL := webUsersPath
if errorFunc == nil {
redirectURL = webAdminMFAPath
}
http.Redirect(w, r, redirectURL, http.StatusFound)
}
func (s *httpdServer) logout(w http.ResponseWriter, r *http.Request) {