Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for administrator to reset user 2FA #14243

Merged
merged 7 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/auth/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type AdminEditUserForm struct {
AllowImportLocal bool
AllowCreateOrganization bool
ProhibitLogin bool
Reset2FA bool `form:"reset_2fa"`
}

// Validate validates form fields
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,7 @@ users.delete_account = Delete User Account
users.still_own_repo = This user still owns one or more repositories. Delete or transfer these repositories first.
users.still_has_org = This user is a member of an organization. Remove the user from any organizations first.
users.deletion_success = The user account has been deleted.
users.reset_2fa = Reset 2FA

emails.email_manage_panel = User Email Management
emails.primary = Primary
Expand Down
23 changes: 23 additions & 0 deletions routers/admin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions templates/admin/user/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@
</div>
{{end}}

{{if .TwoFactorEnabled}}
<div class="ui divider"></div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.i18n.Tr "admin.users.reset_2fa"}}</strong></label>
<input name="reset_2fa" type="checkbox">
</div>
</div>
{{end}}

<div class="ui divider"></div>

<div class="field">
Expand Down