summaryrefslogtreecommitdiffstats
path: root/routers/admin/users.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-01-05 13:54:48 +0000
committerGitHub <noreply@github.com>2021-01-05 14:54:48 +0100
commit325add71cfa3789b5e7ecf40bfe25376981654a7 (patch)
tree92258a4d0407277d9cc1183519c7bcddd42eda8c /routers/admin/users.go
parent15a475b7dbcf7923d9518dff7764b20e404eb774 (diff)
downloadgitea-325add71cfa3789b5e7ecf40bfe25376981654a7.tar.gz
gitea-325add71cfa3789b5e7ecf40bfe25376981654a7.zip
Add option for administrator to reset user 2FA (#14243)
* Frontend * Backend * only show 2FA-Reset option if posible
Diffstat (limited to 'routers/admin/users.go')
-rw-r--r--routers/admin/users.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/routers/admin/users.go b/routers/admin/users.go
index 2ea496624b..1dc6d5bbe2 100644
--- a/routers/admin/users.go
+++ b/routers/admin/users.go
@@ -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