Skip to content

Commit 6b8450b

Browse files
author
Jon Kristensen
committed
Add 0.0.0.4
1 parent c8006cb commit 6b8450b

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

web/auth.html

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
var authenticated = false;
1717

1818
return {
19-
login: function (user, password) {
20-
return $http.post('/api/login', {
19+
login: function (user, password, otp) {
20+
var data = {
2121
password: password,
2222
user: user
23-
}).then(function (result) {
23+
};
24+
25+
if (otp !== null) {
26+
data.otp = otp;
27+
}
28+
29+
return $http.post('/api/login', data).then(function (result) {
2430
$rootScope.session = result;
2531
$rootScope.$broadcast('loginSucceeded', result);
2632
if (!authenticated) {
@@ -29,7 +35,11 @@
2935
}
3036
return result;
3137
}, function (error) {
32-
$rootScope.$broadcast('loginFailed', error);
38+
if (error.status === 499) {
39+
$rootScope.$broadcast('otpRequired');
40+
} else {
41+
$rootScope.$broadcast('loginFailed', error);
42+
}
3343
return error;
3444
});
3545
},
@@ -50,17 +60,27 @@
5060
};
5161
}]);
5262

53-
app.controller('AuthenticateController', ['$http', '$scope', '$window', 'AuthenticationService', function ($http, $scope, $window, AuthenticationService) {
63+
app.controller('AuthenticateController', ['$http', '$scope', '$timeout', '$window', 'AuthenticationService', function ($http, $scope, $timeout, $window, AuthenticationService) {
5464
$scope.authenticate = {
65+
cancel: function () {
66+
$scope.authenticate.otp = null;
67+
$timeout(function () { document.getElementById("authenticate-user").focus(); });
68+
},
69+
otp: null,
5570
submit: function () {
56-
AuthenticationService.login($scope.authenticate.user, $scope.authenticate.password);
71+
AuthenticationService.login($scope.authenticate.user, $scope.authenticate.password, $scope.authenticate.otp);
5772
}
5873
};
5974

6075
$scope.$on('loginSucceeded', function () {
6176
$window.location.reload(true);
6277
});
6378

79+
$scope.$on('otpRequired', function () {
80+
$scope.authenticate.otp = '';
81+
$timeout(function () { document.getElementById("authenticate-otp").focus(); });
82+
});
83+
6484
$scope.$on('loginFailed', function () {
6585
$scope.authenticate.error = "Felaktigt användarnamn och/eller lösenord.";
6686
});
@@ -75,14 +95,19 @@
7595
<div class="panel-body">
7696
<div class="form-group">
7797
<label for="authenticate-user">E-postadress</label>
78-
<input autofocus class="form-control" id="authenticate-user" ng-model="authenticate.user" placeholder="E-postadress" required type="text">
98+
<input autofocus class="form-control" id="authenticate-user" ng-disabled="authenticate.otp !== null" ng-model="authenticate.user" placeholder="E-postadress" required type="text">
7999
</div>
80100
<div class="form-group">
81101
<label for="authenticate-password">Lösenord</label>
82-
<input class="form-control" id="authenticate-password" ng-model="authenticate.password" placeholder="Lösenord" required type="password">
102+
<input class="form-control" id="authenticate-password" ng-disabled="authenticate.otp !== null" ng-model="authenticate.password" placeholder="Lösenord" required type="password">
103+
</div>
104+
<div class="form-group" ng-if="authenticate.otp !== null">
105+
<label for="authenticate-otp">SMS-kod</label>
106+
<input autocomplete="off" class="form-control" id="authenticate-otp" ng-model="authenticate.otp" placeholder="SMS-kod" required type="password">
83107
</div>
84108
<uib-alert ng-if="authenticate.error" style="margin-bottom: 15px;" type="danger">{{authenticate.error}}</uib-alert>
85109
<button class="btn btn-primary" ng-disabled="!authenticate.form.$valid" type="submit">Logga in</button>
110+
<button class="btn btn-warning" ng-click="authenticate.cancel()" ng-if="authenticate.otp !== null" style="float: right;" type="button">Avbryt</button>
86111
</div>
87112
</form>
88113
</div>

0 commit comments

Comments
 (0)