Closes #268: test TOTP after activation

This commit is contained in:
Benjamin Gamard 2019-02-04 16:47:43 +01:00
parent c6eb1c813c
commit 822a4ae776
3 changed files with 40 additions and 9 deletions

View File

@ -11,7 +11,7 @@ angular.module('docs').controller('SettingsSecurity', function($scope, User, $di
/** /**
* Enable TOTP. * Enable TOTP.
*/ */
$scope.enableTotp = function() { $scope.enableTotp = function () {
var title = $translate.instant('settings.security.enable_totp'); var title = $translate.instant('settings.security.enable_totp');
var msg = $translate.instant('settings.security.enable_totp_message'); var msg = $translate.instant('settings.security.enable_totp_message');
var btns = [ var btns = [
@ -34,7 +34,7 @@ angular.module('docs').controller('SettingsSecurity', function($scope, User, $di
/** /**
* Disable TOTP. * Disable TOTP.
*/ */
$scope.disableTotp = function() { $scope.disableTotp = function () {
$uibModal.open({ $uibModal.open({
templateUrl: 'partial/docs/settings.security.disabletotp.html', templateUrl: 'partial/docs/settings.security.disabletotp.html',
controller: 'SettingsSecurityModalDisableTotp' controller: 'SettingsSecurityModalDisableTotp'
@ -53,4 +53,18 @@ angular.module('docs').controller('SettingsSecurity', function($scope, User, $di
}); });
}); });
}; };
/**
* Test TOTP.
*/
$scope.testValidationCodeSuccess = null;
$scope.testTotp = function (code) {
Restangular.one('user/test_totp').post('', {
code: code
}).then(function() {
$scope.testValidationCodeSuccess = true;
}, function () {
$scope.testValidationCodeSuccess = false;
});
};
}); });

View File

@ -347,7 +347,10 @@
"message": "Your account will not be protected by the two-factor authentication anymore.", "message": "Your account will not be protected by the two-factor authentication anymore.",
"confirm_password": "Confirm your password", "confirm_password": "Confirm your password",
"submit": "Disable two-factor authentication" "submit": "Disable two-factor authentication"
} },
"test_totp": "Please enter the validation code displayed on your phone :",
"test_code_success": "Validation code OK",
"test_code_fail": "This code is not valid, please double check that your phone is properly configured or disable Two-factor authentication"
}, },
"group": { "group": {
"title": "Groups management", "title": "Groups management",

View File

@ -19,12 +19,26 @@
</div> </div>
<div ng-if="user.totp_enabled"> <div ng-if="user.totp_enabled">
<div ng-if="secret"> <div class="row mt-30 mb-19" ng-if="secret">
<p translate="settings.security.secret_key" translate-values="{ secret: secret }"></p> <div class="col-sm-3">
<qrcode data="otpauth://totp/Sismics%20Docs?secret={{ secret }}" size="200"></qrcode> <p translate="settings.security.secret_key" translate-values="{ secret: secret }"></p>
<p class="text-danger"> <qrcode data="otpauth://totp/Sismics%20Docs?secret={{ secret }}" size="200"></qrcode>
<strong>{{ 'settings.security.secret_key_warning' | translate }}</strong> <p class="text-danger">
</p> <strong>{{ 'settings.security.secret_key_warning' | translate }}</strong>
</p>
</div>
<div class="col-sm-3">
<p class="mt-30"><strong>{{ 'settings.security.test_totp' | translate }}</strong></p>
<form class="form-inline">
<input type="text" class="form-control" ng-model="testValidationCode" />
<button class="btn btn-primary" ng-click="testTotp(testValidationCode)">{{ 'ok' | translate }}</button>
</form>
<p class="mt-10" ng-if="testValidationCodeSuccess != null"
ng-class="{ 'text-success': testValidationCodeSuccess, 'text-danger': !testValidationCodeSuccess }">
<strong ng-if="testValidationCodeSuccess">{{ 'settings.security.test_code_success' | translate }}</strong>
<strong ng-if="!testValidationCodeSuccess">{{ 'settings.security.test_code_fail' | translate }}</strong>
</p>
</div>
</div> </div>
<p translate="settings.security.totp_enabled_message" translate-values="{ appName: appName }"></p> <p translate="settings.security.totp_enabled_message" translate-values="{ appName: appName }"></p>
<p> <p>