mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 10:48:37 +00:00
Add option for administrator to reset user 2FA (#14243)
* Frontend * Backend * only show 2FA-Reset option if posible
This commit is contained in:
@@ -183,6 +183,16 @@ func prepareUserInfo(ctx *context.Context) *models.User {
|
||||
}
|
||||
ctx.Data["Sources"] = sources
|
||||
|
||||
ctx.Data["TwoFactorEnabled"] = true
|
||||
_, err = models.GetTwoFactorByUID(u.ID)
|
||||
if err != nil {
|
||||
if !models.IsErrTwoFactorNotEnrolled(err) {
|
||||
ctx.InternalServerError(err)
|
||||
return nil
|
||||
}
|
||||
ctx.Data["TwoFactorEnabled"] = false
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
@@ -259,6 +269,19 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||
u.HashPassword(form.Password)
|
||||
}
|
||||
|
||||
if form.Reset2FA {
|
||||
tf, err := models.GetTwoFactorByUID(u.ID)
|
||||
if err != nil && !models.IsErrTwoFactorNotEnrolled(err) {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = models.DeleteTwoFactorByID(tf.ID, u.ID); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
u.LoginName = form.LoginName
|
||||
u.FullName = form.FullName
|
||||
u.Email = form.Email
|
||||
|
Reference in New Issue
Block a user