Skip to content

Commit ed6e49d

Browse files
committed
Added the functionality to reset the 2FA by admin for the other users.
1 parent 06edfbb commit ed6e49d

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/UserService.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@
203203
return self.isLoggingOut;
204204
};
205205

206+
var resetTwoFa = function (userId) {
207+
return $http.delete('api/admin/users/' + userId + '/2fa');
208+
};
209+
206210
var getUiLanguage = function () {
207211
return self.uiLanguage;
208212
};
@@ -223,7 +227,8 @@
223227
getUiLanguage: getUiLanguage,
224228
setUiLanguage: setUiLanguage,
225229
isAuthenticated: isAuthenticated,
226-
isAllowed: isAllowed
230+
isAllowed: isAllowed,
231+
resetTwoFa: resetTwoFa
227232
};
228233
}
229234

src/admin/BackofficeAdminUsersCtrl.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@
121121
);
122122
});
123123
};
124+
125+
$scope.resetTwoFa = function (ev, user) {
126+
var confirm = $mdDialog.confirm()
127+
.title(gettextCatalog.getString('Reset 2FA for this user?'))
128+
.textContent(gettextCatalog.getString('This will disable two-factor authentication and clear recovery codes.'))
129+
.targetEvent(ev)
130+
.ok(gettextCatalog.getString('Reset 2FA'))
131+
.cancel(gettextCatalog.getString('Cancel'));
132+
$mdDialog.show(confirm).then(function() {
133+
UserService.resetTwoFa(user.id).then(
134+
function () {
135+
user.isTwoFactorAuthEnabled = false;
136+
toastr.success(gettextCatalog.getString('Two-factor authentication has been reset.'));
137+
},
138+
function () {
139+
toastr.error(gettextCatalog.getString('Error when disabling two-factor authentication.'));
140+
}
141+
);
142+
});
143+
};
124144
}
125145

126146

views/users.admin.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ <h2 class="md-title md-padding-right md-padding-left">
4848
<td md-cell>{{ user.email }}</td>
4949
<td md-cell>
5050
<md-button class="md-icon-button md-primary" ng-click="editUser($event, user)"><md-icon>edit</md-icon></md-button>
51+
<md-button class="md-icon-button md-warn" ng-click="resetTwoFa($event, user)" ng-if="user.isTwoFactorAuthEnabled" ng-disabled="user.id == myself">
52+
<md-tooltip md-direction="left">{{ 'Reset 2FA' | translate }}</md-tooltip>
53+
<md-icon>vpn_key</md-icon>
54+
</md-button>
5155
<md-button class="md-icon-button md-warn" ng-click="deleteUser($event, user)" ng-disabled="user.id == myself"><md-icon>delete</md-icon></md-button>
5256
</td>
5357
</tr>

0 commit comments

Comments
 (0)