@@ -217,15 +217,17 @@ func prepareUserInfo(ctx *context.Context) *user_model.User {
217217 }
218218 ctx .Data ["Sources" ] = sources
219219
220- ctx .Data ["TwoFactorEnabled" ] = true
221- _ , err = auth .GetTwoFactorByUID (u .ID )
220+ hasTOTP , err := auth .HasTwoFactorByUID (u .ID )
222221 if err != nil {
223- if ! auth .IsErrTwoFactorNotEnrolled (err ) {
224- ctx .ServerError ("IsErrTwoFactorNotEnrolled" , err )
225- return nil
226- }
227- ctx .Data ["TwoFactorEnabled" ] = false
222+ ctx .ServerError ("auth.HasTwoFactorByUID" , err )
223+ return nil
224+ }
225+ hasWebAuthn , err := auth .HasWebAuthnRegistrationsByUID (u .ID )
226+ if err != nil {
227+ ctx .ServerError ("auth.HasWebAuthnRegistrationsByUID" , err )
228+ return nil
228229 }
230+ ctx .Data ["TwoFactorEnabled" ] = hasTOTP || hasWebAuthn
229231
230232 return u
231233}
@@ -327,14 +329,27 @@ func EditUserPost(ctx *context.Context) {
327329 if form .Reset2FA {
328330 tf , err := auth .GetTwoFactorByUID (u .ID )
329331 if err != nil && ! auth .IsErrTwoFactorNotEnrolled (err ) {
330- ctx .ServerError ("GetTwoFactorByUID" , err )
332+ ctx .ServerError ("auth. GetTwoFactorByUID" , err )
331333 return
334+ } else if tf != nil {
335+ if err := auth .DeleteTwoFactorByID (tf .ID , u .ID ); err != nil {
336+ ctx .ServerError ("auth.DeleteTwoFactorByID" , err )
337+ return
338+ }
332339 }
333340
334- if err = auth .DeleteTwoFactorByID (tf .ID , u .ID ); err != nil {
335- ctx .ServerError ("DeleteTwoFactorByID" , err )
341+ wn , err := auth .GetWebAuthnCredentialsByUID (u .ID )
342+ if err != nil {
343+ ctx .ServerError ("auth.GetTwoFactorByUID" , err )
336344 return
337345 }
346+ for _ , cred := range wn {
347+ if _ , err := auth .DeleteCredential (cred .ID , u .ID ); err != nil {
348+ ctx .ServerError ("auth.DeleteCredential" , err )
349+ return
350+ }
351+ }
352+
338353 }
339354
340355 u .LoginName = form .LoginName
0 commit comments