#84: Ask for a TOTP validation code (web UI)

This commit is contained in:
jendib 2016-03-24 00:03:29 +01:00
parent 1343948d33
commit 98350860eb
4 changed files with 30 additions and 7 deletions

View File

@ -4,18 +4,28 @@
* Login controller. * Login controller.
*/ */
angular.module('docs').controller('Login', function($scope, $rootScope, $state, $dialog, User) { angular.module('docs').controller('Login', function($scope, $rootScope, $state, $dialog, User) {
$scope.codeRequired = false;
/**
* Login.
*/
$scope.login = function() { $scope.login = function() {
User.login($scope.user).then(function() { User.login($scope.user).then(function() {
User.userInfo(true).then(function(data) { User.userInfo(true).then(function(data) {
$rootScope.userInfo = data; $rootScope.userInfo = data;
}); });
$state.go('document.default'); $state.go('document.default');
}, function() { }, function(data) {
var title = 'Login failed'; if (data.data.type == 'ValidationCodeRequired') {
var msg = 'Username or password invalid'; // A TOTP validation code is required to login
var btns = [{result:'ok', label: 'OK', cssClass: 'btn-primary'}]; $scope.codeRequired = true;
} else {
$dialog.messageBox(title, msg, btns); // Login truly failed
var title = 'Login failed';
var msg = 'Username or password invalid';
var btns = [{result: 'ok', label: 'OK', cssClass: 'btn-primary'}];
$dialog.messageBox(title, msg, btns);
}
}); });
}; };
}); });

View File

@ -17,6 +17,15 @@
<input class="form-control" type="password" id="inputPassword" placeholder="Password" ng-model="user.password" /> <input class="form-control" type="password" id="inputPassword" placeholder="Password" ng-model="user.password" />
</div> </div>
<span class="help-block" ng-if="codeRequired">
A validation code is required
<span class="glyphicon glyphicon-question-sign" title="You have activated the two-factor authentication on your account. Please enter a validation code generated by the phone app your configured."></span>
</span>
<div class="form-group" ng-if="codeRequired">
<label class="sr-only" for="inputCode">Validation code</label>
<input class="form-control" type="text" id="inputCode" placeholder="Validation code" ng-model="user.code" />
</div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" ng-model="user.remember" /> Remember me <input type="checkbox" ng-model="user.remember" /> Remember me

View File

@ -240,7 +240,11 @@ input[readonly].share-link {
.login-box { .login-box {
background: rgba(255, 255, 255, 0.5); background: rgba(255, 255, 255, 0.5);
padding: 20px; padding: 20px;
border-radius: 4px border-radius: 4px;
.help-block, .checkbox {
color: white;
}
} }
/* Styling for the ngProgress itself */ /* Styling for the ngProgress itself */